Download ASN.1 Compiler Version 6.2 Java User`s Manual Objective Systems
Transcript
Generated BER/DER/CER Decode Methods For each ASN.1 production defined in the ASN.1 source file, a Java decode method may be generated. This method will decode an ASN.1 message into public member variables within the Java object. As was the case for encode methods, a decode method is only generated if it is required to alter the default method in the base class. The Java model is built on inheritance from a set of common run-time base classes. These runtime classes contain default implementations of encode/decode methods that handle the encoding/decoding of the basic types. These default implementations include support for handling the universal tags associated with the types as defined in the X.680 standard. Generated Java Method Format and Calling Parameters The signature for a Java BER decode method is as follows: public void decode (Asn1BerDecodeBuffer buffer, boolean explicit, int implicitLength) throws Asn1Exception, java.io.Exception The buffer argument is a reference of an Asn1BerDecodeBuffer object that describes the message that is being decoded. This must be created and initialized before calling any decode method. See the description of this class in the Java Run- Time Classes section for details on how this class is used. The explicit and implicitLength arguments specify whether or not an explicit tag should be parsed from the encoded contents. The average user will almost always want to set explicit to true and implicitLength to zero. The only time these arguments would not be set this way is if a user wanted to directly decode contents with no tag/length information. These arguments are used primarily by the compiler when generating internal calls to properly handle implicit and explicit tagging. The decode method returns no result. Unlike the C/C++ version, a negative status value is not returned to indicate a failure. That is handled by the exception mechanism. All ASN1C Java exceptions are derived from the Asn1Exception base class. See the section on exceptions for a complete list and description of the various ASN.1 exceptions that can be thrown. The java.io.Exception that can be thrown is in the read method within the decode buffer base class. This method attempts to read data from an input stream using the methods in the java.io package. Procedure for Calling Java BER Decode Methods The general procedure to decode an ASN.1 BER message involves the following three steps: 1. Create a decode message buffer object to describe the message to be decoded 2. Invoke the decode method 3. Process the decoded data values The first step is the creation of a decode message buffer object. The Asn1BerDecodeBuffer object contains constructors that can either accept a message as a byte array or as an I/O input stream. The input stream option makes it possible 61