CanonicalEncodingRulesElement

The unit of encoding and decoding for Canonical Encoding Rules (CER).

There are three parts to an element encoded according to the Canonical Encoding Rules (CER):

  • A Type Tag, which specifies what data type is encoded
  • A Length Tag, which specifies how many subsequent bytes encode the data
  • The Encoded Value

They appear in the binary encoding in that order, and as such, the encoding scheme is sometimes described as "TLV," which stands for Type-Length-Value.

This class provides a properties for getting and setting bit fields of the type tag, but most of it is functionality for encoding data per the specification.

As an example, this is what encoding a simple INTEGER looks like:

CERElement cv = new CERElement();
cv.tagNumber = 0x02u; // "2" means this is an INTEGER
cv.integer = 1433; // Now the data is encoded.
transmit(cast(ubyte[]) cv); // transmit() is a made-up function.

And this is what decoding looks like:

ubyte[] data = receive(); // receive() is a made-up function.
CERElement cv2 = new CERElement(data);

long x;
if (cv.tagNumber == 0x02u) // it is an INTEGER
{
    x = cv.integer;
}
// Now x is 1433!
class CanonicalEncodingRulesElement : ASN1Element!CERElement, Byteable {}

Constructors

this
this(ASN1TagClass tagClass, ASN1Construction construction, size_t tagNumber)

Creates an $(MONO END OF CONTENT) by default

this
this(ubyte[] bytes)

Creates a CERElement from the supplied bytes, inferring that the first byte is the type tag. The supplied ubyte[] array is "chomped" by reference, so the original array will grow shorter as CERElements are generated.

this
this(ubyte[] bytes)

Creates a CERElement from the supplied bytes, inferring that the first byte is the type tag. Unlike the construct that accepts a ubyte[] reference, this constructor does not "chomp" the array. This constructor expects the encoded bytes to encode only one $(CERElement). If there are any remaining bytes after decoding, an exception is thrown.

this
this(size_t bytesRead, ubyte[] bytes)

Creates a CERElement from the supplied bytes, inferring that the first byte is the type tag. The supplied ubyte[] array is read, starting from the index specified by bytesRead, and increments bytesRead by the number of bytes read.

Members

Functions

fromBytes
size_t fromBytes(ubyte[] bytes)
opCast
ubyte[] opCast()

This differs from this.value in that this.value only returns the value octets, whereas this.toBytes returns the type tag, length tag / octets, and the value octets, all concatenated.

Properties

basicMultilingualPlaneString
wstring basicMultilingualPlaneString [@property getter]

Decodes a $(MONO wstring) of UTF-16 characters.

basicMultilingualPlaneString
wstring basicMultilingualPlaneString [@property setter]

Encodes a $(MONO wstring) of UTF-16 characters.

bitString
bool[] bitString [@property getter]

Decodes an array of bools representing a string of bits.

bitString
bool[] bitString [@property setter]

Encodes an array of bools representing a string of bits.

boolean
bool boolean [@property getter]

Decodes a bool.

boolean
bool boolean [@property setter]

Encodes a bool

characterString
CharacterString characterString [@property getter]

Decodes a $(MONO CharacterString), which is a constructed data type, defined in the https://www.itu.int, International Telecommunications Union's https://www.itu.int/rec/T-REC-X.680/en, X.680.

characterString
CharacterString characterString [@property setter]

Encodes a $(MONO CharacterString), which is a constructed data type, defined in the https://www.itu.int, International Telecommunications Union's https://www.itu.int/rec/T-REC-X.680/en, X.680.

coordinatedUniversalTime
DateTime coordinatedUniversalTime [@property getter]

Decodes a https://dlang.org/phobos/std_datetime_date.html#.DateTime, DateTime. The value is just the ASCII character representation of the UTC-formatted timestamp.

coordinatedUniversalTime
DateTime coordinatedUniversalTime [@property setter]

Encodes a DateTime. The value is just the ASCII character representation of the UTC-formatted timestamp.

embeddedPresentationDataValue
EmbeddedPDV embeddedPresentationDataValue [@property getter]

Decodes an $(MONO EmbeddedPDV), which is a constructed data type, defined in the https://www.itu.int, International Telecommunications Union's https://www.itu.int/rec/T-REC-X.680/en, X.680.

embeddedPresentationDataValue
EmbeddedPDV embeddedPresentationDataValue [@property setter]

Encodes an $(MONO EmbeddedPDV), which is a constructed data type, defined in the https://www.itu.int, International Telecommunications Union's https://www.itu.int/rec/T-REC-X.680/en, X.680.

endOfContent
void endOfContent [@property getter]

"Decodes" an $(MONO END OF CONTENT), by which I mean: returns nothing, but throws exceptions if the element is not correct.

enumerated
T enumerated [@property getter]

Decodes a signed integer, which represents a selection from an $(MONO ENUMERATION) of choices.

enumerated
T enumerated [@property setter]

Encodes an $(MONO ENUMERATED) type from an integer.

external
deprecated External external [@property getter]

Decodes an $(MONO EXTERNAL).

external
deprecated External external [@property setter]

Encodes an $(MONO EXTERNAL).

generalString
string generalString [@property getter]

Decodes a string containing only ASCII characters. Deprecated, according to page 182 of the Dubuisson book.

generalString
string generalString [@property setter]

Encodes a string containing only ASCII characters. Deprecated, according to page 182 of the Dubuisson book.

generalizedTime
DateTime generalizedTime [@property getter]

Decodes a DateTime. The value is just the ASCII character representation of the https://www.iso.org/iso-8601-date-and-time-format.html, ISO 8601-formatted timestamp.

generalizedTime
DateTime generalizedTime [@property setter]

Encodes a DateTime.

graphicString
string graphicString [@property getter]

Decodes an ASCII string that contains only characters between and including 0x20 and 0x75. Deprecated, according to page 182 of the Dubuisson book.

graphicString
string graphicString [@property setter]

Encodes an ASCII string that may contain only characters between and including 0x20 and 0x75. Deprecated, according to page 182 of the Dubuisson book.

integer
T integer [@property getter]

Decodes a signed integer.

integer
T integer [@property setter]

Encodes a signed integral type

internationalAlphabetNumber5String
string internationalAlphabetNumber5String [@property getter]

Decodes a string that only contains ASCII characters.

internationalAlphabetNumber5String
string internationalAlphabetNumber5String [@property setter]

Encodes a string that may only contain ASCII characters.

nill
void nill [@property getter]

"Decodes" a null, by which I mean: returns nothing, but throws exceptions if the element is not correct.

numericString
string numericString [@property getter]

Decodes a string, where the characters of the string are limited to 0 - 9 and $(MONO SPACE).

numericString
string numericString [@property setter]

Encodes a string, where the characters of the string are limited to 0 - 9 and space.

objectDescriptor
string objectDescriptor [@property getter]

Decodes an ObjectDescriptor, which is a string consisting of only graphical characters. In fact, ObjectDescriptor is actually implicitly just a $(MONO GraphicString)! The formal specification for an ObjectDescriptor is:

objectDescriptor
string objectDescriptor [@property setter]

Encodes an ObjectDescriptor, which is a string consisting of only graphical characters. In fact, ObjectDescriptor is actually implicitly just a $(MONO GraphicString)! The formal specification for an ObjectDescriptor is:

objectIdentifier
OID objectIdentifier [@property getter]

Decodes an $(MONO OBJECT IDENTIFIER). See $(MONO source/types/universal/objectidentifier.d) for information about the ObjectIdentifier class (aliased as OID).

objectIdentifier
OID objectIdentifier [@property setter]

Encodes an $(MONO OBJECT IDENTIFIER). See $(MONO source/types/universal/objectidentifier.d) for information about the ObjectIdentifier class (aliased as $(OID)).

octetString
ubyte[] octetString [@property getter]

Decodes an $(MONO OCTET STRING) into an unsigned byte array.

octetString
ubyte[] octetString [@property setter]

Encodes an $(MONO OCTET STRING) from an unsigned byte (ubyte) array.

printableString
string printableString [@property getter]

Decodes a string that will only contain characters a-z, A-Z, 0-9, space, apostrophe, parentheses, comma, minus, plus, period, forward slash, colon, equals, and question mark.

printableString
string printableString [@property setter]

Encodes a string that may only contain characters a-z, A-Z, 0-9, space, apostrophe, parentheses, comma, minus, plus, period, forward slash, colon, equals, and question mark.

realNumber
T realNumber [@property getter]

Decodes a floating-point type.

realNumber
T realNumber [@property setter]

Encodes a floating-point type, using base-2 binary encoding.

relativeObjectIdentifier
OIDNode[] relativeObjectIdentifier [@property getter]

Decodes a $(MONO RELATIVE OBJECT IDENTIFIER).

relativeObjectIdentifier
OIDNode[] relativeObjectIdentifier [@property setter]

Encodes a $(MONO RELATIVE OBJECT IDENTIFIER).

sequence
CERElement[] sequence [@property getter]

Decodes a sequence of elements

sequence
CERElement[] sequence [@property setter]

Encodes a sequence of elements

set
CERElement[] set [@property getter]

Decodes a set of elements

set
CERElement[] set [@property setter]

Encodes a set of elements

teletexString
ubyte[] teletexString [@property getter]

Literally just returns the value bytes.

teletexString
ubyte[] teletexString [@property setter]

Literally just sets the value bytes.

toBytes
ubyte[] toBytes [@property getter]

This differs from this.value in that this.value only returns the value octets, whereas this.toBytes returns the type tag, length tag / octets, and the value octets, all concatenated.

unicodeTransformationFormat8String
string unicodeTransformationFormat8String [@property getter]

Decodes the value to UTF-8 characters.

unicodeTransformationFormat8String
string unicodeTransformationFormat8String [@property setter]

Encodes a UTF-8 string to bytes.

universalString
dstring universalString [@property getter]

Decodes a $(MONO dstring) of UTF-32 characters.

universalString
dstring universalString [@property setter]

Encodes a $(MONO dstring) of UTF-32 characters.

videotexString
ubyte[] videotexString [@property getter]

Literally just returns the value bytes.

videotexString
ubyte[] videotexString [@property setter]

Literally just sets the value bytes.

visibleString
string visibleString [@property getter]

Decodes a string that only contains characters between and including 0x20 and 0x7E. (Honestly, I don't know how this differs from $(MONO GraphicalString).)

visibleString
string visibleString [@property setter]

Encodes a string that only contains characters between and including 0x20 and 0x7E. (Honestly, I don't know how this differs from $(MONO GraphicalString).)

Meta