codec.asn1
Class ASN1Opaque

java.lang.Object
  extended by codec.asn1.ASN1AbstractType
      extended by codec.asn1.ASN1TaggedType
          extended by codec.asn1.ASN1Opaque
All Implemented Interfaces:
ASN1Type, Cloneable

public class ASN1Opaque
extends ASN1TaggedType

Represents an opaque type. An opaque type merely decodes the tag and tag class and stores the contents octets in an OCTET STRING. The opaque type is represented in ASN.1 as

[UNIVERSAL x] IMPLICIT OCTET STRING
where x is the tag.

The opaque type is comparable to an open type in that it matches any type (just like the deprecated ANY type) on decoding. The encoding can be reconstructed easily. This type is used whenever decoding of a structure should be deferred to a later point in time. For instance an AlgorithmIdentifier implementation can use an opaque type in order to decode algorithm parameters. The encoding of the algorithm parameters is then done by JCA/JCE classes later on.

One drawback of the opaque type is that special handling by the encoders and decoders is rquired to make it work properly. The main problem is that the opaque type does not store whether the underlying type is constructed or primitive. This decision must be made by the encoder.

Due to this limitation the opaque type can be used only for decoding types of class UNIVERSAL.

Version:
"$Id: ASN1Opaque.java 1913 2007-08-08 02:41:53Z jpeters $"
Author:
Volker Roth

Constructor Summary
ASN1Opaque()
          Creates an instance.
ASN1Opaque(byte[] code)
          Creates an instance that stores the given encoding.
ASN1Opaque(int tag, int tagclass, byte[] b)
          Creates an instance with the given type, class, and inner type.
 
Method Summary
 Object clone()
          Returns a clone.
 byte[] getEncoded()
          This method is a convenience method in order to encode this type with DER.
 boolean isType(int tag, int tagclass)
          This method adopts the given tag and tag class if this instance is not yet initialised with a tag or tag class.
 void setInnerType(ASN1Type t)
          Sets the inner type of this opaque type.
 
Methods inherited from class codec.asn1.ASN1TaggedType
decode, encode, getInnerType, getTag, getTagClass, getValue, isExplicit, setExplicit, setTag, setTagClass, toString
 
Methods inherited from class codec.asn1.ASN1AbstractType
checkConstraints, getConstraint, isOptional, setConstraint, setOptional
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ASN1Opaque

public ASN1Opaque()
Creates an instance. On decoding, opaque types pretend to be of a particular type and read the actual type's encoding into an OCTET STRING from which it can be retrieved later.


ASN1Opaque

public ASN1Opaque(byte[] code)
           throws ASN1Exception
Creates an instance that stores the given encoding. The encoding must be a valid DER encoding as specified in X.690. This constructor uses a DERDecoder in order to decode the identifier octets in the given encoding.

Note: If the given encoding contains the concatenation of multiple encodings then only the first one will be stored. All others will be lost.

Throws:
ASN1Exception - if the given code cannot be decoded.

ASN1Opaque

public ASN1Opaque(int tag,
                  int tagclass,
                  byte[] b)
Creates an instance with the given type, class, and inner type. Be careful, the given octet string must contain the valid DER encoding of the contents octets of a type that matches the tag and tag class. Otherwise coding exceptions are most probably thrown subsequently.

Parameters:
tag - The ASN.1 tag of the opaque type.
tagclass - The tag class of the opaque type.
b - The DER compliant encoding of the contents octets of the opaque type.
Throws:
NullPointerException - if the given byte array is null.
Method Detail

isType

public boolean isType(int tag,
                      int tagclass)
This method adopts the given tag and tag class if this instance is not yet initialised with a tag or tag class. In that case true is returned.

If a tag or tag class is already set then this method calls its super method.

Specified by:
isType in interface ASN1Type
Overrides:
isType in class ASN1AbstractType
Parameters:
tag - The tag to compare with.
tagclass - The tag class to compare with.
Returns:
true if the given tag and tag class matches this type and false otherwise.

getEncoded

public byte[] getEncoded()
                  throws ASN1Exception
This method is a convenience method in order to encode this type with DER. It uses a DEREncoder in order to encode this type to a byte array which is returned.

Returns:
The DER encoding of this type.
Throws:
ASN1Exception

setInnerType

public void setInnerType(ASN1Type t)
Sets the inner type of this opaque type. The given type must be ASN1OctetString or a ClassCastException is thrown.

Overrides:
setInnerType in class ASN1TaggedType
Parameters:
t - The type to set as the inner type.
Throws:
NullPointerException - if the given type is null.
ClassCastException - if the given type is not an ASN1OctetString.

clone

public Object clone()
Returns a clone. The clone is a deep copy of this instance except the constraints. Constraints are copied by reference.

Overrides:
clone in class Object
Returns:
The clone.


Copyright © Fraunhofer Gesellschaft. All Rights Reserved.