Pfp Cybersecurity (Aka Power Fingerprinting, Inc.) / Mbed OS pfp-emon-nxp

Dependencies:   FXAS21002 FXOS8700Q

Committer:
vithyat
Date:
Fri Mar 20 20:15:18 2020 +0000
Revision:
2:990c985a69ae
Parent:
0:977e87915078
Update to work with P2Scan runtime

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vithyat 0:977e87915078 1 // ----------------------------------------------------------------------------
vithyat 0:977e87915078 2 // Copyright 2018 ARM Ltd.
vithyat 0:977e87915078 3 //
vithyat 0:977e87915078 4 // Licensed under the Apache License, Version 2.0 (the "License");
vithyat 0:977e87915078 5 // you may not use this file except in compliance with the License.
vithyat 0:977e87915078 6 // You may obtain a copy of the License at
vithyat 0:977e87915078 7 //
vithyat 0:977e87915078 8 // http://www.apache.org/licenses/LICENSE-2.0
vithyat 0:977e87915078 9 //
vithyat 0:977e87915078 10 // Unless required by applicable law or agreed to in writing, software
vithyat 0:977e87915078 11 // distributed under the License is distributed on an "AS IS" BASIS,
vithyat 0:977e87915078 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
vithyat 0:977e87915078 13 // See the License for the specific language governing permissions and
vithyat 0:977e87915078 14 // limitations under the License.
vithyat 0:977e87915078 15 // ----------------------------------------------------------------------------
vithyat 0:977e87915078 16
vithyat 0:977e87915078 17 #ifndef __CE_TLV_H__
vithyat 0:977e87915078 18 #define __CE_TLV_H__
vithyat 0:977e87915078 19
vithyat 0:977e87915078 20 #ifdef __cplusplus
vithyat 0:977e87915078 21 extern "C" {
vithyat 0:977e87915078 22 #endif
vithyat 0:977e87915078 23 #include <stdint.h>
vithyat 0:977e87915078 24 #include <stdbool.h>
vithyat 0:977e87915078 25 #include <stddef.h>
vithyat 0:977e87915078 26
vithyat 0:977e87915078 27 typedef enum {
vithyat 0:977e87915078 28 CE_TLV_STATUS_SUCCESS,
vithyat 0:977e87915078 29 CE_TLV_STATUS_END,
vithyat 0:977e87915078 30 CE_TLV_STATUS_INVALID_ARG,
vithyat 0:977e87915078 31 CE_TLV_STATUS_TEXT_NOT_TERMINATED,
vithyat 0:977e87915078 32 CE_TLV_STATUS_MALFORMED_TLV,
vithyat 0:977e87915078 33 CE_TLV_STATUS_ERROR,
vithyat 0:977e87915078 34 CE_TLV_STATUS_ENCODER_INSUFFICIENT_BUFFER
vithyat 0:977e87915078 35 } ce_tlv_status_e;
vithyat 0:977e87915078 36
vithyat 0:977e87915078 37 typedef enum {
vithyat 0:977e87915078 38 CE_TLV_TYPE_CERT_NAME = 1
vithyat 0:977e87915078 39 } ce_tlv_type_e;
vithyat 0:977e87915078 40
vithyat 0:977e87915078 41 typedef struct ce_tlv_element_ {
vithyat 0:977e87915078 42 const uint8_t *_current; // 4 bytes
vithyat 0:977e87915078 43 const uint8_t *_end; // 4 bytes
vithyat 0:977e87915078 44 union {
vithyat 0:977e87915078 45 const uint8_t *bytes;
vithyat 0:977e87915078 46 const char *text;
vithyat 0:977e87915078 47 int integer;
vithyat 0:977e87915078 48 } val; // 4 bytes
vithyat 0:977e87915078 49 bool is_required;
vithyat 0:977e87915078 50 uint16_t type; // 2 bytes
vithyat 0:977e87915078 51 uint16_t len; // 2 bytes
vithyat 0:977e87915078 52 } ce_tlv_element_s;
vithyat 0:977e87915078 53
vithyat 0:977e87915078 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);
vithyat 0:977e87915078 55 ce_tlv_status_e ce_tlv_parse_next(ce_tlv_element_s *element);
vithyat 0:977e87915078 56
vithyat 0:977e87915078 57 /* Checks if the given element is required or optional by testing
vithyat 0:977e87915078 58 * the "type" MSB bit. [0 == required] while [1 == optional]
vithyat 0:977e87915078 59 *
vithyat 0:977e87915078 60 * @param element[IN] The element to test
vithyat 0:977e87915078 61 *
vithyat 0:977e87915078 62 * @return "true" if element is required, "false" otherwise.
vithyat 0:977e87915078 63 */
vithyat 0:977e87915078 64 bool is_required(const ce_tlv_element_s *element);
vithyat 0:977e87915078 65
vithyat 0:977e87915078 66 #ifdef CERT_RENEWAL_TEST
vithyat 0:977e87915078 67 typedef struct ce_tlv_encoder_ {
vithyat 0:977e87915078 68 uint8_t *buf; // 4 bytes
vithyat 0:977e87915078 69 uint16_t encoded_length; // 2 bytes
vithyat 0:977e87915078 70 uint16_t _buf_size; // 2 bytes
vithyat 0:977e87915078 71 } ce_tlv_encoder_s;
vithyat 0:977e87915078 72
vithyat 0:977e87915078 73 void ce_tlv_encoder_init(uint8_t *buf, uint16_t buf_size, ce_tlv_encoder_s *encoder);
vithyat 0:977e87915078 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);
vithyat 0:977e87915078 75
vithyat 0:977e87915078 76 #endif // CERT_RENEWAL_TEST
vithyat 0:977e87915078 77
vithyat 0:977e87915078 78 #ifdef __cplusplus
vithyat 0:977e87915078 79 }
vithyat 0:977e87915078 80 #endif
vithyat 0:977e87915078 81
vithyat 0:977e87915078 82 #endif // __CE_TLV_H__
vithyat 0:977e87915078 83