Package codec.asn1

Examples of codec.asn1.ASN1Sequence


    public Name(String rfc2253String, int encType) throws BadNameException {
  super(8);

  ASN1ObjectIdentifier oid;
  RFC2253Parser p;
  ASN1Sequence seq;
  Iterator i;
  ASN1Set set;
  String key;
  String val;
  AVA entry;

  initMaps();

  if (encType == -1) {
      if (!allowDefaultEncoding_) {
    throw new BadNameException(
      "Use the other constructor with the explicit "
        + "encoding parameter!");
      }
      currentEncoding_ = defaultEncoding_;
  } else {
      if (encType != UTF8_ENCODING && encType != T61_ENCODING
        && encType != PRINTABLE_ENCODING && encType != IA5_ENCODING) {
    throw new BadNameException("Unknown EncodingType: " + encType);
      }
      currentEncoding_ = encType;
  }

  p = new RFC2253Parser();
  set = new ASN1Set(1);

  for (i = p.parse(rfc2253String).iterator(); i.hasNext();) {
      entry = (AVA) i.next();
      key = entry.getKey();
      key = key.toUpperCase();
      oid = (ASN1ObjectIdentifier) a2oid_.get(key);
      seq = new ASN1Sequence(2);

      if (oid == null) {
    try {
        oid = new ASN1ObjectIdentifier(key);
    } catch (Exception e) {
        throw new BadNameException("Unsupported attribute key: \""
          + key + "\"");
    }
      }
      seq.add(oid.clone());

      if (entry.isEncodedValue()) {
    ByteArrayInputStream in;
    BERDecoder dec;
    ASN1Type obj;
    byte[] buf;

    try {
        buf = entry.getEncodedValue();
        in = new ByteArrayInputStream(buf);
        dec = new BERDecoder(in);
        obj = dec.readType();

        dec.close();
    } catch (Exception e) {
        throw new BadNameException(
          "Binary data is not a valid BER encoding!");
    }
    seq.add(obj);
      } else {
    val = entry.getValue();

    /*
     * This is a workaround for email addresses which contain the
     * '@' symbol. This symbol is not in the character set of the
     * ASN.1 PrintableString. Hence, we have to take a IA5String
     * instead.
     */
    if (entry.getKey().equalsIgnoreCase("EMAILADDRESS")
      || entry.getKey().equalsIgnoreCase("UID")) {
        seq.add(new ASN1IA5String(val));
    } else if (entry.getKey().equalsIgnoreCase("C")
      || entry.getKey().equalsIgnoreCase("SERIALNUMBER")) {
        seq.add(new ASN1PrintableString(val));
    } else {
        switch (currentEncoding_) {
        case (ASN1.TAG_UTF8STRING):
      seq.add(new ASN1UTF8String(val));
      break;
        case (ASN1.TAG_IA5STRING):
      seq.add(new ASN1IA5String(val));
      break;
        case (ASN1.TAG_PRINTABLESTRING):
      if (checkPrintableSpelling(val)) {
          seq.add(new ASN1PrintableString(val));
      } else {
          throw new BadNameException(
            "Illegal characters for PrintableString "
              + "in characters");
      }
      break;
        case (ASN1.TAG_T61STRING):
      seq.add(new ASN1T61String(val));
      break;
        }
    }
      }
      set.add(seq);
View Full Code Here


     * constructor, using the Generalname of the first Admissionauthority as
     * Parameter.
     */
    public AdmissionExtension(GeneralName adAuth) {

  admissionSyntax = new ASN1Sequence();
  admissionAuthority = adAuth;
  setCritical(false);
  try {
      setOID(new ASN1ObjectIdentifier(EXTENSION_OID));
      admissionSyntax.add(admissionAuthority);
View Full Code Here

    /**
     * constructor, using an Admission as Parameter
     */
    public AdmissionExtension(ASN1Sequence ad) {
  admissionSyntax = new ASN1Sequence();
  setCritical(false);

  admissions = ad;
  admissionSyntax.add(admissions);

View Full Code Here

     * instances. The order is the same as the order in which the
     * <code>AVA</code> instances appear in the code.
     */
    public List getAVAList() {
  ASN1ObjectIdentifier oid;
  ASN1Sequence ava;
  ArrayList list;
  ASN1Type obj;
  Iterator i;
  boolean sibling;
  ASN1Set rdn;
  String val;
  String key;
  AVA entry;
  int j;
  int n;

  list = new ArrayList(size());

  for (i = iterator(); i.hasNext();) {
      rdn = (ASN1Set) i.next();
      n = rdn.size();

      for (j = 0; j < n; j++) {
    /*
     * We have to mark siblings. An AVA has a sibling if it is not
     * the last AVA in the set.
     */
    sibling = (j < n - 1);

    /*
     * Convert key and value into strings. These values are then put
     * into an AVA instance.
     */
    ava = (ASN1Sequence) rdn.get(j);
    oid = (ASN1ObjectIdentifier) ava.get(0);
    obj = (ASN1Type) ava.get(1);
    key = (String) oid2a_.get(oid);

    if (key == null) {
        key = oid.toString();
    }
View Full Code Here

     * instances. The order is the opposite as the order in which the
     * <code>AVA</code> instances appear in the code.
     */
    public List getReverseAVAList() {
  ASN1ObjectIdentifier oid;
  ASN1Sequence ava;
  ArrayList list;
  ASN1Type obj;
  boolean sibling;
  ASN1Set rdn;
  String val;
  String key;
  AVA entry;
  int i;
  int j;
  int n;

  list = new ArrayList(size());

  for (i = size() - 1; i >= 0; i--) {
      rdn = (ASN1Set) get(i);
      n = rdn.size();

      for (j = 0; j < n; j++) {
    /*
     * We have to mark siblings. An AVA has a sibling if it is not
     * the last AVA in the set.
     */
    sibling = (j < n - 1);

    /*
     * Convert key and value into strings. These values are then put
     * into an AVA instance.
     */
    ava = (ASN1Sequence) rdn.get(j);
    oid = (ASN1ObjectIdentifier) ava.get(0);
    obj = (ASN1Type) ava.get(1);
    key = (String) oid2a_.get(oid);

    if (key == null) {
        key = oid.toString();
    }
View Full Code Here

      throw new NullPointerException("caller");
  }
  if (tmp_ == null) {
      tmp_ = new ArrayList(8);
  }
  ASN1Sequence seq;

  seq = new ASN1Sequence(2);

  seq.add(new ASN1ObjectIdentifier());
  seq.add(new ASN1OpenType());
  tmp_.add(seq);

  return seq;
    }
View Full Code Here

    public void decode(Decoder dec) throws ASN1Exception, IOException {
  clear();

  super.decode(dec);

  ASN1Sequence seq;
  ASN1OpenType t;
  Iterator i;
  Object o;

  for (i = tmp_.iterator(); i.hasNext();) {
      seq = (ASN1Sequence) i.next();
      t = (ASN1OpenType) seq.get(1);
      o = t.getInnerType();

      seq.set(1, o);
  }
  /*
   * We don't need the temporary list anymore.
   */
  tmp_ = null;
View Full Code Here

     *         collections.
     * @throws IllegalArgumentException
     *                 if the given object is not a valid RDN.
     */
    public boolean add(ASN1Set o) {
  ASN1Sequence seq;
  Iterator it;
  // Iterator j;
  ASN1Set set;
  Object p;

  if (o == null) {
      throw new NullPointerException("parameter is null");
  }
  set = o;

  for (it = set.iterator(); it.hasNext();) {
      p = it.next();

      if (!(p instanceof ASN1Sequence)) {
    throw new IllegalArgumentException("not a sequence: "
      + p.getClass().getName());
      }
      seq = (ASN1Sequence) p;

      if (seq.size() != 2) {
    throw new IllegalArgumentException(
      "sequence does not have 2 elements: " + seq.size());
      }
      if (!(seq.get(0) instanceof ASN1ObjectIdentifier)) {
    throw new IllegalArgumentException("attribute type not an OID");
      }
      p = seq.get(1);

      if (p == null || !(p instanceof ASN1Type)) {
    throw new IllegalArgumentException(
      "illegal or no attribute value");
      }
View Full Code Here

     * @param source
     * @return the cloned Name
     * @deprecated
     */
    public static Name clone(Name source) throws IllegalArgumentException {
  ASN1Sequence seq;
  Vector sets;
  Name result;

  result = null;

  if (source == null || source.getName().length() == 0) {
      throw new IllegalArgumentException(
        "Name/Principal must not be null nor empty !");
  }
  seq = source;
  sets = new Vector();

  for (int i = 0; i < seq.size(); i++) {
      sets.add(seq.get(i));
  }
  result = new Name();

  for (int j = 0; j < sets.size(); j++) {
      result.add((ASN1Set) sets.elementAt(j));
View Full Code Here

  // info_ = new ASN1OpenType();
  info_ = new codec.asn1.ASN1Null();
  info_.setOptional(true);

  validityModelSyntax = new ASN1Sequence();
  validityModelSyntax.add(oid_);
  validityModelSyntax.add(info_);

  setValue(validityModelSyntax);
    }
View Full Code Here

TOP

Related Classes of codec.asn1.ASN1Sequence

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.