예제 #1
0
        public static Asn1Node Parse(XElement xNode)
        {
            switch (xNode.Name.LocalName)
            {
            case Asn1Sequence.NODE_NAME:
                return(Asn1Sequence.Parse(xNode));

            case Asn1Set.NODE_NAME:
                return(Asn1Set.Parse(xNode));

            case Asn1Integer.NODE_NAME:
                return(Asn1Integer.Parse(xNode));

            case Asn1ObjectIdentifier.NODE_NAME: return(Asn1ObjectIdentifier.Parse(xNode));

            case Asn1PrintableString.NODE_NAME:
                return(Asn1PrintableString.Parse(xNode));

            case Asn1Utf8String.NODE_NAME:
                return(Asn1Utf8String.Parse(xNode));

            case Asn1Null.NODE_NAME:
                return(Asn1Null.Parse(xNode));

            case Asn1BitString.NODE_NAME:
                return(Asn1BitString.Parse(xNode));

            case Asn1CustomNode.NODE_NAME:
                return(Asn1CustomNode.Parse(xNode));

            default:
                throw new Exception("Invalid Node " + xNode.Name.LocalName);
            }
        }
예제 #2
0
        public new static Asn1CustomNode Parse(XElement xNode)
        {
            var type     = int.Parse(xNode.Attribute("type").Value);
            var form     = (Asn1TagForm)Enum.Parse(typeof(Asn1TagForm), xNode.Attribute("form").Value);
            var tagClass = (Asn1TagClass)Enum.Parse(typeof(Asn1TagClass), xNode.Attribute("class").Value);
            var res      = new Asn1CustomNode(type, form)
            {
                TagClass = tagClass
            };

            res.Data = ReadDataFromHexString(xNode.Value);
            return(res);
        }
예제 #3
0
        public static Asn1CustomNode ReadFrom(Asn1UniversalNodeType type, Asn1TagForm tagForm, Stream stream)
        {
            if (tagForm == Asn1TagForm.Primitive)
            {
                var data = new byte[stream.Length];
                stream.Read(data, 0, data.Length);

                return(new Asn1CustomNode((int)type, tagForm)
                {
                    Data = data
                });
            }
            else
            {
                var res = new Asn1CustomNode((int)type, tagForm);
                res.ReadChildren(stream);
                return(res);
            }
        }
예제 #4
0
        public static Asn1Node ReadNode(Stream stream)
        {
            var identifier = stream.ReadByte();
            var type       = (Asn1UniversalNodeType)(identifier & 0x1f);
            var tagClass   = (Asn1TagClass)(identifier >> 6);
            var tagForm    = (Asn1TagForm)((identifier >> 5) & 1);
            var length     = ReadTagLength(stream);
            var data       = new byte[length];

            stream.Read(data, 0, length);
            stream = new MemoryStream(data);
            if (tagClass == Asn1TagClass.Universal)
            {
                var tag = ReadUniversalNode(type, tagForm, stream);
                tag.TagClass = tagClass;
                return(tag);
            }
            else
            {
                var tag = Asn1CustomNode.ReadFrom(type, tagForm, stream);
                tag.TagClass = tagClass;
                return(tag);
            }
        }