| | |
| | | * with generic ASN.1 elements. Subclasses may provide more specific |
| | | * functionality for individual element types. |
| | | */ |
| | | @org.opends.server.types.PublicAPI( |
| | | stability=org.opends.server.types.StabilityLevel.UNCOMMITTED, |
| | | mayInstantiate=true, |
| | | mayExtend=false, |
| | | mayInvoke=true) |
| | | public class ASN1Element |
| | | implements ProtocolElement, Serializable |
| | | { |
| | | |
| | | |
| | | |
| | | /** |
| | | * The serial version identifier required to satisfy the compiler because this |
| | | * class implements the <CODE>java.io.Serializable</CODE> interface. This |
| | |
| | | * |
| | | * @return The BER type for this ASN.1 element. |
| | | */ |
| | | public byte getType() |
| | | public final byte getType() |
| | | { |
| | | return type; |
| | | } |
| | |
| | | * |
| | | * @param type The BER type for this ASN.1 element. |
| | | */ |
| | | public void setType(byte type) |
| | | public final void setType(byte type) |
| | | { |
| | | this.type = type; |
| | | } |
| | |
| | | * @return <CODE>true</CODE> if this ASN.1 element is in the universal class, |
| | | * or <CODE>false</CODE> if not. |
| | | */ |
| | | public boolean isUniversal() |
| | | public final boolean isUniversal() |
| | | { |
| | | return ((type & TYPE_MASK_ALL_BUT_CLASS) == TYPE_MASK_UNIVERSAL); |
| | | } |
| | |
| | | * @return <CODE>true</CODE> if this ASN.1 element is in the |
| | | * application-specific class, or <CODE>false</CODE> if not. |
| | | */ |
| | | public boolean isApplicationSpecific() |
| | | public final boolean isApplicationSpecific() |
| | | { |
| | | return ((type & TYPE_MASK_ALL_BUT_CLASS) == TYPE_MASK_APPLICATION); |
| | | } |
| | |
| | | * @return <CODE>true</CODE> if this ASN.1 element is in the context-specific |
| | | * class, or <CODE>false</CODE> if not. |
| | | */ |
| | | public boolean isContextSpecific() |
| | | public final boolean isContextSpecific() |
| | | { |
| | | return ((type & TYPE_MASK_ALL_BUT_CLASS) == TYPE_MASK_CONTEXT); |
| | | } |
| | |
| | | * @return <CODE>true</CODE> if this ASN.1 element is in the private class, |
| | | * or <CODE>false</CODE> if not. |
| | | */ |
| | | public boolean isPrivate() |
| | | public final boolean isPrivate() |
| | | { |
| | | return ((type & TYPE_MASK_ALL_BUT_CLASS) == TYPE_MASK_PRIVATE); |
| | | } |
| | |
| | | * @return <CODE>true</CODE> if this ASN.1 element has a primitive value, or |
| | | * <CODE>false</CODE> if it is constructed. |
| | | */ |
| | | public boolean isPrimitive() |
| | | public final boolean isPrimitive() |
| | | { |
| | | return ((type & TYPE_MASK_ALL_BUT_PC) == TYPE_MASK_PRIMITIVE); |
| | | } |
| | |
| | | * @return <CODE>true</CODE> if this ASN.1 element has a constructed value, |
| | | * or <CODE>false</CODE> if it is primitive. |
| | | */ |
| | | public boolean isConstructed() |
| | | public final boolean isConstructed() |
| | | { |
| | | return ((type & TYPE_MASK_ALL_BUT_PC) == TYPE_MASK_CONSTRUCTED); |
| | | } |
| | |
| | | * |
| | | * @return The encoded value for this ASN.1 element. |
| | | */ |
| | | public byte[] value() |
| | | public final byte[] value() |
| | | { |
| | | return value; |
| | | } |
| | |
| | | * |
| | | * @return The byte array containing the encoded ASN.1 element. |
| | | */ |
| | | public byte[] encode() |
| | | public final byte[] encode() |
| | | { |
| | | if (value.length == 0) |
| | | { |
| | |
| | | * @throws ASN1Exception If a problem occurs while attempting to decode this |
| | | * element as an ASN.1 Boolean element. |
| | | */ |
| | | public ASN1Boolean decodeAsBoolean() |
| | | public final ASN1Boolean decodeAsBoolean() |
| | | throws ASN1Exception |
| | | { |
| | | return ASN1Boolean.decodeAsBoolean(this); |
| | |
| | | * @throws ASN1Exception If a problem occurs while attempting to decode this |
| | | * element as an ASN.1 enumerated element. |
| | | */ |
| | | public ASN1Enumerated decodeAsEnumerated() |
| | | public final ASN1Enumerated decodeAsEnumerated() |
| | | throws ASN1Exception |
| | | { |
| | | return ASN1Enumerated.decodeAsEnumerated(this); |
| | |
| | | * @throws ASN1Exception If a problem occurs while attempting to decode this |
| | | * element as an ASN.1 integer element. |
| | | */ |
| | | public ASN1Integer decodeAsInteger() |
| | | public final ASN1Integer decodeAsInteger() |
| | | throws ASN1Exception |
| | | { |
| | | return ASN1Integer.decodeAsInteger(this); |
| | |
| | | * @throws ASN1Exception If a problem occurs while attempting to decode this |
| | | * element as an ASN.1 long element. |
| | | */ |
| | | public ASN1Long decodeAsLong() |
| | | public final ASN1Long decodeAsLong() |
| | | throws ASN1Exception |
| | | { |
| | | return ASN1Long.decodeAsLong(this); |
| | |
| | | * @throws ASN1Exception If a problem occurs while attempting to decode this |
| | | * element as an ASN.1 null element. |
| | | */ |
| | | public ASN1Null decodeAsNull() |
| | | public final ASN1Null decodeAsNull() |
| | | throws ASN1Exception |
| | | { |
| | | return ASN1Null.decodeAsNull(this); |
| | |
| | | * @throws ASN1Exception If a problem occurs while attempting to decode this |
| | | * element as an ASN.1 octet string element. |
| | | */ |
| | | public ASN1OctetString decodeAsOctetString() |
| | | public final ASN1OctetString decodeAsOctetString() |
| | | throws ASN1Exception |
| | | { |
| | | return ASN1OctetString.decodeAsOctetString(this); |
| | |
| | | * @throws ASN1Exception If a problem occurs while attempting to decode this |
| | | * element as an ASN.1 sequence element. |
| | | */ |
| | | public ASN1Sequence decodeAsSequence() |
| | | public final ASN1Sequence decodeAsSequence() |
| | | throws ASN1Exception |
| | | { |
| | | return ASN1Sequence.decodeAsSequence(this); |
| | |
| | | * @throws ASN1Exception If a problem occurs while attempting to decode this |
| | | * element as an ASN.1 set element. |
| | | */ |
| | | public ASN1Set decodeAsSet() |
| | | public final ASN1Set decodeAsSet() |
| | | throws ASN1Exception |
| | | { |
| | | return ASN1Set.decodeAsSet(this); |
| | |
| | | * |
| | | * @return The name of the protocol associated with this protocol element. |
| | | */ |
| | | public String getProtocolElementName() |
| | | public final String getProtocolElementName() |
| | | { |
| | | return "ASN.1"; |
| | | } |
| | |
| | | * object will be considered equal if it is an ASN.1 element (or a |
| | | * subclass) with the same type and encoded value. |
| | | */ |
| | | public boolean equals(Object o) |
| | | public final boolean equals(Object o) |
| | | { |
| | | if (this == o) |
| | | { |
| | |
| | | * @return <CODE>true</CODE> if the values of the elements are equal, or |
| | | * <CODE>false</CODE> if not. |
| | | */ |
| | | public boolean equalsIgnoreType(ASN1Element element) |
| | | public final boolean equalsIgnoreType(ASN1Element element) |
| | | { |
| | | return Arrays.equals(value, element.value); |
| | | } |
| | |
| | | * @return <CODE>true</CODE> if the values are equal, or <CODE>false</CODE> |
| | | * if not. |
| | | */ |
| | | public boolean equalsIgnoreType(ByteString byteString) |
| | | public final boolean equalsIgnoreType(ByteString byteString) |
| | | { |
| | | return Arrays.equals(value, byteString.value()); |
| | | } |
| | |
| | | * or <CODE>false</CODE> if not. The elements will be considered |
| | | * equal if they have the same type and encoded value. |
| | | */ |
| | | public boolean equalsElement(ASN1Element e) |
| | | public final boolean equalsElement(ASN1Element e) |
| | | { |
| | | if (this == e) |
| | | { |
| | |
| | | * |
| | | * @return The hash code for this ASN.1 element. |
| | | */ |
| | | public int hashCode() |
| | | public final int hashCode() |
| | | { |
| | | int hashCode = type; |
| | | int length = Math.min(20, value.length); |
| | |
| | | * |
| | | * @return A string representation of this ASN.1 element. |
| | | */ |
| | | public String toString() |
| | | public final String toString() |
| | | { |
| | | StringBuilder buffer = new StringBuilder(); |
| | | toString(buffer); |