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); } }
private static Asn1Node ReadUniversalNode(Asn1UniversalNodeType type, Asn1TagForm tagForm, Stream stream) { switch (type) { case Asn1UniversalNodeType.Boolean: return(Asn1Boolean.ReadFrom(stream)); case Asn1UniversalNodeType.Integer: return(Asn1Integer.ReadFrom(stream)); case Asn1UniversalNodeType.BitString: return(Asn1BitString.ReadFrom(stream)); case Asn1UniversalNodeType.OctetString: return(Asn1OctetString.ReadFrom(stream)); case Asn1UniversalNodeType.Null: return(Asn1Null.ReadFrom(stream)); case Asn1UniversalNodeType.ObjectId: return(Asn1ObjectIdentifier.ReadFrom(stream)); case Asn1UniversalNodeType.Utf8String: return(Asn1Utf8String.ReadFrom(stream)); case Asn1UniversalNodeType.PrintableString: return(Asn1PrintableString.ReadFrom(stream)); case Asn1UniversalNodeType.UtcTime: return(Asn1UtcTime.ReadFrom(stream)); case Asn1UniversalNodeType.Sequence: return(Asn1Sequence.ReadFrom(stream)); case Asn1UniversalNodeType.Set: return(Asn1Set.ReadFrom(stream)); default: throw new NotSupportedException($"unsupported universal type {type}"); } }
public new static Asn1Integer Parse(XElement xNode) { var vals = new List <byte>(); var val = xNode.Value.Trim(); for (var i = 0; i < val.Length; i += 2) { var b = val.Substring(i, 2); var bi = byte.Parse(b, NumberStyles.HexNumber); vals.Add(bi); } var res = new Asn1Integer(vals.ToArray()); return(res); }