xref: /freebsd/contrib/libfido2/src/iso7816.h (revision aa1a8ff2d6dbc51ef058f46f3db5a8bb77967145)
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  * SPDX-License-Identifier: BSD-2-Clause
6  */
7 
8 #ifndef _ISO7816_H
9 #define _ISO7816_H
10 
11 #include <stdint.h>
12 #include <stdlib.h>
13 
14 #include "packed.h"
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif /* __cplusplus */
19 
20 PACKED_TYPE(iso7816_header_t,
21 struct iso7816_header {
22 	uint8_t cla;
23 	uint8_t ins;
24 	uint8_t p1;
25 	uint8_t p2;
26 	uint8_t lc1;
27 	uint8_t lc2;
28 	uint8_t lc3;
29 })
30 
31 typedef struct iso7816_apdu {
32 	size_t            alloc_len;
33 	uint16_t          payload_len;
34 	uint8_t          *payload_ptr;
35 	iso7816_header_t  header;
36 	uint8_t           payload[];
37 } iso7816_apdu_t;
38 
39 const unsigned char *iso7816_ptr(const iso7816_apdu_t *);
40 int iso7816_add(iso7816_apdu_t *, const void *, size_t);
41 iso7816_apdu_t *iso7816_new(uint8_t, uint8_t, uint8_t, uint16_t);
42 size_t iso7816_len(const iso7816_apdu_t *);
43 void iso7816_free(iso7816_apdu_t **);
44 
45 #ifdef __cplusplus
46 } /* extern "C" */
47 #endif /* __cplusplus */
48 
49 #endif /* !_ISO7816_H */
50