protected override bool DecodeValue(IDerAsnDecoder decoder, Queue <byte> rawData) { if (rawData.Count != 1) { throw new ArgumentException("Boolean-type must contain one data byte", nameof(rawData)); } return(rawData.Dequeue() != 0); }
protected override DerAsnType[] DecodeValue(IDerAsnDecoder decoder, Queue <byte> rawData) { var items = new List <DerAsnType>(); while (rawData.Any()) { items.Add(decoder.Decode(rawData)); } return(items.ToArray()); }
protected override BigInteger DecodeValue(IDerAsnDecoder decoder, Queue <byte> rawData) { if (rawData.Count < 1) { throw new ArgumentException("Integer-type must contain at least one data byte", nameof(rawData)); } var littleEndianData = rawData.DequeueAll().Reverse().ToArray(); return(new BigInteger(littleEndianData)); }
protected override int[] DecodeValue(IDerAsnDecoder decoder, Queue <byte> rawData) { var nodes = new List <int>(); var firstTwoNodes = rawData.Dequeue(); nodes.Add(firstTwoNodes / 40); nodes.Add(firstTwoNodes % 40); while (rawData.Any()) { nodes.Add(DequeueNode(rawData)); } return(nodes.ToArray()); }
protected override DateTimeOffset DecodeValue(IDerAsnDecoder decoder, Queue <byte> rawData) { var ascii = Encoding.ASCII.GetString(rawData.DequeueAll().ToArray()); var match = Regex.Match(ascii, @"^(?<year>[0-9]{2})(?<month>[0-9]{2})(?<day>[0-9]{2})(?<hour>[0-9]{2})(?<minute>[0-9]{2})(?<second>[0-9]{2})?(?<offset>(Z|([+-][0-9]{4})))$"); if (!match.Success) { throw new NotSupportedException($"UtcTime format '{ascii}' not supported"); } int year = AdjustYear(int.Parse(match.Groups["year"].Value)); int month = int.Parse(match.Groups["month"].Value); int day = int.Parse(match.Groups["day"].Value); int hour = int.Parse(match.Groups["hour"].Value); int minute = int.Parse(match.Groups["minute"].Value); int second = !string.IsNullOrEmpty(match.Groups["second"].Value) ? int.Parse(match.Groups["second"].Value) : 0; TimeSpan offset = ParseOffset(match.Groups["offset"].Value); return(new DateTimeOffset(year, month, day, hour, minute, second, offset)); }
protected override BitArray DecodeValue(IDerAsnDecoder decoder, Queue <byte> rawData) { var unusedLowerBitsInLastByte = rawData.Dequeue(); var data = rawData.DequeueAll().ToArray(); if (unusedLowerBitsInLastByte > 0) { byte rest = 0; for (int i = 0; i < data.Length; i++) { var @byte = data[i]; data[i] = (byte)((@byte >> unusedLowerBitsInLastByte) | rest); rest = (byte)(@byte << (8 - unusedLowerBitsInLastByte)); } } return(new BitArray(data.Reverse().ToArray()) { Length = data.Length * 8 - unusedLowerBitsInLastByte }); }
internal DerAsnBoolean(IDerAsnDecoder decoder, DerAsnIdentifier identifier, Queue <byte> rawData) : base(decoder, identifier, rawData) { }
protected override byte DecodeValue(IDerAsnDecoder decoder, Queue <byte> rawData) { return(rawData.Dequeue()); }
internal DerAsnEnumerated(IDerAsnDecoder decoder, DerAsnIdentifier identifier, Queue <byte> rawData) : base(decoder, identifier, rawData) { }
internal DerAsnObjectIdentifier(IDerAsnDecoder decoder, DerAsnIdentifier identifier, Queue <byte> rawData) : base(decoder, identifier, rawData) { }
protected override object DecodeValue(IDerAsnDecoder decoder, Queue <byte> rawData) { return(null); }
protected override byte[] DecodeValue(IDerAsnDecoder decoder, Queue <byte> rawData) { return(rawData.DequeueAll().ToArray()); }
internal DerAsnSequence(IDerAsnDecoder decoder, DerAsnIdentifier identifier, Queue <byte> rawData) : base(decoder, identifier, rawData) { }
public OctetStringSequence(IDerAsnDecoder decoder, DerAsnIdentifier identifier, Queue <byte> rawData) : base(decoder, identifier, rawData) { }
public ContextSpecificSequence(IDerAsnDecoder decoder, DerAsnIdentifier identifier, Queue <byte> rawData) : base(decoder, identifier, rawData) { }
protected override string DecodeValue(IDerAsnDecoder decoder, Queue <byte> rawData) { return(Encoding.ASCII.GetString(rawData.DequeueAll().ToArray())); }
internal DerAsnIa5String(IDerAsnDecoder decoder, DerAsnIdentifier identifier, Queue <byte> rawData) : base(decoder, identifier, rawData) { }
internal ContextSpecificString(IDerAsnDecoder decoder, DerAsnIdentifier identifier, Queue <byte> rawData) : base(decoder, identifier, rawData) { }