Exemple #1
0
        /// <summary> Decode an LBER encoded value into an Asn1Object from an InputStream.
        ///
        ///  This method also returns the total length of this encoded
        /// Asn1Object (length of type + length of length + length of content)
        /// in the parameter len. This information is helpful when decoding
        /// structured types.
        /// </summary>
        public virtual Asn1Object decode(System.IO.Stream in_Renamed, int[] len)
        {
            asn1ID.reset(in_Renamed);
            asn1Len.reset(in_Renamed);

            int length = asn1Len.Length;

            len[0] = asn1ID.EncodedLength + asn1Len.EncodedLength + length;

            if (asn1ID.Universal)
            {
                switch (asn1ID.Tag)
                {
                case Asn1Sequence.TAG:
                    return(new Asn1Sequence(this, in_Renamed, length));

                case Asn1Set.TAG:
                    return(new Asn1Set(this, in_Renamed, length));

                case Asn1Boolean.TAG:
                    return(new Asn1Boolean(this, in_Renamed, length));

                case Asn1Integer.TAG:
                    return(new Asn1Integer(this, in_Renamed, length));

                case Asn1OctetString.TAG:
                    return(new Asn1OctetString(this, in_Renamed, length));

                case Asn1Enumerated.TAG:
                    return(new Asn1Enumerated(this, in_Renamed, length));

                case Asn1Null.TAG:
                    return(new Asn1Null());                            // has no content to decode.

                /* Asn1 TYPE NOT YET SUPPORTED
                 * case Asn1BitString.TAG:
                 * return new Asn1BitString(this, in, length);
                 * case Asn1ObjectIdentifier.TAG:
                 * return new Asn1ObjectIdentifier(this, in, length);
                 * case Asn1Real.TAG:
                 * return new Asn1Real(this, in, length);
                 * case Asn1NumericString.TAG:
                 * return new Asn1NumericString(this, in, length);
                 * case Asn1PrintableString.TAG:
                 * return new Asn1PrintableString(this, in, length);
                 * case Asn1TeletexString.TAG:
                 * return new Asn1TeletexString(this, in, length);
                 * case Asn1VideotexString.TAG:
                 * return new Asn1VideotexString(this, in, length);
                 * case Asn1IA5String.TAG:
                 * return new Asn1IA5String(this, in, length);
                 * case Asn1GraphicString.TAG:
                 * return new Asn1GraphicString(this, in, length);
                 * case Asn1VisibleString.TAG:
                 * return new Asn1VisibleString(this, in, length);
                 * case Asn1GeneralString.TAG:
                 * return new Asn1GeneralString(this, in, length);
                 */


                default:
                    throw new System.IO.EndOfStreamException("Unknown tag");                             // !!! need a better exception
                }
            }
            else
            {
                // APPLICATION or CONTEXT-SPECIFIC tag
                return(new Asn1Tagged(this, in_Renamed, length, (Asn1Identifier)asn1ID.Clone()));
            }
        }