Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
simple-mbed-cloud-client/mbed-cloud-client/certificate-enrollment-client/source/include/ce_tlv.h@0:8f0bb79ddd48, 2021-05-04 (annotated)
- Committer:
- leothedragon
- Date:
- Tue May 04 08:55:12 2021 +0000
- Revision:
- 0:8f0bb79ddd48
nmn
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
leothedragon | 0:8f0bb79ddd48 | 1 | // ---------------------------------------------------------------------------- |
leothedragon | 0:8f0bb79ddd48 | 2 | // Copyright 2018 ARM Ltd. |
leothedragon | 0:8f0bb79ddd48 | 3 | // |
leothedragon | 0:8f0bb79ddd48 | 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
leothedragon | 0:8f0bb79ddd48 | 5 | // you may not use this file except in compliance with the License. |
leothedragon | 0:8f0bb79ddd48 | 6 | // You may obtain a copy of the License at |
leothedragon | 0:8f0bb79ddd48 | 7 | // |
leothedragon | 0:8f0bb79ddd48 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
leothedragon | 0:8f0bb79ddd48 | 9 | // |
leothedragon | 0:8f0bb79ddd48 | 10 | // Unless required by applicable law or agreed to in writing, software |
leothedragon | 0:8f0bb79ddd48 | 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
leothedragon | 0:8f0bb79ddd48 | 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
leothedragon | 0:8f0bb79ddd48 | 13 | // See the License for the specific language governing permissions and |
leothedragon | 0:8f0bb79ddd48 | 14 | // limitations under the License. |
leothedragon | 0:8f0bb79ddd48 | 15 | // ---------------------------------------------------------------------------- |
leothedragon | 0:8f0bb79ddd48 | 16 | |
leothedragon | 0:8f0bb79ddd48 | 17 | #ifndef __CE_TLV_H__ |
leothedragon | 0:8f0bb79ddd48 | 18 | #define __CE_TLV_H__ |
leothedragon | 0:8f0bb79ddd48 | 19 | |
leothedragon | 0:8f0bb79ddd48 | 20 | #ifdef __cplusplus |
leothedragon | 0:8f0bb79ddd48 | 21 | extern "C" { |
leothedragon | 0:8f0bb79ddd48 | 22 | #endif |
leothedragon | 0:8f0bb79ddd48 | 23 | #include <stdint.h> |
leothedragon | 0:8f0bb79ddd48 | 24 | #include <stdbool.h> |
leothedragon | 0:8f0bb79ddd48 | 25 | #include <stddef.h> |
leothedragon | 0:8f0bb79ddd48 | 26 | |
leothedragon | 0:8f0bb79ddd48 | 27 | typedef enum { |
leothedragon | 0:8f0bb79ddd48 | 28 | CE_TLV_STATUS_SUCCESS, |
leothedragon | 0:8f0bb79ddd48 | 29 | CE_TLV_STATUS_END, |
leothedragon | 0:8f0bb79ddd48 | 30 | CE_TLV_STATUS_INVALID_ARG, |
leothedragon | 0:8f0bb79ddd48 | 31 | CE_TLV_STATUS_TEXT_NOT_TERMINATED, |
leothedragon | 0:8f0bb79ddd48 | 32 | CE_TLV_STATUS_MALFORMED_TLV, |
leothedragon | 0:8f0bb79ddd48 | 33 | CE_TLV_STATUS_ERROR, |
leothedragon | 0:8f0bb79ddd48 | 34 | CE_TLV_STATUS_ENCODER_INSUFFICIENT_BUFFER |
leothedragon | 0:8f0bb79ddd48 | 35 | } ce_tlv_status_e; |
leothedragon | 0:8f0bb79ddd48 | 36 | |
leothedragon | 0:8f0bb79ddd48 | 37 | typedef enum { |
leothedragon | 0:8f0bb79ddd48 | 38 | CE_TLV_TYPE_CERT_NAME = 1 |
leothedragon | 0:8f0bb79ddd48 | 39 | } ce_tlv_type_e; |
leothedragon | 0:8f0bb79ddd48 | 40 | |
leothedragon | 0:8f0bb79ddd48 | 41 | typedef struct ce_tlv_element_ { |
leothedragon | 0:8f0bb79ddd48 | 42 | const uint8_t *_current; // 4 bytes |
leothedragon | 0:8f0bb79ddd48 | 43 | const uint8_t *_end; // 4 bytes |
leothedragon | 0:8f0bb79ddd48 | 44 | union { |
leothedragon | 0:8f0bb79ddd48 | 45 | const uint8_t *bytes; |
leothedragon | 0:8f0bb79ddd48 | 46 | const char *text; |
leothedragon | 0:8f0bb79ddd48 | 47 | int integer; |
leothedragon | 0:8f0bb79ddd48 | 48 | } val; // 4 bytes |
leothedragon | 0:8f0bb79ddd48 | 49 | bool is_required; |
leothedragon | 0:8f0bb79ddd48 | 50 | uint16_t type; // 2 bytes |
leothedragon | 0:8f0bb79ddd48 | 51 | uint16_t len; // 2 bytes |
leothedragon | 0:8f0bb79ddd48 | 52 | } ce_tlv_element_s; |
leothedragon | 0:8f0bb79ddd48 | 53 | |
leothedragon | 0:8f0bb79ddd48 | 54 | ce_tlv_status_e ce_tlv_parser_init(const uint8_t *tlv_buf, size_t tlv_buf_len, ce_tlv_element_s *element_out); |
leothedragon | 0:8f0bb79ddd48 | 55 | ce_tlv_status_e ce_tlv_parse_next(ce_tlv_element_s *element); |
leothedragon | 0:8f0bb79ddd48 | 56 | |
leothedragon | 0:8f0bb79ddd48 | 57 | /* Checks if the given element is required or optional by testing |
leothedragon | 0:8f0bb79ddd48 | 58 | * the "type" MSB bit. [0 == required] while [1 == optional] |
leothedragon | 0:8f0bb79ddd48 | 59 | * |
leothedragon | 0:8f0bb79ddd48 | 60 | * @param element[IN] The element to test |
leothedragon | 0:8f0bb79ddd48 | 61 | * |
leothedragon | 0:8f0bb79ddd48 | 62 | * @return "true" if element is required, "false" otherwise. |
leothedragon | 0:8f0bb79ddd48 | 63 | */ |
leothedragon | 0:8f0bb79ddd48 | 64 | bool is_required(const ce_tlv_element_s *element); |
leothedragon | 0:8f0bb79ddd48 | 65 | |
leothedragon | 0:8f0bb79ddd48 | 66 | #ifdef CERT_RENEWAL_TEST |
leothedragon | 0:8f0bb79ddd48 | 67 | typedef struct ce_tlv_encoder_ { |
leothedragon | 0:8f0bb79ddd48 | 68 | uint8_t *buf; // 4 bytes |
leothedragon | 0:8f0bb79ddd48 | 69 | uint16_t encoded_length; // 2 bytes |
leothedragon | 0:8f0bb79ddd48 | 70 | uint16_t _buf_size; // 2 bytes |
leothedragon | 0:8f0bb79ddd48 | 71 | } ce_tlv_encoder_s; |
leothedragon | 0:8f0bb79ddd48 | 72 | |
leothedragon | 0:8f0bb79ddd48 | 73 | void ce_tlv_encoder_init(uint8_t *buf, uint16_t buf_size, ce_tlv_encoder_s *encoder); |
leothedragon | 0:8f0bb79ddd48 | 74 | ce_tlv_status_e tlv_add_str(ce_tlv_type_e type, uint16_t length, const char *value, bool is_tlv_required, ce_tlv_encoder_s *encoder); |
leothedragon | 0:8f0bb79ddd48 | 75 | |
leothedragon | 0:8f0bb79ddd48 | 76 | #endif // CERT_RENEWAL_TEST |
leothedragon | 0:8f0bb79ddd48 | 77 | |
leothedragon | 0:8f0bb79ddd48 | 78 | #ifdef __cplusplus |
leothedragon | 0:8f0bb79ddd48 | 79 | } |
leothedragon | 0:8f0bb79ddd48 | 80 | #endif |
leothedragon | 0:8f0bb79ddd48 | 81 | |
leothedragon | 0:8f0bb79ddd48 | 82 | #endif // __CE_TLV_H__ |
leothedragon | 0:8f0bb79ddd48 | 83 |