RPK: Move common asn1 code into separate file

src/coap_asn1.c: (New)
include/coap2/coap_asn1_internal.h: (New)

Created and common asn1 functions added in

Makefile.am:
include/coap2/coap_internal.h:

Reference the new files.

src/coap_gnutls.c:
src/coap_tinydtls.c:

Updated to use new common asn1 functions.
This commit is contained in:
Jon Shallow committed 2020-10-22 12:21:37 +01:00
1 parent 25fbb26c60
commit e5d052cd57
6 files changed
+250 -261

No files matched your search

+78
View File
@@ -0,0 +1,78 @@
/*
* coap_asn1_internal.h -- ASN.1 functions for libcoap
*
* Copyright (C) 2020 Jon Shallow <supjps-libcoap@jpshallow.com>
*
* This file is part of the CoAP library libcoap. Please see README for terms
* of use.
*/
/**
* @file coap_asn1_internal.h
* @brief COAP ASN.1 internal information
*/
#ifndef COAP_ASN1_INTERNAL_H_
#define COAP_ASN1_INTERNAL_H_
/**
* @defgroup asn1 ASN.1 Support (Internal)
* API functions for CoAP ASN.1
* @{
*/
typedef enum {
COAP_ASN1_NONE = 0,
COAP_ASN1_INTEGER = 2,
COAP_ASN1_BITSTRING = 3,
COAP_ASN1_OCTETSTRING = 4,
COAP_ASN1_IDENTIFIER = 6,
} coap_asn1_tag_t;
/**
* Callback to validate the asn1 tag and data.
*
* @param data The start of the tag and data
* @param size The size of the tag and data
*
* @return @c 1 if pass, else @c 0 if fail
*/
typedef int (*asn1_validate)(const uint8_t *data, size_t size);
/**
* Get the asn1 length from the current @p ptr.
*
* @param ptr The current asn.1 object length pointer
*
* @return The length of the asn.1 object. @p ptr is udated to past the length.
*/
size_t asn1_len(const uint8_t **ptr);
/**
* Get the asn1 tag from the current @p ptr.
*
* @param ptr The current asn.1 object tag pointer
* @param constructed 1 if current tag is constructed
* @param class The current class of the tag
*
* @return The tag value.@p ptr is udated to pass the tag.
*/
coap_asn1_tag_t asn1_tag_c(const uint8_t **ptr, int *constructed, int *class);
/**
* Get the asn1 tag and data from the current @p ptr.
*
* @param ltag The tag to look for
* @param ptr The current asn.1 object pointer
* @param tlen The remaining size oof the asn.1 data
* @param validate Call validate to verify tag data or @c NULL
*
* @return The asn.1 tag and data or @c NULL if not found
*/
coap_binary_t *get_asn1_tag(coap_asn1_tag_t ltag, const uint8_t *ptr,
size_t tlen, asn1_validate validate);
/** @} */
#endif /* COAP_ASN1_INTERNAL_H_ */
+1
View File
@@ -46,6 +46,7 @@
#include "coap_mutex.h"
/* Specifically defined internal .h files */
#include "coap_asn1_internal.h"
#include "coap_cache_internal.h"
#include "coap_session_internal.h"
#include "coap_subscribe_internal.h"