1 /* 2 * coap_asn1_internal.h -- ASN.1 functions for libcoap 3 * 4 * Copyright (C) 2020 Jon Shallow <supjps-libcoap@jpshallow.com> 5 * 6 * SPDX-License-Identifier: BSD-2-Clause 7 * 8 * This file is part of the CoAP library libcoap. Please see README for terms 9 * of use. 10 */ 11 12 /** 13 * @file coap_asn1_internal.h 14 * @brief COAP ASN.1 internal information 15 */ 16 17 #ifndef COAP_ASN1_INTERNAL_H_ 18 #define COAP_ASN1_INTERNAL_H_ 19 20 21 /** 22 * @defgroup asn1 ASN.1 Support (Internal) 23 * CoAP ASN.1 Structures, Enums and Functions that are not exposed to 24 * applications 25 * @{ 26 */ 27 28 typedef enum { 29 COAP_ASN1_NONE = 0, 30 COAP_ASN1_INTEGER = 2, 31 COAP_ASN1_BITSTRING = 3, 32 COAP_ASN1_OCTETSTRING = 4, 33 COAP_ASN1_IDENTIFIER = 6, 34 } coap_asn1_tag_t; 35 36 /** 37 * Callback to validate the asn1 tag and data. 38 * 39 * Internal function. 40 * 41 * @param data The start of the tag and data 42 * @param size The size of the tag and data 43 * 44 * @return @c 1 if pass, else @c 0 if fail 45 */ 46 typedef int (*asn1_validate)(const uint8_t *data, size_t size); 47 48 /** 49 * Get the asn1 length from the current @p ptr. 50 * 51 * Internal function. 52 * 53 * @param ptr The current asn.1 object length pointer 54 * 55 * @return The length of the asn.1 object. @p ptr is updated to be after the length. 56 */ 57 size_t asn1_len(const uint8_t **ptr); 58 59 /** 60 * Get the asn1 tag from the current @p ptr. 61 * 62 * Internal function. 63 * 64 * @param ptr The current asn.1 object tag pointer 65 * @param constructed 1 if current tag is constructed 66 * @param class The current class of the tag 67 * 68 * @return The tag value.@p ptr is updated to be after the tag. 69 */ 70 coap_asn1_tag_t asn1_tag_c(const uint8_t **ptr, int *constructed, int *class); 71 72 /** 73 * Get the asn1 tag and data from the current @p ptr. 74 * 75 * Internal function. 76 * 77 * @param ltag The tag to look for 78 * @param ptr The current asn.1 object pointer 79 * @param tlen The remaining size oof the asn.1 data 80 * @param validate Call validate to verify tag data or @c NULL 81 * 82 * @return The asn.1 tag and data or @c NULL if not found 83 */ 84 coap_binary_t *get_asn1_tag(coap_asn1_tag_t ltag, const uint8_t *ptr, 85 size_t tlen, asn1_validate validate); 86 87 /** @} */ 88 89 #endif /* COAP_ASN1_INTERNAL_H_ */ 90