afnix-itu






itu ‐ standard telecom module

The Standard Telecommodule is an original implementation of
various standards managed by the International
Telecommunictaion Union (ITU). At the heart of this module
is the Abstract Syntax Notation(ASN.1) which is widely used
to model data records and store certificates.

     notationAbstractsyntax
The abstract syntax notation (ASN.1) is standardized by the
ITU to express a normal form of communication. The ASN.1 is
in fact the de‐facto standard for representing X509
certificate and is the only justification to provide the
support for such complex representation.

     Encodingrules
This implementation supports all encoding forms as defined
by the ITU, namely the Basic Encoding Rule(BER), the
Canonical Encoding Rule(CER) and the Distinguished Encoding
Rule(DER). The DER form is by far the most widely used.

     ASNobjects
All objects as defined by the ITU are supported in this
implementation, including the ability to create custom OID.

Object        Description
AsnBoolean    Boolean primitive
AsnInteger    Integer primitive
AsnBits       Bit string
AsnOctets     Octet string
AsnBmp        Bmp string
AsnIas        IA5 string
AsnNums       Numeric string
AsnPrts       Printable string
AsnUtfs       Unicode string
AsnUnvs       Universal string
AsneNull      Null primitive
AsneEoc       End‐of‐Content primitive
AsnGtm        Generalized time primitive
AsnUtc        Utc time primitive
AsnSequence   Asn node Sequence
AsnSet        Asn node Set
AsnOid        Asn object identifier Set
AsnRoid       Asn object relative identifier Set



     objectsUsingASN.1
Using ASN.1 object is particularly straightfoward. One can
directly creates a particular object by invoking the
appropriate constructor.

# create an asn boolean node
trans  abn  (afnix:itu:AsnBoolean true)









                             ‐2‐


# check the node type
assert true (afnix:itu:asn‐node‐p abn)
assert true (afnix:itu:asn‐boolean‐p  abn)

Writing the object can be done into a buffer or an output
stream. Note that the default encoding is the DER encoding.

# write into a buffer
trans buf (Buffer)
abn:write buf
# check the buffer content
assert "0101FF" (buf:format)

Building an ASN.1 representation can be achieved by parsing
a buffer or an input stream. This is done by filling a
buffer and requesting a buffer node mapping.

# parse the buffer and check
const anb (afnix:itu:AsnBuffer buf)
# map the node to a boolean
trans abn (anb:node‐map)
# check the node
assert true (afnix:itu:asn‐node‐p abn)
assert true (afnix:itu:asn‐boolean‐p  abn)

With more complex structure, it is likely that a sequence
object will be returned by the buffer node mapper. Once the
sequence object is created, each node can be accessed by
index like any other container.



     AsnNode
The AsnNodeclass is the base class used to represent the asn
tree. The structure of the node is defined in ITU‐T X.690
recommendation. This implementation supports 64 bits tag
number with natural machine length encoding. The Canonical
Encoding Rule (CER) and Distinguished Encoding Rule (DER)
are defined by the class. Since ASN.1 provides several
encoding schemes, the class is designed to be as generic as
possible but does not provides the mechanism for changing
from one representation to another although it is perfectly
valid to read a DER representation and write it in the CER
form.

     Predicate

     asn‐node‐p

     Inheritance

     Object











                             ‐3‐


     Constants

     BER
     The BERconstant defines the Basic Encoding Rulenode
     encoding.

     CER
     The CERconstant defines the Canonical Encoding Rulenode
     encoding.

     DER
     The DERconstant defines the Distinguished Encoding
     Rulenode encoding.

     UNIVERSAL
     The UNIVERSALconstant defines the node universal class.

     APPLICATION
     The APPLICATIONconstant defines the node application
     class.

     CONTEXT‐SPECIFIC
     The CONTEXT‐SPECIFICconstant defines the node context
     specific class.

     PRIVATE
     The PRIVATEconstant defines the node private class.

     Methods

     nonereset‐>
     The resetmethod reset a node to its default value.

     Integerlength‐>
     The lengthmethod returns the total node length in
     bytes.

     UNIVERSAL|APPLICATION|CONTEXT‐SPECIFIC|PRIVATEget‐
     class‐>
     The get‐classmethod returns the node class.

     Booleanprimitive‐p‐>
     The primitive‐preturns true if the node is a primitive.

     Booleanconstructed‐p‐>
     The constructed‐preturns true if the node is a
     constructed node.

     Integerget‐tag‐number‐>
     The get‐tag‐number‐preturns node tag number.

     Integerget‐content‐length‐>
     The get‐content‐length‐preturns node content length.










                             ‐4‐


     nonewrite‐>
     The writemethod write the asn node contents as well as
     the child nodes to an output stream argument or a
     buffer. Without argument, the node is written to the
     interpreter output stream. With one argument, the node
     is written to the specified stream or buffer.

     AsnOctets
The AsnOctetsclass is the asn object class that encodes the
octet string type. This type can be encoded either as a
primitive or as constructed at sender’s option. In CER form,
the primitive form is used when the content length is less
than 1000 octets, and the constructed form is used
otherwise. The DER form will always use the primitive form.

     Predicate

     asn‐octets‐p

     Inheritance

     AsnNode

     Constructors

     AsnOctets(none)
     The AsnOctetsconstructor creates a default asn octets
     string node.

     AsnOctets(String|Buffer)
     The AsnOctetsconstructor creates an asn octets string
     node by string of buffer object.

     Methods

     Bufferto‐buffer‐>
     The to‐buffermethod returns a Bufferobject as an octet
     string representation.

     AsnBuffer
The AsnBufferclass is the asn object class that provides a
generic implementation of an asn structure. The class acts
as a simple encoder and decoder with special facilities to
retarget the buffer content.

     Predicate

     asn‐buffer‐p

     Inheritance

     AsnNode











                             ‐5‐


     Constructors

     AsnBuffer(none)
     The AsnBufferconstructor creates a default asn buffer
     node.

     AsnBuffer(InputStream|Buffer|Bitset)
     The AsnBufferconstructor creates an asn buffer node
     from an input stream, a buffer or a bitset.

     Methods

     nonereset‐>
     The resetmethod reset the buffer.

     Booleanparse‐>
     The parsemethod parse a node represented by an input
     stream, a buffer or a bitset.

     AsnNodenode‐map‐>
     The node‐mapmethod returns a node mapping of this
     buffer.

     Bufferget‐content‐buffer‐>
     The get‐content‐buffermethod returns the asn buffer
     content as a buffer object.

     AsnNull
The AsnNullclass is the asn object class that encodes the
null primitive. This primitive has a unique encoding. The
length is always 0 and there is no content octet.

     Predicate

     asn‐null‐p

     Inheritance

     AsnNode

     Constructors

     AsnNull(none)
     The AsnNullconstructor creates a default asn null node.

     AsnEoc
The AsnEocclass is the asn object class that encodes the eoc
or end‐of‐content primitive. This primitive is almost never
used but its encoding is used with the indefinite length
encoding.

     Predicate

     asn‐eoc‐p









                             ‐6‐


     Inheritance

     AsnNode

     Constructors

     AsnEoc(none)
     The AsnEocconstructor creates a default asn eoc node.

     AsnBoolean
The AsnBooleanclass is the asn object class that encodes the
boolean primitive. This primitive has a unique encoding with
the CER or DER rule, but the BER rule can support any byte
value for the true value.

     Predicate

     asn‐boolean‐p

     Inheritance

     AsnNode

     Constructors

     AsnBoolean(none)
     The AsnBooleanconstructor creates a default asn boolean
     node.

     AsnBoolean(Boolean)
     The AsnBooleanconstructor creates an asn boolean node
     from a boolean object.

     Methods

     Booleanto‐boolean‐>
     The to‐booleanmethod returns a Booleanobject as the asn
     node representation.

     AsnInteger
The AsnIntegerclass is the asn object class that encodes the
integer primitive. This primitive has a unique encoding with
the CER or DER rule. All encoding use a signed 2‐complement
form.

     Predicate

     asn‐integer‐p

     Inheritance

     AsnNode











                             ‐7‐


     Constructors

     AsnInteger(none)
     The AsnIntegerconstructor creates a default asn integer
     node.

     AsnInteger(Integer|Relatif)
     The AsnIntegerconstructor creates an asn integer node
     from an integer or relatif object.

     Methods

     Relatifto‐relatif‐>
     The to‐relatifmethod returns a Relatifobject as the asn
     node representation.

     AsnBits
The AsnBitsclass is the asn object class that encodes the
bit string type. This type can be encoded either as a
primitive or as constructed at sender’s option. In CER form,
the primitive form is used when the content length is less
than 1000 octets, and the constructed form is used
otherwise. The DER form will always use the primitive form.

     Predicate

     asn‐bits‐p

     Inheritance

     AsnNode

     Constructors

     AsnBits(none)
     The AsnBitsconstructor creates a default asn bits node.

     AsnBits(String|Bitset)
     The AsnBitsconstructor creates an asn bits node from a
     string or a bitset.

     Methods

     Bitsetto‐bits‐>
     The to‐bitsmethod returns a Bitsetobject as a bit
     string representation.

     AsnBmps
The AsnBmpsclass is the asn object class that encodes the
asn bmp string primitive also known as the UCS‐2 type
string. This string is implemented, after conversion as an
octet string. Consequently the rules for encoding in CER and
DER modes are applied.










                             ‐8‐


     Predicate

     asn‐bmps‐p

     Inheritance

     AsnOctets

     Constructors

     AsnBmps(none)
     The AsnBmpsconstructor creates a default asn string
     (BMP) node.

     AsnBmps(String)
     The AsnBmpsconstructor creates an asn string (BMP) node
     from a string.

     Methods

     Stringto‐string‐>
     The to‐stringmethod returns a Stringobject as a node
     representation.

     AsnIas
The AsnIasclass is the asn object class that encodes the IA5
string primitive. This string is implemented, after
conversion as an octet string. Consequently the rules for
encoding in CER and DER modes are applied.

     Predicate

     asn‐ias‐p

     Inheritance

     AsnOctets

     Constructors

     AsnIas(none)
     The AsnIasconstructor creates a default asn string
     (IA5) node.

     AsnIas(String)
     The AsnIasconstructor creates an asn string (IA5) node
     from a string.

     Methods

     Stringto‐string‐>
     The to‐stringmethod returns a Stringobject as a node
     representation.










                             ‐9‐


     AsnNums
The AsnNumsclass is the asn object class that encodes the
asn numeric string primitive. This string is implemented,
after conversion as an octet string. Consequently the rules
for encoding in CER and DER modes are applied.

     Predicate

     asn‐nums‐p

     Inheritance

     AsnOctets

     Constructors

     AsnNums(none)
     The AsnNumsconstructor creates a default asn string
     (NUMERIC) node.

     AsnNums(String)
     The AsnNumsconstructor creates an asn string (NUMERIC)
     node from a string.

     Methods

     Stringto‐string‐>
     The to‐stringmethod returns a Stringobject as a node
     representation.

     AsnPrts
The AsnPrtsclass is the asn object class that encodes the
asn printable string primitive. This string is implemented,
after conversion as an octet string. Consequently the rules
for encoding in CER and DER modes are applied.

     Predicate

     asn‐prts‐p

     Inheritance

     AsnOctets

     Constructors

     AsnPrts(none)
     The AsnPrtsconstructor creates a default asn string
     (PRINTABLE) node.

     AsnPrts(String)
     The AsnPrtsconstructor creates an asn string
     (PRINTABLE) node from a string.










                            ‐10‐


     Methods

     Stringto‐string‐>
     The to‐stringmethod returns a Stringobject as a node
     representation.

     AsnUtfs
The AsnUtfsclass is the asn object class that encodes the
asn utf string primitive. This string is implemented as an
octet string. Consequently the rules for encoding in CER and
DER modes are applied.

     Predicate

     asn‐utfs‐p

     Inheritance

     AsnOctets

     Constructors

     AsnUtfs(none)
     The AsnUtfsconstructor creates a default asn string
     (UNICODE) node.

     AsnUtfs(String)
     The AsnUtfsconstructor creates an asn string (UNICODE)
     node from a string.

     Methods

     Stringto‐string‐>
     The to‐stringmethod returns a Stringobject as a node
     representation.

     AsnUnvs
The AsnUnvsclass is the asn object class that encodes the
universal string primitive also known as the UCS‐4 type
string. This string is implemented, after conversion as an
octet string. Consequently the rules for encoding in CER and
DER modes are applied.

     Predicate

     asn‐unvs‐p

     Inheritance

     AsnOctets

     Constructors

     AsnUnvs(none)









                            ‐11‐


     The AsnUnvsconstructor creates a default asn string
     (UNIVERSAL) node.

     AsnUnvs(String)
     The AsnUnvsconstructor creates an asn string
     (UNIVERSAL) node from a string.

     Methods

     Stringto‐string‐>
     The to‐stringmethod returns a Stringobject as a node
     representation.

     AsnGtm
The AsnGtmclass is the asn object class that encodes the
generalized time primitive. This primitive is encoded from
its equivalent string representation. Although, the
constructed mode is authorized, it does not make that much
sense to use it.

     Predicate

     asn‐gtm‐p

     Inheritance

     AsnNode

     Constructors

     AsnGtm(none)
     The AsnGtmconstructor creates a default asn gtm node.

     AsnGtm(String)
     The AsnGtmconstructor creates an asn gtm node from a
     string.

     Methods

     Booleanutc‐p‐>
     The utc‐ppredicate returns true if the time is
     expressed in UTC mode.

     Integerto‐time‐>
     The to‐timemethod returns a time representation of this
     asn node.

     Stringto‐string‐>
     The to‐stringmethod returns a string representation of
     this asn node.

     AsnUtc
The AsnUtcclass is the asn object class that encodes the utc
time primitive. This primitive is encoding from its









                            ‐12‐


equivalent string representation. Although, the constructed
mode is authorized, it does not make that much sense to use
it.

     Predicate

     asn‐utc‐p

     Inheritance

     AsnNode

     Constructors

     AsnUtc(none)
     The AsnUtcconstructor creates a default asn utc node.

     AsnUtc(String)
     The AsnUtcconstructor creates an asn utc node from a
     string.

     Methods

     Booleanutc‐p‐>
     The utc‐ppredicate returns true if the time is
     expressed in UTC mode.

     Integerto‐time‐>
     The to‐timemethod returns a time representation of this
     asn node.

     Stringto‐string‐>
     The to‐stringmethod returns a string representation of
     this asn node.

     AsnSequence
The AsnSequenceclass is the asn object class that encodes
the sequence constructed type. The order of elements is
preserved in the encoding of the sequence.

     Predicate

     asn‐sequence‐p

     Inheritance

     AsnNode

     Constructors

     AsnSequence(none)
     The AsnSequenceconstructor creates an empty asn
     sequence node.










                            ‐13‐


     Methods

     Integernode‐length‐>
     The node‐lengthmethod returns the number of nodes in
     the sequence.

     nonenode‐add‐>
     The node‐addmethod adds a node to the sequence.

     AsnNodenode‐get‐>
     The node‐getmethod returns an asn node by index.

     AsnSet
The AsnSetclass is the asn object class that encodes the set
constructed type. The order of elements is not important in
a set.

     Predicate

     asn‐set‐p

     Inheritance

     AsnNode

     Constructors

     AsnSet(none)
     The AsnSetconstructor creates an empty asn set node.

     Methods

     Integernode‐length‐>
     The node‐lengthmethod returns the number of nodes in
     the set.

     nonenode‐add‐>
     The node‐addmethod adds a node to the set.

     AsnNodenode‐get‐>
     The node‐getmethod returns an asn node by index.

     Oid
The Oidclass is a base class that represents the X500 object
identifier which is used in the ASN.1 encoding and in the
X509 standard. An oid is simply represented by a vector of
subidentifiers.

     Predicate

     oid‐p

     Inheritance










                            ‐14‐


     Object

     Constructors

     Oid(Integer|...)
     The Oidconstructor creates an oid from a sequence of
     integers.

     Methods

     nonereset‐>
     The resetmethod resets the oid object to its null empty
     state.

     Integerlength‐>
     The lengthmethod returns the length of the oid.

     noneadd‐>
     The addmethod adds one or more sub‐indentifiers to the
     oid.

     Integerget‐>
     The getmethod returns an oid sub‐identifier by index.

     Stringformat‐>
     The formatmethod returns a string representation of the
     oid.

     AsnOid
The AsnOidclass is the asn object class that encodes the
object identifier primitive. This primitive has a unique
encoding with the CER or DER rule. The oid is built as a
vector of subidentifiers (sid). Each sid is represented as
an octa (64 bits) value.

     Predicate

     asn‐oid‐p

     Inheritance

     AsnNode

     Constructors

     AsnOid(Integer|...)
     The AsnOidconstructor creates an asn oid from a
     sequence of sid.

     Methods

     Integersid‐length‐>
     The lengthmethod returns the length of the oid.










                            ‐15‐


     nonesid‐add‐>
     The sid‐addmethod adds a sid the oid object.

     Integersid‐get‐>
     The sid‐getmethod returns a sid by oid index.

     Oidget‐oid‐>
     The get‐oidmethod returns an oid object as the asn oid
     representation.

     AsnRoid
The AsnRoidclass is the asn object class that encodes the
object relative identifier primitive. This primitive has a
unique encoding with the CER or DER rule. The oid is built
as a vector of subidentifiers (sid). Each sid is represented
as an octa (64 bits) value. The difference with the oid
object is to be found in the encoding of the first 2 sid.

     Predicate

     asn‐roid‐p

     Inheritance

     AsnNode

     Constructors

     AsnRoid(Integer|...)
     The AsnRoidconstructor creates an asn roid from a
     sequence of sid.

     Methods

     Integersid‐length‐>
     The lengthmethod returns the length of the oid.

     nonesid‐add‐>
     The sid‐addmethod adds a sid the oid object.

     Integersid‐get‐>
     The sid‐getmethod returns a sid by oid index.

     Oidget‐oid‐>
     The get‐oidmethod returns an oid object as the asn oid
     representation.

     Functions

     noneasn‐random‐bits‐>
     The exitfunction creates a random asn bit string. The
     argument is the number of bits in the random string.

     noneasn‐random‐octets‐>









                            ‐16‐


     The exitfunction creates a random asn octet string. The
     integer argument is the number of octets in the string.