Branch data Line data Source code
1 : : /*
2 : : Copyright (c) 2021 Fraunhofer AISEC. See the COPYRIGHT
3 : : file at the top-level directory of this distribution.
4 : :
5 : : Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 : : http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 : : <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 : : option. This file may not be copied, modified, or distributed
9 : : except according to those terms.
10 : : */
11 : :
12 : : #include <stdint.h>
13 : :
14 : : #include "edhoc/retrieve_cred.h"
15 : : #include "edhoc/signature_or_mac_msg.h"
16 : : #include "edhoc/plaintext.h"
17 : : #include "edhoc/bstr_encode_decode.h"
18 : :
19 : : #include "common/oscore_edhoc_error.h"
20 : : #include "common/memcpy_s.h"
21 : : #include "common/print_util.h"
22 : :
23 : : #include "cbor/edhoc_decode_id_cred_x.h"
24 : : #include "cbor/edhoc_encode_int_type.h"
25 : :
26 : 6 : enum err id_cred2kid(const struct byte_array *id_cred, struct byte_array *kid)
27 : : {
28 : 6 : struct id_cred_x_map map = { 0 };
29 : : size_t payload_len_out;
30 : 6 : size_t decode_len = 0;
31 [ - + ]: 6 : TRY_EXPECT(cbor_decode_id_cred_x_map(id_cred->ptr, id_cred->len, &map,
32 : : &decode_len),
33 : : 0);
34 : :
35 [ - + ]: 6 : if (map.id_cred_x_map_kid_present) {
36 [ # # ]: 0 : TRY_EXPECT(
37 : : cbor_encode_int_type_i(
38 : : kid->ptr, kid->len,
39 : : &map.id_cred_x_map_kid.id_cred_x_map_kid_int,
40 : : &payload_len_out),
41 : : ZCBOR_SUCCESS);
42 : 0 : kid->len = (uint32_t)payload_len_out;
43 : : } else {
44 : 6 : kid->len = 0;
45 : : }
46 : :
47 : 6 : return ok;
48 : : }
|