public class EncodedASN1Object extends ASN1Object
mySequence ::= SEQUENCE { firstComponent INTEGER, secondComponent SEQUENCE }Normally you would have to decode the SEQUENCE before adding it to the new SEQUENCE type:
SEQUENCE mySequence = new SEQUENCE(); mySequence.addComponent(new INTEGER(2)); mySequence.addComponent(DerCoder.decode(encodedSequence));The code sample above may appear as part of an
toASN1Object
method for giving an ASN.1 representation of an Java object to
be fed immediately to the DerCoder encoding utility:
byte[] encoding = DerCoder.encode(myASN1Class.toASN1Object());Now, with class
EncodedASN1Object
you may avoid the
decoding-encoding step by immediately supplying the encoded
SEQUENCE component:
SEQUENCE mySequence = new SEQUENCE(); mySequence.addComponent(new INTEGER(2)); mySequence.addComponent(new EncodedASN1Object(encodedSequence));When now calling the DerCoder, the second component is encoded by only "copying" the already given encoding.
Attention! This class only should be used very carefully and
only for a purpose as described above. This class only provides
very limited access to the ASN.1 functionalities accustomed from the
other ASN.1 types of this packages. So, for instance, it does not
have a tag number associated to it and it does not provide any decoding
enhancements. This class provides nothing more than some kind of piping
mechanism: the encoded bytes supplied by one of the constructures are
written ("copied") unchanged to the supplied OutputStream when the
DerCoder calls the encode
method.
ASN1Object
,
ASN
,
ConstructedType
,
DerCoder
asnType, constructed, encode_listener, indefinite_length, isStringType, stream_mode
Constructor and Description |
---|
EncodedASN1Object()
Creates an empty EncodedASN1Object.
|
EncodedASN1Object(byte[] encodedASN1Object)
Creates an EncodedASN1Object object where the encoding is supplied from an
byte array.
|
EncodedASN1Object(java.io.InputStream encodedStream)
Creates an EncodedASN1Object object where the encoding is supplied from an
input stream.
|
EncodedASN1Object(java.io.InputStream encodedStream,
int blockSize)
Creates an EncodedASN1Object object which reads the encoding from an InputStream
and processes it into blocks of
blockSize bytes. |
Modifier and Type | Method and Description |
---|---|
protected void |
decode(int length,
java.io.InputStream is)
Only throws a CodingException since decoding not supported by this class.
|
protected void |
encode(java.io.OutputStream os)
Writes this EncodedASN1Object to the given output stream.
|
int |
getBlockSize()
Returns the blockSize defining the number of bytes to be processed in memory.
|
java.lang.Object |
getValue()
Returns the encoded ASN.1 object itself.
|
void |
setIndefiniteLength(boolean indefiniteLength)
Does nothing.
|
void |
setValue(java.lang.Object object)
Sets the value of this object.
|
java.lang.String |
toString()
Returns a string representation of this object.
|
addComponent, addEncodeListener, clone, countComponents, encodeObject, getAsnType, getComponentAt, indefiniteLength, isA, isConstructed, isStringType
public EncodedASN1Object()
public EncodedASN1Object(byte[] encodedASN1Object)
encodedASN1Object
- an encoded ASN.1 object supplied from a byte arraypublic EncodedASN1Object(java.io.InputStream encodedStream)
encodedStream
- an encoded ASN.1 object supplied from an input streampublic EncodedASN1Object(java.io.InputStream encodedStream, int blockSize)
blockSize
bytes.
This constructor does not decode the given encoded ASN.1 object! It only
maintains the given encoding to be written out when the DerCoder is
invoked.encodedStream
- an encoded ASN.1 object supplied from an input streamblockSize
- the blocksize setting the block size for in-memory processingpublic java.lang.Object getValue()
getValue
in class ASN1Object
public void setValue(java.lang.Object object)
The value may be supplied as byte array or input stream and represents the encoding of the ASN1Object.
Generally there should be no need for using this method since data immediately can be supplied when creating a new simple OCTET_STRING object by means of a proper constructor.
setValue
in class ASN1Object
object
- the value (encoding), as byte array or input streampublic void setIndefiniteLength(boolean indefiniteLength)
setIndefiniteLength
in class ASN1Object
indefiniteLength
- ignoredprotected void encode(java.io.OutputStream os) throws java.io.IOException
encode
methods of the
DerCoder
class for performing
the encoding, and the DerCoder internally will call this
encode
method.encode
in class ASN1Object
os
- the output stream to which to write the encodingjava.io.IOException
- if an error occurs during writing to the streamprotected void decode(int length, java.io.InputStream is) throws CodingException
decode
in class ASN1Object
length
- the already decoded length, i.e. number of the bytes representing
the ASN1Object to be decodedis
- the InputStream supplying the encoded ASN1Objectjava.io.IOException
- if there is a problem with the InputStreamCodingException
- since not supported by this classpublic int getBlockSize()
public java.lang.String toString()
toString
in class ASN1Object