/**
   * Constructor from ASN1Sequence.
   *
   * <p>The sequence is of type CertificatePair:
   *
   * <p>
   *
   * <pre>
   *       CertificatePair ::= SEQUENCE {
   *         forward        [0]    Certificate OPTIONAL,
   *         reverse        [1]    Certificate OPTIONAL,
   *         -- at least one of the pair shall be present -- }
   * </pre>
   *
   * @param seq The ASN.1 sequence.
   */
  private CertificatePair(ASN1Sequence seq) {
    if (seq.size() != 1 && seq.size() != 2) {
      throw new IllegalArgumentException("Bad sequence size: " + seq.size());
    }

    Enumeration e = seq.getObjects();

    while (e.hasMoreElements()) {
      ASN1TaggedObject o = ASN1TaggedObject.getInstance(e.nextElement());
      if (o.getTagNo() == 0) {
        forward = X509CertificateStructure.getInstance(o, true);
      } else if (o.getTagNo() == 1) {
        reverse = X509CertificateStructure.getInstance(o, true);
      } else {
        throw new IllegalArgumentException("Bad tag number: " + o.getTagNo());
      }
    }
  }
  /**
   * Constructor that builds an instance of <code>RoleSyntax</code> by extracting the encoded
   * elements from the <code>ASN1Sequence</code> object supplied.
   *
   * @param seq an instance of <code>ASN1Sequence</code> that holds the encoded elements used to
   *     build this <code>RoleSyntax</code>.
   */
  public RoleSyntax(ASN1Sequence seq) {
    if (seq.size() < 1 || seq.size() > 2) {
      throw new IllegalArgumentException("Bad sequence size: " + seq.size());
    }

    for (int i = 0; i != seq.size(); i++) {
      ASN1TaggedObject taggedObject = ASN1TaggedObject.getInstance(seq.getObjectAt(i));
      switch (taggedObject.getTagNo()) {
        case 0:
          roleAuthority = GeneralNames.getInstance(taggedObject, false);
          break;
        case 1:
          roleName = GeneralName.getInstance(taggedObject, false);
          break;
        default:
          throw new IllegalArgumentException("Unknown tag in RoleSyntax");
      }
    }
  }