# class ASNLib | Class containing functions for decoding/encoding ASN.1 basic data types. More...
Full name | `TelEngine::ASNLib`
Definition | `#include <libs/yasn/yateasn.h>`
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

#### Public Types

- enum TypeTag { UNIVERSAL = 0x00, BOOLEAN = 0x01, INTEGER = 0x02, BIT_STRING = 0x03, OCTET_STRING = 0x04, NULL_ID = 0x05, OBJECT_ID = 0x06, REAL = 0x09, UTF8_STR = 0x0c, SEQUENCE = 0x30, SET = 0x31, NUMERIC_STR = 0x12, PRINTABLE_STR = 0x13, IA5_STR = 0x16, UTC_TIME = 0x17, GENERALIZED_TIME = 0x18, VISIBLE_STR = 0x1a, GENERAL_STR = 0x1b, UNIVERSAL_STR = 0x1c, CHARACTER_STR = 0x1d, BMP_STR = 0x1e, CHOICE = 0x1f, DEFINED = 0x2d }
- enum Error { InvalidLengthOrTag = -1, ConstraintBreakError = -2, ParseError = -3, InvalidContentsError = -4, IndefiniteForm = -5, }

#### Public Methods

- ASNLib ()
- ~ASNLib ()

#### Public Static Methods

- static int decodeLength (DataBlock& data)
- static int decodeBoolean (DataBlock& data, bool* val, bool tagCheck)
- static int decodeInteger (DataBlock& data, u_int64_t& intVal, unsigned int bytes, bool tagCheck)
- static int decodeUINT8 (DataBlock& data, u_int8_t* intVal, bool tagCheck)
- static int decodeUINT16 (DataBlock& data, u_int16_t* intVal, bool tagCheck)
- static int decodeUINT32 (DataBlock& data, u_int32_t* intVal, bool tagCheck)
- static int decodeUINT64 (DataBlock& data, u_int64_t* intVal, bool tagCheck)
- static int decodeINT8 (DataBlock& data, int8_t* intVal, bool tagCheck)
- static int decodeINT16 (DataBlock& data, int16_t* intVal, bool tagCheck)
- static int decodeINT32 (DataBlock& data, int32_t* intVal, bool tagCheck)
- static int decodeINT64 (DataBlock& data, int64_t* intVal, bool tagCheck)
- static int decodeBitString (DataBlock& data, String* val, bool tagCheck)
- static int decodeOctetString (DataBlock& data, OctetString* strVal, bool tagCheck)
- static int decodeNull (DataBlock& data, bool tagCheck)
- static int decodeOID (DataBlock& data, ASNObjId* obj, bool tagCheck)
- static int decodeReal (DataBlock& data, float* realVal, bool tagCheck)
- static int decodeString (DataBlock& data, String* str, int* type, bool tagCheck)
- static int decodeUtf8 (DataBlock& data, String* str, bool tagCheck)
- static int decodeGenTime (DataBlock& data, unsigned int* time, unsigned int* fractions, bool* utc, bool tagCheck)
- static int decodeUTCTime (DataBlock& data, unsigned int* time, bool tagCheck)
- static int decodeAny (DataBlock data, DataBlock* val, bool tagCheck)
- static int decodeSequence (DataBlock& data, bool tagCheck)
- static int decodeSet (DataBlock& data, bool tagCheck)
- static DataBlock buildLength (DataBlock& data)
- static DataBlock encodeBoolean (bool val, bool tagCheck)
- static DataBlock encodeInteger (u_int64_t intVal, bool tagCheck)
- static DataBlock encodeOctetString (OctetString strVal, bool tagCheck)
- static DataBlock encodeNull (bool tagCheck)
- static DataBlock encodeBitString (String val, bool tagCheck)
- static DataBlock encodeOID (ASNObjId obj, bool tagCheck)
- static DataBlock encodeReal (float val, bool tagCheck)
- static DataBlock encodeString (String str, int type, bool tagCheck)
- static DataBlock encodeUtf8 (String str, bool tagCheck)
- static DataBlock encodeGenTime (unsigned int time, unsigned int fractions, bool tagCheck)
- static DataBlock encodeUTCTime (unsigned int time, bool tagCheck)
- static DataBlock encodeAny (DataBlock data, bool tagCheck)
- static int encodeSequence (DataBlock& data, bool tagCheck)
- static int encodeSet (DataBlock& data, bool tagCheck)
- static int matchEOC (DataBlock& data)
- static int parseUntilEoC (DataBlock& data, int length = 0)

## Detailed Description

Class ASNLib

enum TypeTag { UNIVERSAL = 0x00, BOOLEAN = 0x01, INTEGER = 0x02, BIT_STRING = 0x03, OCTET_STRING = 0x04, NULL_ID = 0x05, OBJECT_ID = 0x06, REAL = 0x09, UTF8_STR = 0x0c, SEQUENCE = 0x30, SET = 0x31, NUMERIC_STR = 0x12, PRINTABLE_STR = 0x13, IA5_STR = 0x16, UTC_TIME = 0x17, GENERALIZED_TIME = 0x18, VISIBLE_STR = 0x1a, GENERAL_STR = 0x1b, UNIVERSAL_STR = 0x1c, CHARACTER_STR = 0x1d, BMP_STR = 0x1e, CHOICE = 0x1f, DEFINED = 0x2d } | ### TypeTag

ASN.1 Type tags

enum Error { InvalidLengthOrTag = -1, ConstraintBreakError = -2, ParseError = -3, InvalidContentsError = -4, IndefiniteForm = -5, } | ### Error

Error types

ASNLib () | ### ASNLib

Constructor

~ASNLib () | ### ~ASNLib

Destructor

int decodeLength (DataBlock& data) | ### decodeLength

[static]

Decode the length of the block data containing the ASN.1 type data

Parameters:

data | Input block from which to extract the length

Returns: The length of the data block containing data, -1 if it couldn't be decoded

int decodeBoolean (DataBlock& data, bool* val, bool tagCheck) | ### decodeBoolean

[static]

Decode a boolean value from the encoded data

Parameters:

data | Input block from which the boolean value should be extracted
val | Pointer to a boolean to be filled with the decoded value
tagCheck | Flag for indicating if in the process of decoding the value the presence of the ASN.1 tag for boolean (0x01) should be verified

Returns: Length of data consumed from the input data it the decoding was successful, -1 if the boolean value could not be decoded

int decodeInteger (DataBlock& data, u_int64_t& intVal, unsigned int bytes, bool tagCheck) | ### decodeInteger

[static]

Decode an integer value from the encoded data

Parameters:

data | Input block from which the integer value should be extracted
intVal | Integer to be filled with the decoded value
bytes | Width of the decoded integer field
tagCheck | Flag for indicating if in the process of decoding the value the presence of the ASN.1 tag for integer (0x02) should be verified

Returns: Length of data consumed from the input data it the decoding was successful, -1 if the integer value could not be decoded

int decodeUINT8 (DataBlock& data, u_int8_t* intVal, bool tagCheck) | ### decodeUINT8

[static]

Decode an unsigned integer value from the encoded data - helper function for casting from u_int64_t to u_int8_t in case of size constraints

Parameters:

data | Input block from which the integer value should be extracted
intVal | Integer to be filled with the decoded value
tagCheck | Flag for indicating if in the process of decoding the value the presence of the ASN.1 tag for integer (0x02) should be verified

Returns: Length of data consumed from the input data it the decoding was successful, -1 if the integer value could not be decoded

int decodeUINT16 (DataBlock& data, u_int16_t* intVal, bool tagCheck) | ### decodeUINT16

[static]

Decode an unsigned integer value from the encoded data - helper function for casting from u_int64_t to u_int16_t in case of size constraints

Parameters:

data | Input block from which the integer value should be extracted
intVal | Integer to be filled with the decoded value
tagCheck | Flag for indicating if in the process of decoding the value the presence of the ASN.1 tag for integer (0x02) should be verified

Returns: Length of data consumed from the input data it the decoding was successful, -1 if the integer value could not be decoded

int decodeUINT32 (DataBlock& data, u_int32_t* intVal, bool tagCheck) | ### decodeUINT32

[static]

Decode an unsigned integer value from the encoded data - helper function for casting from u_int64_t to u_int32_t in case of size constraints

Parameters:

data | Input block from which the integer value should be extracted
intVal | Integer to be filled with the decoded value
tagCheck | Flag for indicating if in the process of decoding the value the presence of the ASN.1 tag for integer (0x02) should be verified

Returns: Length of data consumed from the input data it the decoding was successful, -1 if the integer value could not be decoded

int decodeUINT64 (DataBlock& data, u_int64_t* intVal, bool tagCheck) | ### decodeUINT64

[static]

Decode an unsigned integer value from the encoded data - helper function for casting in case of size constraints

Parameters:

data | Input block from which the integer value should be extracted
intVal | Integer to be filled with the decoded value
tagCheck | Flag for indicating if in the process of decoding the value the presence of the ASN.1 tag for integer (0x02) should be verified

Returns: Length of data consumed from the input data it the decoding was successful, -1 if the integer value could not be decoded

int decodeINT8 (DataBlock& data, int8_t* intVal, bool tagCheck) | ### decodeINT8

[static]

Decode an integer value from the encoded data - helper function for casting from u_int64_t to int8_t in case of size constraints

Parameters:

data | Input block from which the integer value should be extracted
intVal | Integer to be filled with the decoded value
tagCheck | Flag for indicating if in the process of decoding the value the presence of the ASN.1 tag for integer (0x02) should be verified

Returns: Length of data consumed from the input data it the decoding was successful, -1 if the integer value could not be decoded

int decodeINT16 (DataBlock& data, int16_t* intVal, bool tagCheck) | ### decodeINT16

[static]

Decode an integer value from the encoded data - helper function for casting from u_int64_t to int16_t in case of size constraints

Parameters:

data | Input block from which the integer value should be extracted
intVal | Integer to be filled with the decoded value
tagCheck | Flag for indicating if in the process of decoding the value the presence of the ASN.1 tag for integer (0x02) should be verified

Returns: Length of data consumed from the input data it the decoding was successful, -1 if the integer value could not be decoded

int decodeINT32 (DataBlock& data, int32_t* intVal, bool tagCheck) | ### decodeINT32

[static]

Decode an integer value from the encoded data - helper function for casting from u_int64_t to int32_t in case of size constraints

Parameters:

data | Input block from which the integer value should be extracted
intVal | Integer to be filled with the decoded value
tagCheck | Flag for indicating if in the process of decoding the value the presence of the ASN.1 tag for integer (0x02) should be verified

Returns: Length of data consumed from the input data it the decoding was successful, -1 if the integer value could not be decoded

int decodeINT64 (DataBlock& data, int64_t* intVal, bool tagCheck) | ### decodeINT64

[static]

Decode an integer value from the encoded data - helper function for casting in case of size constraints

Parameters:

data | Input block from which the integer value should be extracted
intVal | Integer to be filled with the decoded value
tagCheck | Flag for indicating if in the process of decoding the value the presence of the ASN.1 tag for integer (0x02) should be verified

Returns: Length of data consumed from the input data it the decoding was successful, -1 if the integer value could not be decoded

int decodeBitString (DataBlock& data, String* val, bool tagCheck) | ### decodeBitString

[static]

Decode a bitstring value from the encoded data

Parameters:

data | Input block from which the bitstring value should be extracted
val | String to be filled with the decoded value
tagCheck | Flag for indicating if in the process of decoding the value the presence of the ASN.1 tag for integer (0x03) should be verified

Returns: Length of data consumed from the input data it the decoding was successful, -1 if the integer value could not be decoded

int decodeOctetString (DataBlock& data, OctetString* strVal, bool tagCheck) | ### decodeOctetString

[static]

Decode a string value from the encoded data

Parameters:

data | Input block from which the octet string value should be extracted
strVal | String to be filled with the decoded value
tagCheck | Flag for indicating if in the process of decoding the value the presence of the ASN.1 tag for integer (0x04) should be verified

Returns: Length of data consumed from the input data it the decoding was successful, -1 if the integer value could not be decoded

int decodeNull (DataBlock& data, bool tagCheck) | ### decodeNull

[static]

Decode a null value from the encoded data

Parameters:

data | Input block from which the null value should be extracted
tagCheck | Flag for indicating if in the process of decoding the value the presence of the ASN.1 tag for integer (0x05) should be verified

Returns: Length of data consumed from the input data it the decoding was successful, -1 if the integer value could not be decoded

int decodeOID (DataBlock& data, ASNObjId* obj, bool tagCheck) | ### decodeOID

[static]

Decode an object id value from the encoded data

Parameters:

data | Input block from which the OID value should be extracted
obj | ASNObjId to be filled with the decoded value
tagCheck | Flag for indicating if in the process of decoding the value the presence of the ASN.1 tag for integer (0x06) should be verified

Returns: Length of data consumed from the input data it the decoding was successful, -1 if the integer value could not be decoded

int decodeReal (DataBlock& data, float* realVal, bool tagCheck) | ### decodeReal

[static]

Decode a real value from the encoded data - not implemented

Parameters:

data | Input block from which the real value should be extracted
realVal | Float to be filled with the decoded value
tagCheck | Flag for indicating if in the process of decoding the value the presence of the ASN.1 tag for integer (0x09) should be verified

Returns: Length of data consumed from the input data it the decoding was successful, -1 if the integer value could not be decoded

int decodeString (DataBlock& data, String* str, int* type, bool tagCheck) | ### decodeString

[static]

Decode other types of ASN.1 strings from the encoded data (NumericString, PrintableString, VisibleString, IA5String)

Parameters:

data | Input block from which the string value should be extracted
str | String to be filled with the decoded value
type | Integer to be filled with the value indicating which type of string has been decoded
tagCheck | Flag for indicating if in the process of decoding the value the presence of the ASN.1 tag should be verified

Returns: Length of data consumed from the input data it the decoding was successful, -1 if the integer value could not be decoded

int decodeUtf8 (DataBlock& data, String* str, bool tagCheck) | ### decodeUtf8

[static]

Decode an UTF8 string from the encoded data

Parameters:

data | Input block from which the string value should be extracted
str | String to be filled with the decoded value
tagCheck | Flag for indicating if in the process of decoding the value the presence of the ASN.1 tag (0x0c) should be verified

Returns: Length of data consumed from the input data it the decoding was successful, -1 if the integer value could not be decoded

int decodeGenTime (DataBlock& data, unsigned int* time, unsigned int* fractions, bool* utc, bool tagCheck) | ### decodeGenTime

[static]

Decode a GeneralizedTime value from the encoded data

Parameters:

data | Input block from which the value should be extracted
time | Integer to be filled with time in seconds since epoch
fractions | Integer to be filled with fractions of a second
utc | Flag indicating if the decode time value represent local time or UTC time
tagCheck | Flag for indicating if in the process of decoding the value the presence of the ASN.1 tag (0x18) should be verified

Returns: Length of data consumed from the input data it the decoding was successful, -1 if the integer value could not be decoded

int decodeUTCTime (DataBlock& data, unsigned int* time, bool tagCheck) | ### decodeUTCTime

[static]

Decode a UTC time value from the encoded data

Parameters:

data | Input block from which the value should be extracted
time | Integer to be filled with time in seconds since epoch
tagCheck | Flag for indicating if in the process of decoding the value the presence of the ASN.1 tag (0x17) should be verified

Returns: Length of data consumed from the input data it the decoding was successful, -1 if the integer value could not be decoded

int decodeAny (DataBlock data, DataBlock* val, bool tagCheck) | ### decodeAny

[static]

Decode a block of arbitrary data

Parameters:

data | Input block from which the value should be extracted
val | DataBlock in which the data shoulb be copied
tagCheck | Flag for indicating if in the process of decoding the value the presence of the ASN.1 should be verified

Returns: Length of data consumed from the input data it the decoding was successful, -1 if the integer value could not be decoded

int decodeSequence (DataBlock& data, bool tagCheck) | ### decodeSequence

[static]

Decode the header of an ASN.1 sequence ( decodes the tag and the length of the sequence)

Parameters:

data | Input block from which the header should be extracted
tagCheck | Flag for indicating if in the process of decoding the value the presence of the ASN.1 (0x30) should be verified

Returns: Length of data consumed from the input data it the decoding was succesful, -1 if the integer value could not be decoded

int decodeSet (DataBlock& data, bool tagCheck) | ### decodeSet

[static]

Decode the header of an ASN.1 set ( decodes the tag and the length of the sequence)

Parameters:

data | Input block from which the header should be extracted
tagCheck | Flag for indicating if in the process of decoding the value the presence of the ASN.1 (0x31) should be verified

Returns: Length of data consumed from the input data it the decoding was succesful, -1 if the integer value could not be decoded

DataBlock buildLength (DataBlock& data) | ### buildLength

[static]

Encode the length of the given data

Parameters:

data | The data for which the length should be encoded

Returns: The data block which now contains the length encoding

DataBlock encodeBoolean (bool val, bool tagCheck) | ### encodeBoolean

[static]

Encode the given boolean value

Parameters:

val | The boolean value to encode
tagCheck | Flag to specify if the boolean type tag should be inserted in the encoding

Returns: The data block encoding of the value

DataBlock encodeInteger (u_int64_t intVal, bool tagCheck) | ### encodeInteger

[static]

Encode the given integer value

Parameters:

intVal | The integer value to encode
tagCheck | Flag to specify if the integer type tag should be inserted in the encoding

Returns: The data block encoding of the value

DataBlock encodeOctetString (OctetString strVal, bool tagCheck) | ### encodeOctetString

[static]

Encode the given octet string value

Parameters:

strVal | The octet string value to encode
tagCheck | Flag to specify if the octet string type tag should be inserted in the encoding

Returns: The data block encoding of the value

DataBlock encodeNull (bool tagCheck) | ### encodeNull

[static]

Encode a null value

Parameters:

tagCheck | Flag to specify if the null tag should be inserted in the encoding

Returns: The data block encoding of the value

DataBlock encodeBitString (String val, bool tagCheck) | ### encodeBitString

[static]

Encode the given bitstring value

Parameters:

val | The bitstring value to encode
tagCheck | Flag to specify if the type tag should be inserted in the encoding

Returns: The data block encoding of the value

DataBlock encodeOID (ASNObjId obj, bool tagCheck) | ### encodeOID

[static]

Encode the given OID value

Parameters:

obj | The OID value to encode
tagCheck | Flag to specify if the type tag should be inserted in the encoding

Returns: The data block encoding of the value

DataBlock encodeReal (float val, bool tagCheck) | ### encodeReal

[static]

Encode the given real value - not implemented

Parameters:

val | The real value to encode
tagCheck | Flag to specify if the type tag should be inserted in the encoding

Returns: The data block encoding of the value

DataBlock encodeString (String str, int type, bool tagCheck) | ### encodeString

[static]

Encode the given string value to NumericString, PrintableString, IA5String, VisibleString

Parameters:

str | The string value to encode
type | The type of the encoding
tagCheck | Flag to specify if the type tag should be inserted in the encoding

Returns: The data block encoding of the value

DataBlock encodeUtf8 (String str, bool tagCheck) | ### encodeUtf8

[static]

Encode the UTF8 string value

Parameters:

str | The string value to encode
tagCheck | Flag to specify if the type tag should be inserted in the encoding

Returns: The data block encoding of the value

DataBlock encodeGenTime (unsigned int time, unsigned int fractions, bool tagCheck) | ### encodeGenTime

[static]

Encode the given time value into a GeneralizedTime format

Parameters:

time | Time in seconds since epoch to encode
fractions | Fractions of a seconds to encode
tagCheck | Flag to specify if the type tag should be inserted in the encoding

Returns: The data block encoding of the value

DataBlock encodeUTCTime (unsigned int time, bool tagCheck) | ### encodeUTCTime

[static]

Encode the given time value into an UTCTime format

Parameters:

time | Time in seconds since epoch to encode
tagCheck | Flag to specify if the type tag should be inserted in the encoding

Returns: The data block encoding of the value

DataBlock encodeAny (DataBlock data, bool tagCheck) | ### encodeAny

[static]

Encode an arbitrary block a data

Parameters:

data | data
tagCheck | Flag to specify if the type tag should be inserted in the encoding

Returns: The data block encoding of the value

int encodeSequence (DataBlock& data, bool tagCheck) | ### encodeSequence

[static]

Encode the header for a sequence

Parameters:

data | Sequence data for which the header is encoded
tagCheck | Flag to specify if the ype tag should be inserted in the encoding

Returns: The length of the data block length encoding

int encodeSet (DataBlock& data, bool tagCheck) | ### encodeSet

[static]

Encode the header for a set

Parameters:

data | Sequence data for which the header is encoded
tagCheck | Flag to specify if the type tag should be inserted in the encoding

Returns: The length of the data block length encoding

int matchEOC (DataBlock& data) | ### matchEOC

[static]

Verify the data for End Of Contents presence

Parameters:

data | Input block to verify

Returns: Length of data consumed from the input data it the decoding was succesful, it should be 2 in case of success, -1 if the data doesn't match EoC

int parseUntilEoC (DataBlock& data, int length = 0) | ### parseUntilEoC

[static]

Extract length until a End Of Contents is found.

Parameters:

data | Input block for which to determine the length to End Of Contents
length | Length to which to add determined length

Returns: Length until End Of Contents

Generated by: paulc on bussard on Mon Feb 10 13:15:47 2014, using kdoc 2.0a54.