org.bouncycastle.asn1

## Class ASN1TaggedObject

- java.lang.Object
- - org.bouncycastle.asn1.ASN1Object
  - - org.bouncycastle.asn1.ASN1Primitive
    - - org.bouncycastle.asn1.ASN1TaggedObject

- All Implemented Interfaces:
    ASN1Encodable, ASN1TaggedObjectParser, InMemoryRepresentable, Encodable
  Direct Known Subclasses:
    BERTaggedObject, DERTaggedObject, DLTaggedObject

      public abstract class ASN1TaggedObject
      extends ASN1Primitive
      implements ASN1TaggedObjectParser

  ASN.1 TaggedObject - in ASN.1 notation this is any object preceded by a [n] where n is some number - these are assumed to follow the construction rules (as with sequences).

- - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `ASN1TaggedObject(boolean explicit, int tagNo, ASN1Encodable obj)` Create a tagged object with the style given by the value of explicit.
    `protected` | `ASN1TaggedObject(boolean explicit, int tagClass, int tagNo, ASN1Encodable obj)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `ASN1Object` | `getBaseObject()` Needed for open types, until we have better type-guided parsing support.
    `ASN1Primitive` | `getBaseUniversal(boolean declaredExplicit, int tagNo)` Note: tagged objects are generally context dependent.
    `static ASN1TaggedObject` | `getContextInstance(java.lang.Object obj)`
    `static ASN1TaggedObject` | `getContextInstance(java.lang.Object obj, int tagNo)`
    `static ASN1TaggedObject` | `getContextOptional(ASN1Encodable element)`
    `static ASN1TaggedObject` | `getContextOptional(ASN1Encodable element, int tagNo)`
    `ASN1Object` | `getExplicitBaseObject()` Needed for open types, until we have better type-guided parsing support.
    `ASN1TaggedObject` | `getExplicitBaseTagged()`
    `ASN1TaggedObject` | `getImplicitBaseTagged(int baseTagClass, int baseTagNo)`
    `static ASN1TaggedObject` | `getInstance(ASN1TaggedObject taggedObject, boolean declaredExplicit)`
    `static ASN1TaggedObject` | `getInstance(ASN1TaggedObject taggedObject, int tagClass, boolean declaredExplicit)`
    `static ASN1TaggedObject` | `getInstance(ASN1TaggedObject taggedObject, int tagClass, int tagNo, boolean declaredExplicit)`
    `static ASN1TaggedObject` | `getInstance(java.lang.Object obj)`
    `static ASN1TaggedObject` | `getInstance(java.lang.Object obj, int tagClass)`
    `static ASN1TaggedObject` | `getInstance(java.lang.Object obj, int tagClass, int tagNo)`
    `ASN1Primitive` | `getLoadedObject()` Get the in-memory representation of the ASN.1 object.
    `static ASN1TaggedObject` | `getOptional(ASN1Encodable element)`
    `static ASN1TaggedObject` | `getOptional(ASN1Encodable element, int tagClass)`
    `static ASN1TaggedObject` | `getOptional(ASN1Encodable element, int tagClass, int tagNo)`
    `int` | `getTagClass()` Return the tag class associated with this object.
    `int` | `getTagNo()` Return the tag number associated with this object.
    `boolean` | `hasContextTag()`
    `boolean` | `hasContextTag(int tagNo)`
    `int` | `hashCode()`
    `boolean` | `hasTag(int tagClass, int tagNo)`
    `boolean` | `hasTagClass(int tagClass)`
    `boolean` | `isExplicit()` return whether or not the object may be explicitly tagged.
    `ASN1Encodable` | `parseBaseUniversal(boolean declaredExplicit, int baseTagNo)`
    `ASN1Encodable` | `parseExplicitBaseObject()` Needed for open types, until we have better type-guided parsing support.
    `ASN1TaggedObjectParser` | `parseExplicitBaseTagged()`
    `ASN1TaggedObjectParser` | `parseImplicitBaseTagged(int baseTagClass, int baseTagNo)`
    `java.lang.String` | `toString()`

    - ### Methods inherited from class org.bouncycastle.asn1.ASN1Primitive

      `encodeTo, encodeTo, equals, equals, equals, fromByteArray, fromStream, toASN1Primitive`

    - ### Methods inherited from class org.bouncycastle.asn1.ASN1Object

      `getEncoded, getEncoded, hasEncodedTagValue`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface org.bouncycastle.asn1.ASN1Encodable

      `toASN1Primitive`

- - ### Constructor Detail

    - #### ASN1TaggedObject

          protected ASN1TaggedObject(boolean explicit,
                                     int tagNo,
                                     ASN1Encodable obj)

      Create a tagged object with the style given by the value of explicit.

      If the object implements ASN1Choice the tag style will always be changed to explicit in accordance with the ASN.1 encoding rules.

      Parameters:
        `explicit` - true if the object is explicitly tagged.
        `tagNo` - the tag number for this object.
        `obj` - the tagged object.

    - #### ASN1TaggedObject

          protected ASN1TaggedObject(boolean explicit,
                                     int tagClass,
                                     int tagNo,
                                     ASN1Encodable obj)

  - ### Method Detail

    - #### getContextInstance

          public static ASN1TaggedObject getContextInstance(java.lang.Object obj)

    - #### getContextInstance

          public static ASN1TaggedObject getContextInstance(java.lang.Object obj,
                                                            int tagNo)

    - #### getContextOptional

          public static ASN1TaggedObject getContextOptional(ASN1Encodable element)

    - #### getContextOptional

          public static ASN1TaggedObject getContextOptional(ASN1Encodable element,
                                                            int tagNo)

    - #### getInstance

          public static ASN1TaggedObject getInstance(java.lang.Object obj)

    - #### getInstance

          public static ASN1TaggedObject getInstance(java.lang.Object obj,
                                                     int tagClass)

    - #### getInstance

          public static ASN1TaggedObject getInstance(java.lang.Object obj,
                                                     int tagClass,
                                                     int tagNo)

    - #### getInstance

          public static ASN1TaggedObject getInstance(ASN1TaggedObject taggedObject,
                                                     boolean declaredExplicit)

    - #### getInstance

          public static ASN1TaggedObject getInstance(ASN1TaggedObject taggedObject,
                                                     int tagClass,
                                                     boolean declaredExplicit)

    - #### getInstance

          public static ASN1TaggedObject getInstance(ASN1TaggedObject taggedObject,
                                                     int tagClass,
                                                     int tagNo,
                                                     boolean declaredExplicit)

    - #### getOptional

          public static ASN1TaggedObject getOptional(ASN1Encodable element)

    - #### getOptional

          public static ASN1TaggedObject getOptional(ASN1Encodable element,
                                                     int tagClass)

    - #### getOptional

          public static ASN1TaggedObject getOptional(ASN1Encodable element,
                                                     int tagClass,
                                                     int tagNo)

    - #### hashCode

          public int hashCode()

      Specified by:
        `hashCode` in class `ASN1Primitive`

    - #### getTagClass

          public int getTagClass()

      Description copied from interface: `ASN1TaggedObjectParser`
      Return the tag class associated with this object.
      Specified by:
        `getTagClass` in interface `ASN1TaggedObjectParser`
      Returns:
        the tag class.

    - #### getTagNo

          public int getTagNo()

      Return the tag number associated with this object.
      Specified by:
        `getTagNo` in interface `ASN1TaggedObjectParser`
      Returns:
        the tag number.

    - #### hasContextTag

          public boolean hasContextTag()

      Specified by:
        `hasContextTag` in interface `ASN1TaggedObjectParser`

    - #### hasContextTag

          public boolean hasContextTag(int tagNo)

      Specified by:
        `hasContextTag` in interface `ASN1TaggedObjectParser`

    - #### hasTag

          public boolean hasTag(int tagClass,
                                int tagNo)

      Specified by:
        `hasTag` in interface `ASN1TaggedObjectParser`

    - #### hasTagClass

          public boolean hasTagClass(int tagClass)

      Specified by:
        `hasTagClass` in interface `ASN1TaggedObjectParser`

    - #### isExplicit

          public boolean isExplicit()

      return whether or not the object may be explicitly tagged.

      Note: if the object has been read from an input stream, the only time you can be sure if isExplicit is returning the true state of affairs is if it returns false. An implicitly tagged object may appear to be explicitly tagged, so you need to understand the context under which the reading was done as well, see getObject below.

    - #### getBaseObject

          public ASN1Object getBaseObject()

      Needed for open types, until we have better type-guided parsing support. Use sparingly for other purposes, and prefer `getExplicitBaseTagged()`, `getImplicitBaseTagged(int, int)` or `getBaseUniversal(boolean, int)` where possible. Before using, check for matching tag `class` and `number`.

    - #### getExplicitBaseObject

          public ASN1Object getExplicitBaseObject()

      Needed for open types, until we have better type-guided parsing support. Use sparingly for other purposes, and prefer `getExplicitBaseTagged()` or `getBaseUniversal(boolean, int)` where possible. Before using, check for matching tag `class` and `number`.

    - #### getExplicitBaseTagged

          public ASN1TaggedObject getExplicitBaseTagged()

    - #### getImplicitBaseTagged

          public ASN1TaggedObject getImplicitBaseTagged(int baseTagClass,
                                                        int baseTagNo)

    - #### getBaseUniversal

          public ASN1Primitive getBaseUniversal(boolean declaredExplicit,
                                                int tagNo)

      Note: tagged objects are generally context dependent. Before trying to extract a tagged object this way, make sure you have checked that both the `tag class` and `tag number` match what you are looking for.
      Parameters:
        `declaredExplicit` - Whether the tagged type for this object was declared EXPLICIT.
        `tagNo` - The universal `tag number` of the expected base object.

    - #### parseBaseUniversal

          public ASN1Encodable parseBaseUniversal(boolean declaredExplicit,
                                                  int baseTagNo)
                                           throws java.io.IOException

      Specified by:
        `parseBaseUniversal` in interface `ASN1TaggedObjectParser`
      Throws:
        `java.io.IOException`

    - #### parseExplicitBaseObject

          public ASN1Encodable parseExplicitBaseObject()
                                                throws java.io.IOException

      Description copied from interface: `ASN1TaggedObjectParser`
      Needed for open types, until we have better type-guided parsing support. Use sparingly for other purposes, and prefer `ASN1TaggedObjectParser.parseExplicitBaseTagged()` or `ASN1TaggedObjectParser.parseBaseUniversal(boolean, int)` where possible. Before using, check for matching tag `class` and `number`.
      Specified by:
        `parseExplicitBaseObject` in interface `ASN1TaggedObjectParser`
      Throws:
        `java.io.IOException`

    - #### parseExplicitBaseTagged

          public ASN1TaggedObjectParser parseExplicitBaseTagged()
                                                         throws java.io.IOException

      Specified by:
        `parseExplicitBaseTagged` in interface `ASN1TaggedObjectParser`
      Throws:
        `java.io.IOException`

    - #### parseImplicitBaseTagged

          public ASN1TaggedObjectParser parseImplicitBaseTagged(int baseTagClass,
                                                                int baseTagNo)
                                                         throws java.io.IOException

      Specified by:
        `parseImplicitBaseTagged` in interface `ASN1TaggedObjectParser`
      Throws:
        `java.io.IOException`

    - #### getLoadedObject

          public final ASN1Primitive getLoadedObject()

      Description copied from interface: `InMemoryRepresentable`
      Get the in-memory representation of the ASN.1 object.
      Specified by:
        `getLoadedObject` in interface `InMemoryRepresentable`
      Returns:
        an ASN1Primitive representing the loaded object.

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`