public Asn1UtcTime(Asn1Document document, TaggedObject content, Asn1Object parentObject) : base(document, content, parentObject) { var ascii = Encoding.ASCII.GetString(content.Workload); dateTime = DateTime.ParseExact(ascii, UtcFormats, CultureInfo.InvariantCulture, DateTimeStyles.None); }
public Asn1Object CreateAsn1Object( Asn1Document document, TaggedObject content, Asn1Object parent) { Asn1Object result = null; try { if (document.ShowInvalidTaggedObjects && IsInvalidTaggedObject(content)) return new Asn1InvalidObject(document, (InvalidTaggedObject)content, parent); var tagValue = content.Tag.Value; if (!tagValue.IsUniversalClass()) { var specific = CreateSpecificTaggedObject(document, content, parent); return specific ?? CreateUnsupportedTaggedObject(document, content, parent); } var asn1TagValue = tagValue.GetAsn1TagValue(); switch (asn1TagValue) { case (int)Asn1Tags.Boolean: return new Asn1Boolean(document, content, parent); case (int)Asn1Tags.Integer: return new Asn1Integer(document, content, parent); case (int)Asn1Tags.BitString: return new Asn1BitString(document, content, parent); case (int)Asn1Tags.OctetString: return new Asn1OctetString(document, content, parent); case (int)Asn1Tags.Null: return new Asn1Null(document, content, parent); case (int)Asn1Tags.ObjectIdentifier: return new Asn1Oid(document, content, parent); case (int)Asn1Tags.Utf8String: return new Asn1Utf8String(document, content, parent); case (int)Asn1Tags.Sequence: return new Asn1Sequence(document, content, parent); case (int)Asn1Tags.Set: return new Asn1Set(document, content, parent); case (int)Asn1Tags.NumericString: return new Asn1NumericString(document, content, parent); case (int)Asn1Tags.PrintableString: return new Asn1PrintableString(document, content, parent); case (int)Asn1Tags.UtcTime: return new Asn1UtcTime(document, content, parent); default: var specific = CreateSpecificTaggedObject(document, content, parent); return specific ?? CreateUnsupportedTaggedObject(document, content, parent); } } catch (Exception ex) { // Could not create a "real" ASN1 object --> return the special "Unsupported" object. log.Error(ex); result = CreateUnsupportedTaggedObject(document, content, parent, ex); } return result; }
internal Asn1Object(Asn1Document document, TaggedObject content, Asn1Object parentObject) { if (content == null) throw new ArgumentNullException("content"); TaggedObject = content; Document = document; Parent = parentObject; }
private Asn1Object CreateUnsupportedTaggedObject(Asn1Document document, TaggedObject content, Asn1Object parent, Exception exception = null) { if (exception != null) return new Asn1Unsupported(document, content, parent, exception); var tagValue = content.Tag.Value; if (tagValue.IsContextSpecificClass()) return new Asn1ContextSpecific(document, content, parent); return new Asn1Unsupported(document, content, parent); }
public Asn1Integer(Asn1Document document, TaggedObject content, Asn1Object parentObject) : base(document, content, parentObject) { long value = 0L; foreach (byte element in content.Workload) { value <<= 8; value += element; } Value = value; }
protected override Asn1Object CreateSpecificTaggedObject(Asn1Document document, TaggedObject content, Asn1Object parent) { var result = base.CreateSpecificTaggedObject(document, content, parent); if (result != null) return result; var tag = content.Tag.Value; if (tag == (ushort)Tags.Icao.Mrz) return new Asn1Mrz(document, content, parent); return null; }
protected override Asn1Object CreateSpecificTaggedObject(Asn1Document document, TaggedObject content, Asn1Object parent) { var asn1 = base.CreateSpecificTaggedObject(document, content, parent); if (asn1 != null) return asn1; var tagValue = content.Tag.Value; var ef = Tags.FindEF(tagValue); if (!ef.HasValue) return null; switch (ef.Value) { case Tags.EF.DG1: return new Asn1DG1Data(document, content, parent); } return null; }
protected virtual void ParseContent() { var taggedObjects = TaggedObject.CreateObjects( base.TaggedObject.AllData, base.TaggedObject.WorkloadOffset, base.TaggedObject.WorkloadLength); if (taggedObjects != null && taggedObjects.Length > 0) { var objects = new List<Asn1Object>(); foreach (var taggedObject in taggedObjects) { var asn1 = ObjectFactory.CreateAsn1Object(base.Document, taggedObject, this); if (asn1 != null) objects.Add(asn1); } Nodes = objects.ToArray(); } else Nodes = new Asn1Object[0]; }
private int GetImageIndex(Asn1Object asn) { // TODO: support icon sets by theme if (asn == null) return emptyImageIndex; if (asn is Asn1InvalidObject) return invalidImageIndex; if (asn is Asn1Sequence) return sequenceImageIndex; if (asn is Asn1Set) return setImageIndex; if (asn is Asn1Oid) return oidImageIndex; if (asn is Asn1Integer) return integerImageIndex; if (asn is Asn1BitString) return stringImageIndex; if (asn is Asn1Utf8String) return stringImageIndex; if (asn is Asn1NumericString) return stringImageIndex; if (asn is Asn1OctetString) return stringImageIndex; if (asn is Asn1UtcTime) return stringImageIndex; if (asn is Asn1Unsupported) return unknownImageIndex; if (asn is Asn1ContextSpecific) return contextSpecificImageIndex; if (asn is Asn1Boolean) return booleanImageIndex; return emptyImageIndex; }
private void AddAsnNode(Asn1Object asn, TreeNodeEx parent) { var nodeAsText = asn.ToString(); if ((asn is Asn1OctetString || asn is Asn1BitString) && nodeAsText.Length > 40) nodeAsText = nodeAsText.Substring(0, 40) + "..."; var treeNode = new TreeNodeEx(nodeAsText); var imageIndex = GetImageIndex(asn); treeNode.SelectedImageIndex = imageIndex; treeNode.ImageIndex = imageIndex; var asnt = asn as Asn1StructuredObject; if (asnt != null) { foreach (var asn2 in asnt.Nodes) AddAsnNode(asn2, treeNode); } treeNode.Tag = asn; parent.Nodes.Add(treeNode); }
protected Asn1Document( byte[] data, bool parseOctetStrings, bool showInvalidTaggedObjects, Asn1ObjectFactory objectFactory) { Data = data; ParseOctetStrings = parseOctetStrings; ShowInvalidTaggedObjects = showInvalidTaggedObjects; ObjectFactory = objectFactory ?? new Asn1ObjectFactory(); var taggedObjects = CreateTaggedObjects(data); if (taggedObjects != null && taggedObjects.Length > 0) { var objects = new List<Asn1Object>(); foreach (var taggedObject in taggedObjects) { var asn1 = ObjectFactory.CreateAsn1Object(this, taggedObject, null); if (asn1 != null) objects.Add(asn1); } Nodes = objects.ToArray(); } else Nodes = new Asn1Object[0]; }
public Asn1Oid(Asn1Document document, TaggedObject content, Asn1Object parentObject) : base(document, content, parentObject) { oid = OidUtils.Decode(content.Workload); }
internal Asn1InvalidObject( Asn1Document document, InvalidTaggedObject content, Asn1Object parentObject) : base(document, content, parentObject) { InvalidTaggedObject = content; }
public Asn1BitString(Asn1Document document, TaggedObject content, Asn1Object parentObject) : base(document, content, parentObject) { unusedBytes = content.Workload[0]; bitString = content.Workload.Skip(1).ToArray(); }
internal Asn1ContextSpecific(Asn1Document document, TaggedObject content, Asn1Object parentObject) : base(document, content, parentObject) { }
public Asn1BitString(Asn1Document document, TaggedObject content, Asn1Object parentObject) : base(document, content, parentObject) { unusedBytes = content.Workload[0]; bitString = content.Workload.Skip(1).ToArray(); }
public Asn1StructuredObject(Asn1Document document, TaggedObject content, Asn1Object parentObject) : base(document, content, parentObject) { ParseContent(); }
public Asn1Set(Asn1Document document, TaggedObject content, Asn1Object parentObject) : base(document, content, parentObject) { }
public Asn1Boolean(Asn1Document document, TaggedObject content, Asn1Object parentObject) : base(document, content, parentObject) { boolean = content.Workload[0] == 0xFF; }
public Asn1Null(Asn1Document document, TaggedObject content, Asn1Object parentObject) : base(document, content, parentObject) { warning = content.WorkloadLength != 0; }
internal Asn1InvalidObject( Asn1Document document, InvalidTaggedObject content, Asn1Object parentObject) : base(document, content, parentObject) { InvalidTaggedObject = content; }
public Asn1NumericString(Asn1Document document, TaggedObject content, Asn1Object parentObject) : base(document, content, parentObject) { }
public Asn1Object CreateAsn1Object(Asn1Document document, TaggedObject content, Asn1Object parent) { return ObjectFactory.CreateAsn1Object(document, content, parent); }
public Asn1PrintableString(Asn1Document document, TaggedObject content, Asn1Object parentObject) : base(document, content, parentObject) { }
public Asn1Utf8String(Asn1Document document, TaggedObject content, Asn1Object parentObject) : base(document, content, parentObject) { utf8 = Encoding.UTF8.GetString(content.Workload); }
public Asn1DG1Data(Asn1Document document, TaggedObject content, Asn1Object parentObject) : base(document, content, parentObject) { }
protected virtual Asn1Object CreateSpecificTaggedObject(Asn1Document document, TaggedObject content, Asn1Object parent) { return null; }
public Asn1NumericString(Asn1Document document, TaggedObject content, Asn1Object parentObject) : base(document, content, parentObject) { }
public Asn1PrintableString(Asn1Document document, TaggedObject content, Asn1Object parentObject) : base(document, content, parentObject) { }