xref: /freebsd/contrib/libfido2/src/iso7816.h (revision 19fae0f66023a97a9b464b3beeeabb2081f575b3)
1 /*
2  * Copyright (c) 2018 Yubico AB. All rights reserved.
3  * Use of this source code is governed by a BSD-style
4  * license that can be found in the LICENSE file.
5  */
6 
7 #ifndef _ISO7816_H
8 #define _ISO7816_H
9 
10 #include <stdint.h>
11 #include <stdlib.h>
12 
13 #include "packed.h"
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif /* __cplusplus */
18 
19 PACKED_TYPE(iso7816_header_t,
20 struct iso7816_header {
21 	uint8_t cla;
22 	uint8_t ins;
23 	uint8_t p1;
24 	uint8_t p2;
25 	uint8_t lc1;
26 	uint8_t lc2;
27 	uint8_t lc3;
28 })
29 
30 typedef struct iso7816_apdu {
31 	size_t            alloc_len;
32 	uint16_t          payload_len;
33 	uint8_t          *payload_ptr;
34 	iso7816_header_t  header;
35 	uint8_t           payload[];
36 } iso7816_apdu_t;
37 
38 const unsigned char *iso7816_ptr(const iso7816_apdu_t *);
39 int iso7816_add(iso7816_apdu_t *, const void *, size_t);
40 iso7816_apdu_t *iso7816_new(uint8_t, uint8_t, uint8_t, uint16_t);
41 size_t iso7816_len(const iso7816_apdu_t *);
42 void iso7816_free(iso7816_apdu_t **);
43 
44 #ifdef __cplusplus
45 } /* extern "C" */
46 #endif /* __cplusplus */
47 
48 #endif /* !_ISO7816_H */
49