Beispiel #1
0
        public override bool Equals(
            object o)
        {
            if (o == null || !(o is ASN1TaggedObject))
            {
                return(false);
            }

            ASN1TaggedObject other = (ASN1TaggedObject)o;

            if (tagNo != other.tagNo || empty != other.empty || explicitly != other.explicitly)
            {
                return(false);
            }

            if (obj == null)
            {
                if (other.obj != null)
                {
                    return(false);
                }
            }
            else
            {
                if (!(obj.Equals(other.obj)))
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #2
0
        /**
         * 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 implictly 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,
            bool explicitly)
        {
            if (explicitly)
            {
                if (!obj.isExplicit())
                {
                    throw new ArgumentException("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() is 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() is ASN1Sequence)
                    {
                        ASN1Sequence s = (ASN1Sequence)obj.getObject();
                        IEnumerator  e = s.getObjects();

                        while (e.MoveNext())
                        {
                            v.add((ASN1Encodable)e.Current);
                        }

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

            throw new ArgumentException(
                      "unknown object in getInstanceFromTagged");
        }
Beispiel #3
0
        static public ASN1TaggedObject getInstance(
            ASN1TaggedObject obj,
            bool explicitly)
        {
            if (explicitly)
            {
                return((ASN1TaggedObject)obj.getObject());
            }

            throw new ArgumentException("implicitly tagged tagged object");
        }
Beispiel #4
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,
            bool explicitly)
        {
            if (explicitly)
            {
                if (!obj.isExplicit())
                {
                    throw new ArgumentException("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 is BERTaggedObject)
                    {
                        return(new BERSequence(obj.getObject()));
                    }
                    else
                    {
                        return(new DERSequence(obj.getObject()));
                    }
                }
                else
                {
                    if (obj.getObject() is ASN1Sequence)
                    {
                        return((ASN1Sequence)obj.getObject());
                    }
                }
            }

            throw new ArgumentException(
                      "unknown object in getInstanceFromTagged");
        }
Beispiel #5
0
 /**
  * return an T61 string from a tagged object.
  *
  * @param obj the tagged object holding the object we want
  * @param explicitly true if the object is meant to be explicitly
  *              tagged false otherwise.
  * @exception IllegalArgumentException if the tagged object cannot
  *               be converted.
  */
 public static DERT61String getInstance(
     ASN1TaggedObject obj,
     bool explicitly)
 {
     return(getInstance(obj.getObject()));
 }
Beispiel #6
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 DERBoolean getInstance(
     ASN1TaggedObject obj,
     bool isExplicit)
 {
     return(getInstance(obj.getObject()));
 }
Beispiel #7
0
 /**
  * return an object Identifier from a tagged object.
  *
  * @param obj the tagged object holding the object we want
  * @param explicitly 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,
     bool explicitly)
 {
     return(getInstance(obj.getObject()));
 }
Beispiel #8
0
 /**
  * return an Enumerated from a tagged object.
  *
  * @param obj the tagged object holding the object we want
  * @param explicitly true if the object is meant to be explicitly
  *              tagged false otherwise.
  * @exception IllegalArgumentException if the tagged object cannot
  *               be converted.
  */
 public static DEREnumerated getInstance(
     ASN1TaggedObject obj,
     bool explicitly)
 {
     return(getInstance(obj.getObject()));
 }
Beispiel #9
0
 /**
  * return a Generalized Time object from a tagged object.
  *
  * @param obj the tagged object holding the object we want
  * @param explicitly 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,
     bool explicitly)
 {
     return(getInstance(obj.getObject()));
 }