예제 #1
0
 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;
        }
예제 #3
0
        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);
        }
예제 #5
0
            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;
            }
예제 #6
0
        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 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;
            }
예제 #8
0
 public Asn1Object CreateAsn1Object(Asn1Document document,  TaggedObject content,  Asn1Object parent)
 {
     return ObjectFactory.CreateAsn1Object(document, content, parent);
 }
 public Asn1NumericString(Asn1Document document, TaggedObject content, Asn1Object parentObject)
     : base(document, content, parentObject)
 {
 }
예제 #10
0
 public Asn1Oid(Asn1Document document, TaggedObject content, Asn1Object parentObject)
     : base(document, content, parentObject)
 {
     oid = OidUtils.Decode(content.Workload);
 }
 public Asn1StructuredObject(Asn1Document document, TaggedObject content, Asn1Object parentObject)
     : base(document, content, parentObject)
 {
     ParseContent();
 }
 internal Asn1ContextSpecific(Asn1Document document, TaggedObject content, Asn1Object parentObject)
     : base(document, content, parentObject) { }
예제 #13
0
 public Asn1BitString(Asn1Document document, TaggedObject content, Asn1Object parentObject)
     : base(document, content, parentObject)
 {
     unusedBytes = content.Workload[0];
     bitString   = content.Workload.Skip(1).ToArray();
 }
예제 #14
0
 public Asn1PrintableString(Asn1Document document, TaggedObject content, Asn1Object parentObject)
     : base(document, content, parentObject)
 {
 }
예제 #15
0
 public Asn1Null(Asn1Document document, TaggedObject content, Asn1Object parentObject)
     : base(document, content, parentObject)
 {
     warning = content.WorkloadLength != 0;
 }
 protected virtual Asn1Object CreateSpecificTaggedObject(Asn1Document document, TaggedObject content, Asn1Object parent)
 {
     return null;
 }
예제 #17
0
 public Asn1Set(Asn1Document document, TaggedObject content, Asn1Object parentObject)
     : base(document, content, parentObject)
 {
 }
 private static bool IsInvalidTaggedObject(TaggedObject content)
 {
     return content == null || content is InvalidTaggedObject;
 }
예제 #19
0
 public Asn1Boolean(Asn1Document document, TaggedObject content, Asn1Object parentObject)
     : base(document, content, parentObject)
 {
     boolean = content.Workload[0] == 0xFF;
 }
예제 #20
0
 public Asn1BitString(Asn1Document document, TaggedObject content, Asn1Object parentObject)
     : base(document, content, parentObject)
 {
     unusedBytes = content.Workload[0];
     bitString = content.Workload.Skip(1).ToArray();
 }
 public Asn1NumericString(Asn1Document document, TaggedObject content, Asn1Object parentObject)
     : base(document, content, parentObject) { }
 public Asn1PrintableString(Asn1Document document, TaggedObject content, Asn1Object parentObject)
     : base(document, content, parentObject) { }
 public Asn1StructuredObject(Asn1Document document, TaggedObject content, Asn1Object parentObject)
     : base(document, content, parentObject) 
 {
     ParseContent();
 }
예제 #24
0
 public Asn1DG1Data(Asn1Document document, TaggedObject content, Asn1Object parentObject)
     : base(document, content, parentObject) { }
예제 #25
0
 public Asn1Utf8String(Asn1Document document, TaggedObject content, Asn1Object parentObject)
     : base(document, content, parentObject)
 {
     utf8 = Encoding.UTF8.GetString(content.Workload); 
 }
예제 #26
0
        private static TaggedObject CreateObject(byte[] data, int offset, int length, out int count)
        {
            try
            {
                EnsureArguments(data, offset, length);
                var taggedObject = new TaggedObject(data, offset, length);
                count = taggedObject.Parse();
                return taggedObject;
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }

            count = length;
            return new InvalidTaggedObject(data, offset, length);
        }
 internal Asn1ContextSpecific(Asn1Document document, TaggedObject content, Asn1Object parentObject)
     : base(document, content, parentObject)
 {
 }