Encoding/decoding support is provided for BER and DER encoded data packets. The framework provides the required hooks and flexibility for other coders (PER, XER, ...) to be plugged in easily, and experimental (but not officially released and maintained) versions of PER and XER coders are provided.
asn1Definitions
^
'
rsadsi OBJECT IDENTIFIER ::=
{iso(1) member-body(2) us(840) rsadsi(113549)}
digestAlgorithm OBJECT IDENTIFIER ::= {rsadsi 2}
id-hmacWithSHA224 OBJECT IDENTIFIER ::= {digestAlgorithm 8}
id-hmacWithSHA256 OBJECT IDENTIFIER ::= {digestAlgorithm 9}
id-hmacWithSHA384 OBJECT IDENTIFIER ::= {digestAlgorithm 10}
id-hmacWithSHA512 OBJECT IDENTIFIER ::= {digestAlgorithm 11}
'
(the above is a real world example, copy-pasted from RFC4231).
Then, the classes initialize
-method could be:
assuming that Module is a local class variable.
initialize
Module isNil ifTrue:[
Module := OSI::ASN1Parser parseModuleDefinition:self asn1Definitions.
].
^ Module
Then, within the class, defined entities are accessible like:
Module at:'hmacWithSHA512'
If the module contains data structures, as in the X509 definition:
those can be instantiated as:
...
TBSCertificate ::= SEQUENCE {
version [ 0 ] Version DEFAULT v1,
serialNumber CertificateSerialNumber,
signature AlgorithmIdentifier,
issuer Name,
validity Validity,
subject Name,
subjectPublicKeyInfo SubjectPublicKeyInfo,
issuerUniqueID [ 1 ] IMPLICIT UniqueIdentifier OPTIONAL,
subjectUniqueID [ 2 ] IMPLICIT UniqueIdentifier OPTIONAL,
extensions [ 3 ] Extensions OPTIONAL
}
...
i.e. the returned objects behave like classes which can be instantiated,
and those instances can be accessed via getter- and setter methods.
cert := (Module at:'TBSCertificate') new.
cert issuer:'fooBar'.
cert subjectPublicKeyInfo:((Module at:'SubjectPublicKeyInfo') new.
...
By putting those definitions into a shared pool or class variables,
the code can further be simplified to:
and eventually encoded using the BER-coder:
cert := TBSCertificate new.
cert issuer:'fooBar'.
cert subjectPublicKeyInfo:SubjectPublicKeyInfo new.
...
or decode a BER-encoded stream, using the ASN.1 type:
bytes := OSI::BERCoder encode:cert.
cert := OSI::BERCoder decode:bztes withType:TBSCertificate.
Copyright © 1999 eXept Software AG
<info@exept.de>