Example #1
0
  public boolean equals(Object o) {
    if (o == null || !(o instanceof ASN1Sequence)) {
      return false;
    }

    ASN1Sequence other = (ASN1Sequence) o;

    if (this.getSize() != other.getSize()) {
      return false;
    }

    Enumeration s1 = this.getObjects();
    Enumeration s2 = other.getObjects();

    while (s1.hasMoreElements()) {
      if (!s1.nextElement().equals(s2.nextElement())) {
        return false;
      }
    }

    return true;
  }
Example #2
0
  /**
   * Return an ASN1 sequence from a tagged object. There is a special case here, if an object
   * appears to have been explicitly tagged on reading but we were expecting it to be implictly
   * tagged in the normal course of events it indicates that we lost the surrounding sequence - so
   * we need to add it back (this will happen if the tagged object is a sequence that contains other
   * sequences). If you are dealing with implicitly tagged sequences you really <b>should</b> be
   * using this method.
   *
   * @param obj the tagged object.
   * @param explicit true if the object is meant to be explicitly tagged, false otherwise.
   * @exception IllegalArgumentException if the tagged object cannot be converted.
   */
  public static ASN1Sequence getInstance(ASN1TaggedObject obj, boolean explicit) {
    if (explicit) {
      if (!obj.isExplicit()) {
        throw new IllegalArgumentException("object implicit - explicit expected.");
      }

      return (ASN1Sequence) obj.getObject();
    } else {
      //
      // constructed object which appears to be explicitly tagged
      // when it should be implicit means we have to add the
      // surrounding sequence.
      //
      if (obj.isExplicit()) {
        ASN1Sequence seq;

        if (obj instanceof BERTaggedObject) {
          seq = new BERConstructedSequence();
        } else {
          seq = new DERConstructedSequence();
        }

        seq.addObject(obj.getObject());

        return seq;
      } else {
        ASN1Sequence seq;

        if (obj.getObject() instanceof ASN1Sequence) {
          return (ASN1Sequence) obj.getObject();
        }
      }
    }

    throw new IllegalArgumentException("unknown object in getInstanceFromTagged");
  }