Blame src/asn1c/ber_tlv_tag.h

Packit 728676
/*-
Packit 728676
 * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
Packit 728676
 * Redistribution and modifications are permitted subject to BSD license.
Packit 728676
 */
Packit 728676
#ifndef	_BER_TLV_TAG_H_
Packit 728676
#define	_BER_TLV_TAG_H_
Packit 728676
Packit 728676
#ifdef __cplusplus
Packit 728676
extern "C" {
Packit 728676
#endif
Packit 728676
Packit 728676
enum asn_tag_class {
Packit 728676
	ASN_TAG_CLASS_UNIVERSAL		= 0,	/* 0b00 */
Packit 728676
	ASN_TAG_CLASS_APPLICATION	= 1,	/* 0b01 */
Packit 728676
	ASN_TAG_CLASS_CONTEXT		= 2,	/* 0b10 */
Packit 728676
	ASN_TAG_CLASS_PRIVATE		= 3	/* 0b11 */
Packit 728676
};
Packit 728676
typedef unsigned ber_tlv_tag_t;	/* BER TAG from Tag-Length-Value */
Packit 728676
Packit 728676
/*
Packit 728676
 * Tag class is encoded together with tag value for optimization purposes.
Packit 728676
 */
Packit 728676
#define	BER_TAG_CLASS(tag)	((tag) & 0x3)
Packit 728676
#define	BER_TAG_VALUE(tag)	((tag) >> 2)
Packit 728676
#define	BER_TLV_CONSTRUCTED(tagptr)	(((*(const uint8_t *)tagptr)&0x20)?1:0)
Packit 728676
Packit 728676
#define	BER_TAGS_EQUAL(tag1, tag2)	((tag1) == (tag2))
Packit 728676
Packit 728676
/*
Packit 728676
 * Several functions for printing the TAG in the canonical form
Packit 728676
 * (i.e. "[PRIVATE 0]").
Packit 728676
 * Return values correspond to their libc counterparts (if any).
Packit 728676
 */
Packit 728676
ssize_t ber_tlv_tag_snprint(ber_tlv_tag_t tag, char *buf, size_t buflen);
Packit 728676
ssize_t ber_tlv_tag_fwrite(ber_tlv_tag_t tag, FILE *);
Packit 728676
char *ber_tlv_tag_string(ber_tlv_tag_t tag);
Packit 728676
Packit 728676
Packit 728676
/*
Packit 728676
 * This function tries to fetch the tag from the input stream.
Packit 728676
 * RETURN VALUES:
Packit 728676
 * 	 0:	More data expected than bufptr contains.
Packit 728676
 * 	-1:	Fatal error deciphering tag.
Packit 728676
 *	>0:	Number of bytes used from bufptr. tag_r will contain the tag.
Packit 728676
 */
Packit 728676
ssize_t ber_fetch_tag(const void *bufptr, size_t size, ber_tlv_tag_t *tag_r);
Packit 728676
Packit 728676
/*
Packit 728676
 * This function serializes the tag (T from TLV) in BER format.
Packit 728676
 * It always returns number of bytes necessary to represent the tag,
Packit 728676
 * it is a caller's responsibility to check the return value
Packit 728676
 * against the supplied buffer's size.
Packit 728676
 */
Packit 728676
size_t ber_tlv_tag_serialize(ber_tlv_tag_t tag, void *bufptr, size_t size);
Packit 728676
Packit 728676
#ifdef __cplusplus
Packit 728676
}
Packit 728676
#endif
Packit 728676
Packit 728676
#endif	/* _BER_TLV_TAG_H_ */