Example #1
0
        public static Asn1Set GetInstance(Asn1TaggedObject obj, bool explicitly)
        {
            Asn1Object @object = obj.GetObject();

            if (explicitly)
            {
                if (!obj.IsExplicit())
                {
                    throw new ArgumentException("object implicit - explicit expected.");
                }
                return((Asn1Set)@object);
            }
            if (obj.IsExplicit())
            {
                return(new DerSet(@object));
            }
            if (@object is Asn1Set)
            {
                return((Asn1Set)@object);
            }
            if (@object is Asn1Sequence)
            {
                Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector();
                Asn1Sequence        asn1Sequence        = (Asn1Sequence)@object;
                foreach (Asn1Encodable item in asn1Sequence)
                {
                    asn1EncodableVector.Add(item);
                }
                return(new DerSet(asn1EncodableVector, needsSorting: false));
            }
            throw new ArgumentException("Unknown object in GetInstance: " + obj.GetType().FullName, "obj");
        }
Example #2
0
        public static Asn1Sequence GetInstance(Asn1TaggedObject obj, bool explicitly)
        {
            Asn1Object @object = obj.GetObject();

            if (explicitly)
            {
                if (!obj.IsExplicit())
                {
                    throw new ArgumentException("object implicit - explicit expected.");
                }
                return((Asn1Sequence)@object);
            }
            else if (obj.IsExplicit())
            {
                if (obj is BerTaggedObject)
                {
                    return(new BerSequence(@object));
                }
                return(new DerSequence(@object));
            }
            else
            {
                if (@object is Asn1Sequence)
                {
                    return((Asn1Sequence)@object);
                }
                throw new ArgumentException("Unknown object in GetInstance: " + obj.GetType().FullName, "obj");
            }
        }
Example #3
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 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 explicitly true if the object is meant to be explicitly tagged
         *          false otherwise.
         * @exception ArgumentException if the tagged object cannot
         *          be converted.
         */
        public static Asn1Set GetInstance(
            Asn1TaggedObject obj,
            bool explicitly)
        {
            Asn1Object inner = obj.GetObject();

            if (explicitly)
            {
                if (!obj.IsExplicit())
                {
                    throw new ArgumentException("object implicit - explicit expected.");
                }

                return((Asn1Set)inner);
            }

            //
            // constructed object which appears to be explicitly tagged
            // and it's really implicit means we have to add the
            // surrounding sequence.
            //
            if (obj.IsExplicit())
            {
                return(new DerSet(inner));
            }

            if (inner is Asn1Set)
            {
                return((Asn1Set)inner);
            }

            //
            // in this case the parser returns a sequence, convert it
            // into a set.
            //
            if (inner is Asn1Sequence)
            {
                Asn1EncodableVector v = new Asn1EncodableVector();
                Asn1Sequence        s = (Asn1Sequence)inner;

                foreach (Asn1Encodable ae in s)
                {
                    v.Add(ae);
                }

                // TODO Should be able to construct set directly from sequence?
                return(new DerSet(v, false));
            }

            throw new ArgumentException("Unknown object in GetInstance: " + obj.GetType().FullName, "obj");
        }
Example #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 implicitly 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 explicitly true if the object is meant to be explicitly tagged,
         *          false otherwise.
         * @exception ArgumentException if the tagged object cannot
         *          be converted.
         */
        public static Asn1Sequence GetInstance(
            Asn1TaggedObject obj,
            bool explicitly)
        {
            Asn1Object inner = obj.GetObject();

            if (explicitly)
            {
                if (!obj.IsExplicit())
                {
                    throw new ArgumentException("object implicit - explicit expected.");
                }

                return((Asn1Sequence)inner);
            }

            //
            // 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(inner));
                }

                return(new DerSequence(inner));
            }

            if (inner is Asn1Sequence)
            {
                return((Asn1Sequence)inner);
            }

            throw new ArgumentException("Unknown object in GetInstance: " + obj.GetType().FullName, "obj");
        }
Example #5
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 implicitly 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 explicitly true if the object is meant to be explicitly tagged,
         *          false otherwise.
         * @exception ArgumentException if the tagged object cannot
         *          be converted.
         */
        public static Asn1Sequence GetInstance(
            Asn1TaggedObject	obj,
            bool				explicitly)
        {
			Asn1Object inner = obj.GetObject();

			if (explicitly)
            {
                if (!obj.IsExplicit())
                    throw new ArgumentException("object implicit - explicit expected.");

				return (Asn1Sequence) inner;
            }

			//
            // 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(inner);
                }

				return new DerSequence(inner);
            }

			if (inner is Asn1Sequence)
            {
                return (Asn1Sequence) inner;
            }

			throw new ArgumentException("Unknown object in GetInstance: " + obj.GetType().FullName, "obj");
		}
Example #6
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 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 explicitly true if the object is meant to be explicitly tagged
         *          false otherwise.
         * @exception ArgumentException if the tagged object cannot
         *          be converted.
         */
        public static Asn1Set GetInstance(
            Asn1TaggedObject	obj,
            bool				explicitly)
        {
			Asn1Object inner = obj.GetObject();

			if (explicitly)
            {
                if (!obj.IsExplicit())
                    throw new ArgumentException("object implicit - explicit expected.");

				return (Asn1Set) inner;
            }

			//
            // constructed object which appears to be explicitly tagged
            // and it's really implicit means we have to add the
            // surrounding sequence.
            //
            if (obj.IsExplicit())
            {
                return new DerSet(inner);
            }

			if (inner is Asn1Set)
            {
                return (Asn1Set) inner;
            }

            //
            // in this case the parser returns a sequence, convert it
            // into a set.
            //
			if (inner is Asn1Sequence)
            {
				Asn1EncodableVector v = new Asn1EncodableVector();
				Asn1Sequence s = (Asn1Sequence) inner;

				foreach (Asn1Encodable ae in s)
				{
                    v.Add(ae);
                }

				// TODO Should be able to construct set directly from sequence?
				return new DerSet(v, false);
            }

			throw new ArgumentException("Unknown object in GetInstance: " + obj.GetType().FullName, "obj");
		}