Ejemplo n.º 1
0
        public List <object> ReadConstructedType(int length)
        {
            var  values      = new List <object>();
            long endPosition = Position + length;

            while (Position < endPosition)
            {
                Asn1Type type = ReadType();
                if (type.Byte == 0)
                {
                    break;
                }

                length = ReadLength();

                if (type.IsPrimitive)
                {
                    values.Add(ReadPrimiveType(type, length));
                }
                else
                {
                    values.Add(ReadConstructedType(length));
                }
            }

            return(values);
        }
Ejemplo n.º 2
0
        public string ReadOctetString()
        {
            Asn1Type type = ReadType();

            if (!type.IsPrimitive && type.Tag == Asn1Tag.OctetString)
            {
                throw new Exception("Expected OctetString");
            }

            int length = ReadLength();

            return(ReadOctetString(length));
        }
Ejemplo n.º 3
0
        public int ReadInteger()
        {
            Asn1Type type = ReadType();

            if (!type.IsPrimitive && type.Tag == Asn1Tag.Integer)
            {
                throw new Exception("Expected integer");
            }

            int length = ReadLength();

            return(ReadInteger(length));
        }
Ejemplo n.º 4
0
        public object ReadPrimiveType(Asn1Type type, int length)
        {
            switch (type.Tag)
            {
            case Asn1Tag.Null:
                return(null);

            case Asn1Tag.Integer:
                return(ReadInteger(length));

            case Asn1Tag.OctetString:
                return(ReadOctetString(length));

            case Asn1Tag.ObjectIdentifier:
                return(ReadOID(length));

            default:
                Skip(length);
                return("NYI: " + type.Tag);
            }
        }
Ejemplo n.º 5
0
        public object ReadPrimiveType(Asn1Type type, int length)
        {
            switch (type.Tag)
            {
                case Asn1Tag.Null:
                    return null;

                case Asn1Tag.Integer:
                    return ReadInteger(length);

                case Asn1Tag.OctetString:
                    return ReadOctetString(length);

                case Asn1Tag.ObjectIdentifier:
                    return ReadOID(length);

                default:
                    Skip(length);
                    return "NYI: " + type.Tag;
            }
        }