|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jasn.BaseBerEncoder
This abstract class implements the basic functionality of an ASN.1 encoder using the Basic Encoding Rules (BER).
| Field Summary | |
protected int |
implicitTag
|
| Constructor Summary | |
BaseBerEncoder()
|
|
| 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. |
abstract 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)
Starts the encoding of an implicitely tagged ASN.1 value. |
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. |
protected void |
encodeLength(int len)
Encodes the length part of a BER TLV. |
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 offs,
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. |
abstract int |
encodeSequence()
Starts the encoding of an ASN.1 SEQUENCE. |
int |
encodeSequenceOf()
Starts the encoding of an ASN.1 SEQUENCE OF. |
abstract int |
encodeSet()
Starts the encoding of an ASN.1 SET. |
int |
encodeSetOf()
Starts the encoding of an ASN.1 SET OF. |
protected int |
encodeTag(int tag,
boolean constructed)
|
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. |
abstract void |
endOf(int id)
Terminates the encoding of the constructed value identified by id. |
protected byte[] |
getByteBuffer(int len)
|
protected char[] |
getCharBuffer(int len)
Returns an array of characters whose size is sufficient to hold len characters. |
boolean |
isDefaultEncoded()
Indicates wether this encoder encodes DEFAULT values. |
void |
setName(String name)
|
protected abstract void |
writeByte(int b)
|
protected void |
writeBytes(byte[] b)
|
protected abstract void |
writeBytes(byte[] b,
int offs,
int len)
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface org.jasn.Asn1Encoder |
reset |
| Field Detail |
protected int implicitTag
| Constructor Detail |
public BaseBerEncoder()
| Method Detail |
public void encodeAny(byte[] encoded)
throws IOException
Asn1EncoderNullPointerException is thrown if the array is
null.
encodeAny in interface Asn1Encoderencoded - the array of bytes
IOException
public void encodeBoolean(boolean b)
throws IOException
Asn1Encoder
encodeBoolean in interface Asn1Encoderb - the boolean value to be encoded.
IOException
public void encodeInteger(BigInteger i)
throws IOException
Asn1EncoderencodeInteger 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.
encodeInteger in interface Asn1Encoderi - the arbitrary-precision integer to be encoded.
IOExceptionAsn1Encoder.encodeInteger(int),
Asn1Encoder.encodeInteger(long)
public void encodeInteger(int i)
throws IOException
Asn1Encoder
encodeInteger in interface Asn1Encoderi - the number to be encoded.
IOException
public void encodeInteger(long l)
throws IOException
Asn1Encoder
encodeInteger in interface Asn1Encoderl - the number to be encoded.
IOException
public void encodeBitString(BitString bits)
throws IOException
Asn1Encoderbits is null, a NullPointerException
is thrown.
encodeBitString in interface Asn1Encoderbits - a BitString representing the sequence of bits to
be encoded.
IOException
public void encodeBitString(byte[] bits)
throws IOException
Asn1Encoderbits is null, a NullPointerException
is thrown.
encodeBitString in interface Asn1Encoderbits - an array of bytes representing the sequence of bits to be
encoded.
IOException
public void encodeOctetString(byte[] b,
int offs,
int len)
throws IOException
Asn1Encoderlen 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.
encodeOctetString in interface Asn1Encoderb - the byte array containing the bytes to be encoded.offs - the start offset in the byte array.len - the number of bytes to encode.
IOException
public void encodeOctetString(byte[] b)
throws IOException
Asn1Encoderb.length bytes from the specified byte array as
an ASN.1 OCTET STRING.
If b is null, a NullPointerException
is thrown.
encodeOctetString in interface Asn1Encoderb - the byte array to be encoded.
IOExceptionAsn1Encoder.encodeOctetString(byte[],int,int)
public void encodeNull()
throws IOException
Asn1Encoder
encodeNull in interface Asn1EncoderIOException
public void encodeObjectIdentifier(ObjectIdentifier oid)
throws IOException
Asn1Encoderoid is null, a NullPointerException
is thrown.
encodeObjectIdentifier in interface Asn1Encoderoid - the ObjectIdentifier to encode.
IOException
public void encodeReal(double value)
throws IOException
UnsupportedOperationException each time it is invoked.
encodeReal in interface Asn1Encodervalue - the number to be encoded.
IOException
public void encodeEnumerated(BigInteger e)
throws IOException
Asn1Encoderint or a
long. Otherwise the encodeEnumerated methods
with int or long parameter should be used.
encodeEnumerated in interface Asn1Encodere - the ENUMERATED value represented as a abitrary-precision
integer.
IOExceptionAsn1Encoder.encodeEnumerated(int),
Asn1Encoder.encodeEnumerated(long)
public void encodeEnumerated(int e)
throws IOException
Asn1Encoder
encodeEnumerated in interface Asn1Encodere - the ENUMERATED value to encode.
IOException
public void encodeEnumerated(long e)
throws IOException
Asn1Encoder
encodeEnumerated in interface Asn1Encodere - the ENUMERATED value to encode.
IOException
public void encodeUTF8String(String s)
throws IOException
Asn1Encoder
encodeUTF8String in interface Asn1Encoders - the string value to encode.
IOException
public abstract int encodeSequence()
throws IOException
Asn1Encoderdecode 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);
encodeSequence in interface Asn1EncoderIOException
public int encodeSequenceOf()
throws IOException
Asn1Encoderencode 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);
encodeSequenceOf in interface Asn1EncoderIOException
public abstract int encodeSet()
throws IOException
Asn1Encoderencode 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);
encodeSet in interface Asn1EncoderIOException
public int encodeSetOf()
throws IOException
Asn1Encoderencode 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);
encodeSetOf in interface Asn1EncoderIOException
public void encodeNumericString(String s)
throws IOException
Asn1Encoder
encodeNumericString in interface Asn1Encoders - the string value to encode.
IOException
public void encodePrintableString(String s)
throws IOException
Asn1EncoderName 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 ?
encodePrintableString in interface Asn1Encoders - the string value to encode.
IOException
public void encodeTeletexString(String s)
throws IOException
Asn1Encoder
encodeTeletexString in interface Asn1Encoders - the string value to encode.
IOException
public void encodeVideotexString(String s)
throws IOException
Asn1Encoder
encodeVideotexString in interface Asn1Encoders - the string value to encode.
IOException
public void encodeIA5String(String s)
throws IOException
Asn1Encoder
encodeIA5String in interface Asn1Encoders - the string value to encode.
IOException
public void encodeUTCTime(Calendar date)
throws IOException
Asn1Encoder
encodeUTCTime in interface Asn1Encoderdate - the date to encode.
IOException
public void encodeGeneralizedTime(Calendar date)
throws IOException
Asn1Encoder
encodeGeneralizedTime in interface Asn1Encoderdate - the date to encode.
IOException
public void encodeGraphicString(String s)
throws IOException
Asn1Encoder
encodeGraphicString in interface Asn1Encoders - the string value to encode.
IOException
public void encodeVisibleString(String s)
throws IOException
Asn1Encoder
encodeVisibleString in interface Asn1Encoders - the string value to encode.
IOException
public void encodeGeneralString(String s)
throws IOException
Asn1Encoder
encodeGeneralString in interface Asn1Encoders - the string value to encode.
IOException
public void encodeUniversalString(String s)
throws IOException
Asn1EncoderUniversalString 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.
encodeUniversalString in interface Asn1Encoders - the string value to encode.
IOException
public void encodeBMPString(String s)
throws IOException
Asn1Encoder
encodeBMPString in interface Asn1Encoders - the string value to encode.
IOException
public void encodeImplicit(int tag)
throws IOException
encodeImplicit in interface Asn1Encodertag - the implicit tag used to encode the next ASN.1 value.
IOException
public abstract int encodeExplicit(int tag)
throws IOException
Asn1EncoderendOf 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);
encodeExplicit in interface Asn1Encodertag - 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.
IOExceptionAsn1Encoder.endOf(int),
Tags.createTag(int, int)
public abstract void endOf(int id)
throws IOException
Asn1Encoderid.
endOf in interface Asn1Encoderid - the reference to a constructed value.
IOException
public void setName(String name)
throws IOException
IOExceptionpublic boolean isDefaultEncoded()
Asn1Encoder
isDefaultEncoded in interface Asn1Encoder
protected int encodeTag(int tag,
boolean constructed)
throws IOException
IOException
protected void encodeLength(int len)
throws IOException
IOException
protected abstract void writeByte(int b)
throws IOException
IOException
protected abstract void writeBytes(byte[] b,
int offs,
int len)
throws IOException
IOException
protected void writeBytes(byte[] b)
throws IOException
IOExceptionprotected char[] getCharBuffer(int len)
len characters.
len - the minimum length of the array to return.
protected byte[] getByteBuffer(int len)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||