public interface EncodeListener
extends java.util.EventListener
toASN1Object method of such a structure, use an empty
OCTET_STRING for the not-yet known byte value, and implement the
encodeCalled method to set the
OCTET_STRING value actually during the encoding is performed, e.g.:
class xxx implements EncodeListener {
...
byte[] value;
...
public ASN1Object toASN1Object() throws CodingException {
SEQUENCE seq = new SEQUENCE();
...
// create an empty octet string and register as encode listener
OCTET_STRING oct = OCTET_STRING();
oct.addEncodeListener(this, 1);
}
...
// implement the encodeCalled method for setting the value during the
// encoding actually is performed
public void encodeCalled(ASN1Object o, int id) throws CodingException {
...
o.setValue(value);
}
...
}
Now, when calling DerCoder.encode(xxx.toASN1Object()) for
performing the DER encoding, the
addEncodeListener method of the ASN1Object
class is used for registering the calling instance of the xxx
class to be notified when the OCTET_STRING component actually has to be
encoded. Later, the program execution will jump to the
encodeCalled method of the xxx instance for
obtaining the OCTET_STRING value. The encode method of the
OCTET_STRING instance itself will be executed not before the
encodeCalled methods of all registers listeners have been
executed.
Within the IAIK-JCE library, the EncodeListener utility is used for the
stream implementations of the several PKCS#7 content types, where the raw
data to be processed - e.g. signed for the example of the
SignedData type - is supplied from an input stream that is not
read before the encoding actually is performed. Since the, for instance,
encryptedDigest value of an inherent SigenrInfo
depends on the data supplied from the stream, it cannot be calculated before
the stream has been read, and therefore has been set during the encoding. For
that reason, the SignerInfo class implemets the EncodeListener
interface.
ASN1Object| Modifier and Type | Method and Description |
|---|---|
void |
encodeCalled(ASN1Object o,
int id)
Method to be implemented for being called during the encoding procedure.
|
void encodeCalled(ASN1Object o, int id) throws CodingException
Use this method for setting specific properties of the supplied ASN1Object
actually during the encoding is performed. If the EncodeListener wishes to
be notified about the encoding process of more than only one object, use
different id values to distinguish between the several
objects.
o - the ASN1Object to be supplied with information during the encoding
processid - an id that may be used to listen for more than only one object
encodingsCodingException - if an error occurs during the encoding procedure