|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
This interface defines a generic encoder for the marshalling of ASN.1 values.
It provides encoding methods for all the ASN.1 primitive values. The encoding of a constructed value (SET, SEQUENCE or explicit tagged value) must begin with a call to the encodeSet, encodeSequence or encodeExplicit method that returns an identifier; then, the elements contained in the constructed value must be encoded with their corresponding encode methods. Finally, the endOf method must be invoked with the identifier to terminate the encoding of the constructed value. All the encoding methods may throw anEncodingException if
invalid values are being encoded or if some internal state is not correct. An
IOException may also be thrown if an I/O error occured during
writing into an output stream specified by some implementation (as it is the
case for BER encoders but not for DER encoders).
| Method Summary | |
void |
encodeAny(byte[] encoded)
Encodes an ASN.1 ANY value. |
void |
encodeBitString(BitString bits)
Encodes an ASN.1 BIT STRING value. |
void |
encodeBitString(byte[] bits)
Encodes the specified bytes as an ASN.1 BIT STRING value. |
void |
encodeBMPString(String s)
Encodes an ASN.1 BMPString value. |
void |
encodeBoolean(boolean b)
Encodes an ASN.1 BOOLEAN value. |
void |
encodeEnumerated(BigInteger e)
Encodes an ASN.1 ENUMERATED value. |
void |
encodeEnumerated(int e)
Encodes an ASN.1 ENUMERATED value. |
void |
encodeEnumerated(long e)
Encodes an ASN.1 ENUMERATED value. |
int |
encodeExplicit(int tag)
Indicates that the next ASN.1 value must be encoded with an explicit tag equals to the specified tag value. |
void |
encodeGeneralizedTime(Calendar date)
Encodes the specified date as an ASN.1 GeneralizedTime. |
void |
encodeGeneralString(String s)
Encodes an ASN.1 GeneralString value. |
void |
encodeGraphicString(String s)
Encodes an ASN.1 GraphicString value. |
void |
encodeIA5String(String s)
Encodes an ASN.1 IA5String value. |
void |
encodeImplicit(int tag)
Signals that the next ASN.1 value must be encoded with the specified implicit tag. |
void |
encodeInteger(BigInteger i)
Encodes an ASN.1 INTEGER value. |
void |
encodeInteger(int i)
Encodes an ASN.1 INTEGER value. |
void |
encodeInteger(long l)
Encodes an ASN.1 INTEGER value. |
void |
encodeNull()
Encodes an ASN.1 NULL value. |
void |
encodeNumericString(String s)
Encodes an ASN.1 NumericString value. |
void |
encodeObjectIdentifier(ObjectIdentifier oid)
Encodes an ASN.1 OBJECT IDENTIFIER value. |
void |
encodeOctetString(byte[] b)
Encodes the b.length bytes from the specified byte array as
an ASN.1 OCTET STRING.
|
void |
encodeOctetString(byte[] b,
int off,
int len)
Encodes an ASN.1 OCTET STRING consisting of len bytes of the
specified byte array starting at offset off.
|
void |
encodePrintableString(String s)
Encodes an ASN.1 PrintableString value. |
void |
encodeReal(double value)
Encodes an ASN.1 REAL value. |
int |
encodeSequence()
Starts the encoding of an ASN.1 SEQUENCE. |
int |
encodeSequenceOf()
Starts the encoding of an ASN.1 SEQUENCE OF. |
int |
encodeSet()
Starts the encoding of an ASN.1 SET. |
int |
encodeSetOf()
Starts the encoding of an ASN.1 SET OF. |
void |
encodeTeletexString(String s)
Encodes an ASN.1 TeletexString value. |
void |
encodeUniversalString(String s)
Encodes an ASN.1 UniversalString value. |
void |
encodeUTCTime(Calendar date)
Encodes the specified date as an ASN.1 UTCTime. |
void |
encodeUTF8String(String s)
Encodes an ASN.1 UTF8String value. |
void |
encodeVideotexString(String s)
Encodes an ASN.1 VideotexString value. |
void |
encodeVisibleString(String s)
Encodes an ASN.1 VisibleString value. |
void |
endOf(int id)
Terminates the encoding of the constructed value identified by id. |
boolean |
isDefaultEncoded()
Indicates wether this encoder encodes DEFAULT values. |
void |
reset()
Resets the state of this encoder. |
| Method Detail |
public void encodeAny(byte[] encoded)
throws IOException
NullPointerException is thrown if the array is
null.
encoded - the array of bytes
IOException
public void encodeBoolean(boolean b)
throws IOException
b - the boolean value to be encoded.
IOException
public void encodeInteger(BigInteger i)
throws IOException
encodeInteger methods with int or
long as parameter (if the value to encode may be represented
by a int or a long).
If i is null, a NullPointerException
is thrown.
i - the arbitrary-precision integer to be encoded.
IOExceptionencodeInteger(int),
encodeInteger(long)
public void encodeInteger(long l)
throws IOException
l - the number to be encoded.
IOException
public void encodeInteger(int i)
throws IOException
i - the number to be encoded.
IOException
public void encodeBitString(BitString bits)
throws IOException
bits is null, a NullPointerException
is thrown.
bits - a BitString representing the sequence of bits to
be encoded.
IOException
public void encodeBitString(byte[] bits)
throws IOException
bits is null, a NullPointerException
is thrown.
bits - an array of bytes representing the sequence of bits to be
encoded.
IOException
public void encodeOctetString(byte[] b,
int off,
int len)
throws IOException
len bytes of the
specified byte array starting at offset off.
If b is null, a NullPointerException
is thrown.
If off is negative, or len is negative, or
off+len is greater than the length of the array
b, then an IndexOutOfBoundsException is
thrown.
b - the byte array containing the bytes to be encoded.off - the start offset in the byte array.len - the number of bytes to encode.
IOException
public void encodeOctetString(byte[] b)
throws IOException
b.length bytes from the specified byte array as
an ASN.1 OCTET STRING.
If b is null, a NullPointerException
is thrown.
b - the byte array to be encoded.
IOExceptionencodeOctetString(byte[],int,int)
public void encodeNull()
throws IOException
IOException
public void encodeObjectIdentifier(ObjectIdentifier oid)
throws IOException
oid is null, a NullPointerException
is thrown.
oid - the ObjectIdentifier to encode.
IOException
public void encodeReal(double value)
throws IOException
value - the number to be encoded.
IOException
public void encodeEnumerated(BigInteger e)
throws IOException
int or a
long. Otherwise the encodeEnumerated methods
with int or long parameter should be used.
e - the ENUMERATED value represented as a abitrary-precision
integer.
IOExceptionencodeEnumerated(int),
encodeEnumerated(long)
public void encodeEnumerated(int e)
throws IOException
e - the ENUMERATED value to encode.
IOException
public void encodeEnumerated(long e)
throws IOException
e - the ENUMERATED value to encode.
IOException
public void encodeUTF8String(String s)
throws IOException
s - the string value to encode.
IOException
public void encodeNumericString(String s)
throws IOException
s - the string value to encode.
IOException
public void encodePrintableString(String s)
throws IOException
Name Graphic --------------- ----------- Capital letters A, B, ... Z Small letters a, b, ... z Digits 0, 1, ... 9 Space (space) Apostrophe ' Left Parenthesis ( Right Parenthesis ) Plus sign + Comma , Hyphen - Full stop . Solidus / Colon : Equal sign = Question mark ?
s - the string value to encode.
IOException
public void encodeTeletexString(String s)
throws IOException
s - the string value to encode.
IOException
public void encodeVideotexString(String s)
throws IOException
s - the string value to encode.
IOException
public void encodeIA5String(String s)
throws IOException
s - the string value to encode.
IOException
public void encodeUTCTime(Calendar date)
throws IOException
date - the date to encode.
IOException
public void encodeGeneralizedTime(Calendar date)
throws IOException
date - the date to encode.
IOException
public void encodeGraphicString(String s)
throws IOException
s - the string value to encode.
IOException
public void encodeVisibleString(String s)
throws IOException
s - the string value to encode.
IOException
public void encodeGeneralString(String s)
throws IOException
s - the string value to encode.
IOException
public void encodeUniversalString(String s)
throws IOException
UniversalString comprises the characters defined in the ISO10646-1 standard or in
the
Unicode Standard. It is a set of fixed-length characters: each
character of the UniversalString type encoded on 4 bytes has
only one possible interpretation.
s - the string value to encode.
IOException
public void encodeBMPString(String s)
throws IOException
s - the string value to encode.
IOException
public void encodeImplicit(int tag)
throws IOException
enc.encodeImplicit(Tags.makeTag(Tags.CONTEXT, 5)); ... enc.encodeImplicit(Tags.makeTag(Tags.CONTEXT, 7)); enc.encodeInteger(124);are equivalent to
enc.encodeImplicit(Tags.makeTag(Tags.CONTEXT, 5)); enc.encodeInteger(124);This tag reduction mechanism is useful for encoding ASN.1 type like
Type1 ::= [APPLICATION 2] IMPLICIT INTEGER Type2 ::= [APPLICATION 5] IMPLICIT Type1where the code used to encode value of type Type2 looks like
enc.encodeImplicit(Tags.makeTag(Tags.APPLICATION, 5)); enc.encodeImplicit(Tags.makeTag(Tags.APPLICATION, 2)); enc.encodeInteger();
tag - the implicit tag used to encode the next ASN.1 value.
IOException
public int encodeExplicit(int tag)
throws IOException
endOf method must be invoked to terminate the
explicitly encoding.
The encoding of the following ASN.1 type
version [0] EXPLICIT Versionlooks like:
int id = enc.encodeExplicit(Tags.makeTag(Tags.CONTEXT, 0));
enc.encodeInteger(version);
dec.endOf(id);
tag - the explicit tag of the next encoded ASN.1 value. The tag must
be a valid tag such as one that has been created with the Tags.createTag(int, int) method.
IOExceptionendOf(int),
Tags.createTag(int, int)
public int encodeSequence()
throws IOException
decode methods. Finally, the endOf method must be invoked to terminate the decoding of the SEQUENCE.
The returned int value must be passed to the endOf method
that then checks if the current nesting and the passed int do match.
The code samples below show the decoding of two nested sequences. The
corresponding ASN.1 definition is:
SEQUENCE {
s IA5String,
a SEQUENCE {
i INTEGER
}
}
int id1 = enc.encodeSequence();
enc.decodeIA5String("Organization");
int id2 = enc.encodeSequence();
enc.encodeInteger(124);
enc.endOf(id2);
enc.endOf(id1);
IOException
public int encodeSequenceOf()
throws IOException
encode methods. Finally, the endOf method must be invoked to terminate the encoding of the SEQUENCE
OF.
The returned int value must be passed to the endOf method
that then checks if the current nesting and the passed int do match.
The code samples below show the encoding of SEQUENCE OF. The
corresponding ASN.1 definition is:
MySequence ::= SEQUENCE OF PrintableString
List mySequence = ...; // contains a list of String
int id = enc.encodeSequenceOf();
Iterator it = mySequence.iterator();
while (it.hasNext()) {
enc.encodePrintableString((String)it.next());
}
enc.endOf(id);
IOException
public int encodeSet()
throws IOException
encode methods. Finally, the endOf method
must be invoked to terminate the encoding of the SET.
The returned int value must be passed to the endOf method
that then checks if the current nesting and the passed int do match.
The code samples below show the decoding of two nested sequences. The
corresponding ASN.1 definition is:
SET {
s IA5String,
a SET {
i INTEGER
}
}
int id1 = enc.encodeSet();
enc.decodeIA5String("Organization");
int id2 = enc.encodeSet();
enc.encodeInteger(124);
enc.endOf(id2);
enc.endOf(id1);
IOException
public int encodeSetOf()
throws IOException
encode methods. Finally, the endOf method must be invoked to terminate the encoding of the SET OF.
The returned int value must be passed to the endOf method
that then checks if the current nesting and the passed int do match.
The code samples below show the encoding of SET OF. The corresponding
ASN.1 definition is:
MySet ::= SET OF PrintableString
Set mySet = ...; // contains a set of String
int id = enc.encodeSetOf();
Iterator it = mySet.iterator();
while (it.hasNext()) {
enc.encodePrintableString((String)it.next());
}
enc.endOf(id);
IOException
public void endOf(int id)
throws IOException
id.
id - the reference to a constructed value.
EncodingException - if the specified identifier doesn't refer any
constructed value.
IOExceptionpublic boolean isDefaultEncoded()
public void reset()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||