1/* 2 * coap_asn1_internal.h -- ASN.1 functions for libcoap 3 * 4 * Copyright (C) 2020-2023 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#include "coap_internal.h" 21 22/** 23 * @ingroup internal_api 24 * @defgroup asn1 ASN.1 Support 25 * Internal API for CoAP ASN.1 handling 26 * @{ 27 */ 28 29typedef enum { 30 COAP_ASN1_NONE = 0, 31 COAP_ASN1_INTEGER = 2, 32 COAP_ASN1_BITSTRING = 3, 33 COAP_ASN1_OCTETSTRING = 4, 34 COAP_ASN1_IDENTIFIER = 6, 35} coap_asn1_tag_t; 36 37/** 38 * Callback to validate the asn1 tag and data. 39 * 40 * Internal function. 41 * 42 * @param data The start of the tag and data 43 * @param size The size of the tag and data 44 * 45 * @return @c 1 if pass, else @c 0 if fail 46 */ 47typedef int (*asn1_validate)(const uint8_t *data, size_t size); 48 49/** 50 * Get the asn1 length from the current @p ptr. 51 * 52 * Internal function. 53 * 54 * @param ptr The current asn.1 object length pointer 55 * 56 * @return The length of the asn.1 object. @p ptr is updated to be after the length. 57 */ 58size_t asn1_len(const uint8_t **ptr); 59 60/** 61 * Get the asn1 tag from the current @p ptr. 62 * 63 * Internal function. 64 * 65 * @param ptr The current asn.1 object tag pointer 66 * @param constructed 1 if current tag is constructed 67 * @param cls The current class of the tag 68 * 69 * @return The tag value.@p ptr is updated to be after the tag. 70 */ 71coap_asn1_tag_t asn1_tag_c(const uint8_t **ptr, int *constructed, int *cls); 72 73/** 74 * Get the asn1 tag and data from the current @p ptr. 75 * 76 * Internal function. 77 * 78 * @param ltag The tag to look for 79 * @param ptr The current asn.1 object pointer 80 * @param tlen The remaining size oof the asn.1 data 81 * @param validate Call validate to verify tag data or @c NULL 82 * 83 * @return The asn.1 tag and data (to be freed off by caller) 84 * or @c NULL if not found 85 */ 86coap_binary_t *get_asn1_tag(coap_asn1_tag_t ltag, const uint8_t *ptr, 87 size_t tlen, asn1_validate validate); 88 89/** @} */ 90 91#endif /* COAP_ASN1_INTERNAL_H_ */ 92