2 * Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
\r
3 * Redistribution and modifications are permitted subject to BSD license.
\r
5 #ifndef _BER_TLV_TAG_H_
\r
6 #define _BER_TLV_TAG_H_
\r
12 enum asn_tag_class {
\r
13 ASN_TAG_CLASS_UNIVERSAL = 0, /* 0b00 */
\r
14 ASN_TAG_CLASS_APPLICATION = 1, /* 0b01 */
\r
15 ASN_TAG_CLASS_CONTEXT = 2, /* 0b10 */
\r
16 ASN_TAG_CLASS_PRIVATE = 3 /* 0b11 */
\r
18 typedef unsigned ber_tlv_tag_t; /* BER TAG from Tag-Length-Value */
\r
21 * Tag class is encoded together with tag value for optimization purposes.
\r
23 #define BER_TAG_CLASS(tag) ((tag) & 0x3)
\r
24 #define BER_TAG_VALUE(tag) ((tag) >> 2)
\r
25 #define BER_TLV_CONSTRUCTED(tagptr) (((*(const uint8_t *)tagptr)&0x20)?1:0)
\r
27 #define BER_TAGS_EQUAL(tag1, tag2) ((tag1) == (tag2))
\r
30 * Several functions for printing the TAG in the canonical form
\r
31 * (i.e. "[PRIVATE 0]").
\r
32 * Return values correspond to their libc counterparts (if any).
\r
34 ssize_t ber_tlv_tag_snprint(ber_tlv_tag_t tag, char *buf, size_t buflen);
\r
35 ssize_t ber_tlv_tag_fwrite(ber_tlv_tag_t tag, FILE *);
\r
36 char *ber_tlv_tag_string(ber_tlv_tag_t tag);
\r
40 * This function tries to fetch the tag from the input stream.
\r
42 * 0: More data expected than bufptr contains.
\r
43 * -1: Fatal error deciphering tag.
\r
44 * >0: Number of bytes used from bufptr. tag_r will contain the tag.
\r
46 ssize_t ber_fetch_tag(const void *bufptr, size_t size, ber_tlv_tag_t *tag_r);
\r
49 * This function serializes the tag (T from TLV) in BER format.
\r
50 * It always returns number of bytes necessary to represent the tag,
\r
51 * it is a caller's responsibility to check the return value
\r
52 * against the supplied buffer's size.
\r
54 size_t ber_tlv_tag_serialize(ber_tlv_tag_t tag, void *bufptr, size_t size);
\r
60 #endif /* _BER_TLV_TAG_H_ */
\r