SSE4E

Home

GPError
GPSystem
ByteString
ByteBuffer
TLV
TLVList
Card
Atr
Key
Crypto
Application GPApplication GPSecDomain

ASN1
CardFile
IsoSecureChannel
ApplFactory
GPXML
JsScript
CardSim

X509
CRL
KeyStore
CMSSignedData
CMSGenerator
XMLSignature
OCSPQuery
LDAP
SOAP
URLConnection

PKCS11Provider
PKCS11Session
PKCS11Object

OutlineNode

OpenSCDP

ASN1 - Reference Documentation

Implementation of support for ASN.1 data structures using DER encoding rule

Index of Methods

Constants

TypeNameDescription
NumberUNIVERSALEND_OF_CONTENTS ASN.1 class
NumberAPPLICATIONAPPLICATION ASN.1 class
NumberCONTEXTCONTEXT ASN.1 class
NumberPRIVATEPRIVATE ASN.1 class
NumberEND_OF_CONTENTSEND_OF_CONTENTS ASN.1 object
NumberBOOLEANBOOLEAN ASN.1 object
NumberINTEGERINTEGER ASN.1 object
NumberBIT_STRINGBIT_STRING ASN.1 object
NumberOCTET_STRINGOCTET_STRING ASN.1 object
NumberNULLNULL ASN.1 object
NumberOBJECT_IDENTIFIEROBJECT_IDENTIFIER ASN.1 object
NumberOBJECT_DESCRIPTOROBJECT_DESCRIPTOR ASN.1 object
NumberEXTERNAL_TYPEEXTERNAL_TYPE ASN.1 object
NumberREALREAL ASN.1 object
NumberENUMERATEDENUMERATED ASN.1 object
NumberEMBEDDED_PDVEMBEDDED_PDV ASN.1 object
NumberUTF8StringUTF8String ASN.1 object
NumberRELATIVE_OIDRELATIVE_OID ASN.1 object
NumberSEQUENCESEQUENCE ASN.1 object
NumberSETSET ASN.1 object
NumberNumericStringNumericString ASN.1 object
NumberPrintableStringPrintableString ASN.1 object
NumberT61StringT61String ASN.1 object
NumberIA5StringIA5String ASN.1 object
NumberUTCTimeUTCTime ASN.1 object
NumberGeneralizedTimeGeneralizedTime ASN.1 object
NumberGeneralStringGeneralString ASN.1 object
NumberUniversalStringUniversalString ASN.1 object
NumberBMPStringBMPString ASN.1 object

Properties

TypeNameDescription
NumbertagThe combined value of the tag, containing the class, constructed flag and number
NumberlengthLength of the value field
ByteStringvalueThe value field
NumbertagclassThe class of the ASN.1 object. Is one of ASN1.UNIVERSAL, ASN1.APPLICATION, ASN1.CONTEXT or ASN1.PRIVATE
NumbertagnumberThe number element of the tag
BooleanisconstructedTrue, if the object is a constructed ASN.1 object
NumbersizeSize of the concatenation of tag, length and value field
NumberelementsNumber of elements in a constructed object. 0 for primitive objects
StringnameName of object

Constructor

Prototype

ASN1(Number tag)

ASN1(Number tag, ByteString value)

ASN1(Number tag, ASN1 object*)

ASN1(ByteString encoded)

ASN1(String name, Number tag)

ASN1(String name, Number tag, ByteString value)

ASN1(String name, Number tag, ASN1 object*)

ASN1(String name, ByteString encoded)

Description

Create an ASN.1 object, either primitive or constructed. The constructor without a value or with a list of TLV objects will create a constructed object, which can be further completed using the add() method. The constructor with a value field will create a primitive, immutuable object

Arguments

TypeNameDescription
NumbertagTag value, including class, primitive/constructed flag and id
StringnameObject name to be assigned to the object
ASN1objectOne or more ASN1 object(s) to be included in constructed object
ByteStringvalueValue field of object
ByteStringencodedDER encoded ASN.1 object

Exceptions

NameValueDescription
GPErrorGPError.ARGUMENTS_MISSINGToo few arguments in call
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call
GPErrorGPError.INVALID_TYPEType of argument is invalid for call
GPErrorGPError.INVALID_DATAByteString does not contain a valid DER encoded object

Example


t = new ASN1(ASN1.SEQUENCE);
assert(t instanceof ASN1);
assert(t.tag == ASN1.SEQUENCE);
assert(t.length == 0);
assert(t.value.toString(HEX) == "");

assert(t.tagclass == ASN1.UNIVERSAL);
assert(t.tagnumber == 16);
assert(t.isconstructed);
assert(t.size == 2);
assert(t.elements == 0);
t = new ASN1("singleSequence", ASN1.SEQUENCE);
print(t);

t = new ASN1(ASN1.OBJECT_IDENTIFIER, new ByteString("2A1200", HEX));
assert(t instanceof ASN1);
assert(t.tag == ASN1.OBJECT_IDENTIFIER);
assert(t.length == 3);
assert(t.value.toString(HEX) == "2A1200");

assert(t.tagclass == ASN1.UNIVERSAL);
assert(t.tagnumber == 6);
assert(!t.isconstructed);
assert(t.size == 5);
t = new ASN1("objectIdentifier", ASN1.OBJECT_IDENTIFIER, new ByteString("2A1200", HEX));
print(t);

t = new ASN1(new ByteString("06022A11", HEX));
assert(t instanceof ASN1);
assert(t.tag == ASN1.OBJECT_IDENTIFIER);
assert(t.length == 2);
assert(t.value.toString(HEX) == "2A11");

assert(t.tagclass == ASN1.UNIVERSAL);
assert(t.tagnumber == 6);
assert(!t.isconstructed);
assert(t.size == 4);
t = new ASN1("fromByteString", new ByteString("06022A11", HEX));
print(t);

t = new ASN1(ASN1.SEQUENCE, 
		new ASN1(ASN1.OCTET_STRING, new ByteString("Hello World", ASCII)),
		new ASN1(ASN1.GeneralizedTime, new ByteString("20051010120000Z", ASCII)));

assert(t instanceof ASN1);
assert(t.tag == ASN1.SEQUENCE);
assert(t.elements == 2);

assert(t.tagclass == ASN1.UNIVERSAL);
assert(t.tagnumber == 16);
assert(t.isconstructed);
assert(t.size == 32);
t = new ASN1("complexSequence", ASN1.SEQUENCE, 
		new ASN1(ASN1.OCTET_STRING, new ByteString("Hello World", ASCII)),
		new ASN1(ASN1.GeneralizedTime, new ByteString("20051010120000Z", ASCII)));
print(t);


root = new X509("root.cer");
bs = root.getBytes();
print(bs);
t = new ASN1(bs);
assert(t instanceof ASN1);
print(t);

add()

Prototype

ASN1 add(ASN1 object*)

ASN1 add(Number index, ASN1 object*)

Description

Add one or more ASN.1 objects to a constructed object at index or at the end.

Arguments

TypeNameDescription
ASN1objectASN.1 objects to add
NumberindexZero based index

Return

ASN1The object the method is applied to

Exceptions

NameValueDescription
GPErrorGPError.ARGUMENTS_MISSINGToo few arguments in call
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call
GPErrorGPError.INVALID_TYPEType of argument is invalid for call
GPErrorGPError.INVALID_MECHObject must be constructed

Example


t = new ASN1(ASN1.SEQUENCE);
t.add(new ASN1(ASN1.OBJECT_IDENTIFIER, new ByteString("2A1200", HEX)));

t.add(new ASN1(ASN1.OBJECT_IDENTIFIER, new ByteString("2A1200", HEX)),
      new ASN1(ASN1.PrintableString, new ByteString("Hello World", ASCII)));

t.add(0, new ASN1(ASN1.INTEGER, new ByteString("01", HEX)));

get()

Prototype

ASN1 get(Number index)

Description

Get ASN.1 object at zero based index from constructed object.

This method does not provide a copy of the element, but a reference to it. Changes to the element will have an effect in parent objects or other instances obtained with the get() method

Arguments

TypeNameDescription
NumberindexZero based offset

Return

ASN1New ASN1 object representing the element at the requested index

Exceptions

NameValueDescription
GPErrorGPError.ARGUMENTS_MISSINGToo few arguments in call
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call
GPErrorGPError.INVALID_TYPEType of argument is invalid for call
GPErrorGPError.INVALID_INDEXIndex is out of range
GPErrorGPError.INVALID_MECHObject must be constructed

Example


t = new ASN1(ASN1.SEQUENCE);
t.add(new ASN1(ASN1.OBJECT_IDENTIFIER, new ByteString("2A1200", HEX)));
t.add(new ASN1(ASN1.OCTET_STRING, new ByteString("ÄÖÜ", UTF8)));

n = t.get(0);
assert(n instanceof ASN1);
assert(n.tag == ASN1.OBJECT_IDENTIFIER);
assert(n.length == 3);

n = t.get(1);
assert(n instanceof ASN1);
assert(n.tag == ASN1.OCTET_STRING);
assert(n.length == 6);

find()

Prototype

ASN1 find(Number tag)

ASN1 find(Number tag, Number index)

ASN1 find(Number tag, ASN1 cursor)

Description

Find ASN1 object with matching tag.

The method can be called with an object after which the search will start. The constant value null indicates the beginning of the list.

This method does not provide a copy of the element, but a reference to it. Changes to the element will have an effect in parent objects or other instances obtained with the get() method

Arguments

TypeNameDescription
NumbertagThe tag value to search for
NumberindexZero based offset of the object at which the search is started.
ASN1cursorThe object after which the search resumes or null for a new search

Return

ASN1New ASN1 object representing the found element or null if no match found

Exceptions

NameValueDescription
GPErrorGPError.ARGUMENTS_MISSINGToo few arguments in call
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call
GPErrorGPError.INVALID_TYPEType of argument is invalid for call
GPErrorGPError.INVALID_INDEXIndex is out of range
GPErrorGPError.INVALID_MECHObject must be constructed

Example


t = new ASN1(ASN1.SEQUENCE);
t.add(new ASN1(ASN1.OBJECT_IDENTIFIER, new ByteString("2A1200", HEX)));
t.add(new ASN1(ASN1.OCTET_STRING, new ByteString("ÄÖÜ", UTF8)));
t.add(new ASN1(ASN1.INTEGER, new ByteString("00", HEX)));
t.add(new ASN1(ASN1.INTEGER, new ByteString("0000", HEX)));

n = t.find(ASN1.OBJECT_IDENTIFIER);
assert(n instanceof ASN1);
assert(n.tag == ASN1.OBJECT_IDENTIFIER);

n = t.find(ASN1.INTEGER);
assert(n instanceof ASN1);
assert(n.tag == ASN1.INTEGER);
assert(n.length == 1);


n = t.find(ASN1.INTEGER, n);
assert(n instanceof ASN1);
assert(n.tag == ASN1.INTEGER);
assert(n.length == 2);

n = t.find(ASN1.INTEGER, n);
assert(n == null);

n = t.find(ASN1.OBJECT_IDENTIFIER, n);
assert(n instanceof ASN1);
assert(n.tag == ASN1.OBJECT_IDENTIFIER);


n = t.find(ASN1.INTEGER, 1);
assert(n instanceof ASN1);
assert(n.tag == ASN1.INTEGER);
assert(n.length == 1);

n = t.find(ASN1.INTEGER, 3);
assert(n instanceof ASN1);
assert(n.tag == ASN1.INTEGER);
assert(n.length == 2);

n = t.find(ASN1.OBJECT_IDENTIFIER, 0);
assert(n instanceof ASN1);
assert(n.tag == ASN1.OBJECT_IDENTIFIER);


remove()

Prototype

void remove(Number index)

Description

Remove ASN.1 object at zero based index from constructed object.

Arguments

TypeNameDescription
NumberindexZero based offset

Return

Exceptions

NameValueDescription
GPErrorGPError.ARGUMENTS_MISSINGToo few arguments in call
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call
GPErrorGPError.INVALID_TYPEType of argument is invalid for call
GPErrorGPError.INVALID_INDEXIndex is out of range
GPErrorGPError.INVALID_MECHObject must be constructed

Example


t = new ASN1(ASN1.SEQUENCE);
t.add(new ASN1(ASN1.OBJECT_IDENTIFIER, new ByteString("2A1200", HEX)));
t.add(new ASN1(ASN1.OCTET_STRING, new ByteString("ÄÖÜ", UTF8)));

t.remove(0);

n = t.get(0);
assert(n instanceof ASN1);
assert(n.tag == ASN1.OCTET_STRING);
assert(n.length == 6);

getBytes()

Prototype

ByteString getBytes()

Description

Return the DER encoded ASN.1 object

Return

ByteStringThe DER encoded object

Exceptions

NameValueDescription
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call

Example


t = new ASN1(ASN1.SEQUENCE);
t.add(new ASN1(ASN1.OBJECT_IDENTIFIER, new ByteString("2A1200", HEX)));
assert(t.getBytes().toString(HEX) == "300506032A1200");

getDate()

Prototype

Date getDate()

Description

Return the value field of a primitive ASN.1 object as a date. This usually works for for GeneralizedTime objects which store date and time in ISO8601 format.

Return

ByteStringThe DER encoded object

Exceptions

NameValueDescription
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call
GPErrorGPError.INVALID_MECHObject must be primitive
GPErrorGPError.INVALID_DATAValue field does not contain a valid date and time

Example


// Local time
t = new ASN1(ASN1.GeneralizedTime, new ByteString("20050929113422", ASCII));
d = t.getDate();
print(d);
assert(d.toString().substr(0,24) == "Thu Sep 29 2005 11:34:22");
	    
// UTC time
t = new ASN1(ASN1.GeneralizedTime, new ByteString("20050929113422Z", ASCII));
d = t.getDate();
assert(d.getTime() == 1127993662000);

// CEST time
t = new ASN1(ASN1.GeneralizedTime, new ByteString("20050929133422+0200", ASCII));
d = t.getDate();
assert(d.getTime() == 1127993662000);

// Local time with millisecond
t = new ASN1(ASN1.GeneralizedTime, new ByteString("20050929113422.1", ASCII));
d = t.getDate();
assert(d.toString().substr(0,24) == "Thu Sep 29 2005 11:34:22");

// UTC time with millisecond
t = new ASN1(ASN1.GeneralizedTime, new ByteString("20050929113422.1Z", ASCII));
d = t.getDate();
assert(d.getTime() == 1127993662001);
	    
// CEST time with millisecond
t = new ASN1(ASN1.GeneralizedTime, new ByteString("20050929133422.1+0200", ASCII));
d = t.getDate();
assert(d.getTime() == 1127993662001);

setName()

Prototype

setName(String name)

Description

Assign a name to the ASN.1 object.

Return

Exceptions

NameValueDescription
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call

Example


t = new ASN1(ASN1.SEQUENCE);
t.setName("testObject");
print(t.toString());

ASN1.defineObjectIdentifier()

Prototype

defineObjectIdentifier(String name, String definition)

Description

Add a definition for a symbolic object identifier to the internal registry.

The definition may be recursive and can use the dotted or spaced format.

Return

Exceptions

NameValueDescription
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call

Example


ASN1.defineObjectIdentifier("openscdp-test", "1.3.6.1.4.1.24991.0");
ASN1.defineObjectIdentifier("openscdp-test-sub1", "openscdp-test.4");
ASN1.defineObjectIdentifier("openscdp-test-sub2", "openscdp-test branch(5)");

var b = new ByteString("openscdp-test-sub2", OID);
print(b);
assert(b.toString(OID) == "1.3.6.1.4.1.24991.0.5");

toString()

Prototype

String toString()

Description

Dump the contents of the ASN.1 object

Return

StringDump of ASN.1 object

Exceptions

NameValueDescription
GPErrorGPError.ARGUMENTS_MISSINGToo few arguments in call
GPErrorGPError.INVALID_ARGUMENTSToo many arguments in call
GPErrorGPError.INVALID_TYPEArgument must be of type Number and either Card.RESET_COLD or Card.RESET_WARM

Example


t = new ASN1(ASN1.SEQUENCE);
t.add(new ASN1(ASN1.OBJECT_IDENTIFIER, new ByteString("2A1200", HEX)));
print(t.toString());