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