Esempio n. 1
0
  /**
   * return an Integer from a tagged object.
   *
   * @param obj the tagged object holding the object we want
   * @param explicit true if the object is meant to be explicitly tagged false otherwise.
   * @throws IllegalArgumentException if the tagged object cannot be converted.
   * @return an ASN1Integer instance.
   */
  public static ASN1Integer getInstance(ASN1TaggedObject obj, boolean explicit) {
    ASN1Primitive o = obj.getObject();

    if (explicit || (o instanceof ASN1Integer)) {
      return getInstance(o);
    } else {
      return new ASN1Integer(ASN1OctetString.getInstance(obj.getObject()).getOctets());
    }
  }
Esempio n. 2
0
  /**
   * return an Integer from a tagged object.
   *
   * @param obj the tagged object holding the object we want
   * @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 DERInteger getInstance(ASN1TaggedObject obj, boolean explicit) {
    DERObject o = obj.getObject();

    if (explicit || o instanceof DERInteger) {
      return getInstance(o);
    } else {
      return new ASN1Integer(ASN1OctetString.getInstance(obj.getObject()).getOctets());
    }
  }
Esempio n. 3
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()) {
        if (obj instanceof BERTaggedObject) {
          return new BERSequence(obj.getObject());
        } else {
          return new DERSequence(obj.getObject());
        }
      } else {
        if (obj.getObject() instanceof ASN1Sequence) {
          return (ASN1Sequence) obj.getObject();
        }
      }
    }

    throw new IllegalArgumentException("unknown object in getInstanceFromTagged");
  }
  public static DERGeneralString getInstance(ASN1TaggedObject obj, boolean explicit) {
    ASN1Primitive o = obj.getObject();

    if (explicit || o instanceof DERGeneralString) {
      return getInstance(o);
    } else {
      return new DERGeneralString(((ASN1OctetString) o).getOctets());
    }
  }
Esempio n. 5
0
  /**
   * return a Boolean from a tagged object.
   *
   * @param obj the tagged object holding the object we want
   * @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 ASN1Boolean getInstance(ASN1TaggedObject obj, boolean explicit) {
    ASN1Primitive o = obj.getObject();

    if (explicit || o instanceof ASN1Boolean) {
      return getInstance(o);
    } else {
      return ASN1Boolean.fromOctetString(((ASN1OctetString) o).getOctets());
    }
  }
Esempio n. 6
0
  public CrlID(ASN1Sequence seq) {
    Enumeration e = seq.getObjects();

    while (e.hasMoreElements()) {
      ASN1TaggedObject o = (ASN1TaggedObject) e.nextElement();

      switch (o.getTagNo()) {
        case 0:
          crlUrl = DERIA5String.getInstance(o, true);
          break;
        case 1:
          crlNum = DERInteger.getInstance(o, true);
          break;
        case 2:
          crlTime = DERGeneralizedTime.getInstance(o, true);
          break;
        default:
          throw new IllegalArgumentException("unknown tag number: " + o.getTagNo());
      }
    }
  }
  /**
   * Return an ASN1 set 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 implicitly tagged in the
   * normal course of events it indicates that we lost the surrounding set - 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 sets 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 ASN1Set getInstance(ASN1TaggedObject obj, boolean explicit) {
    if (explicit) {
      if (!obj.isExplicit()) {
        throw new IllegalArgumentException("object implicit - explicit expected.");
      }

      return (ASN1Set) obj.getObject();
    } else {
      //
      // constructed object which appears to be explicitly tagged
      // and it's really implicit means we have to add the
      // surrounding sequence.
      //
      if (obj.isExplicit()) {
        ASN1Set set = new DERSet(obj.getObject());

        return set;
      } else {
        if (obj.getObject() instanceof ASN1Set) {
          return (ASN1Set) obj.getObject();
        }

        //
        // in this case the parser returns a sequence, convert it
        // into a set.
        //
        ASN1EncodableVector v = new ASN1EncodableVector();

        if (obj.getObject() instanceof ASN1Sequence) {
          ASN1Sequence s = (ASN1Sequence) obj.getObject();
          Enumeration e = s.getObjects();

          while (e.hasMoreElements()) {
            v.add((DEREncodable) e.nextElement());
          }

          return new DERSet(v, false);
        }
      }
    }

    throw new IllegalArgumentException(
        "unknown object in getInstance: " + obj.getClass().getName());
  }
 /**
  * return a Generalized Time object from a tagged object.
  *
  * @param obj the tagged object holding the object we want
  * @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 DERGeneralizedTime getInstance(ASN1TaggedObject obj, boolean explicit) {
   return getInstance(obj.getObject());
 }
 /**
  * return a BMP String from a tagged object.
  *
  * @param obj the tagged object holding the object we want
  * @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 DERBMPString getInstance(ASN1TaggedObject obj, boolean explicit) {
   return getInstance(obj.getObject());
 }
 /**
  * return an Object Identifier from a tagged object.
  *
  * @param obj the tagged object holding the object we want
  * @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 DERObjectIdentifier getInstance(ASN1TaggedObject obj, boolean explicit) {
   return getInstance(obj.getObject());
 }