Exemple #1
0
        internal static void Decode(AsnReader reader, Asn1Tag expectedTag, out Asn1Substring decoded)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            reader.ReadNull(expectedTag);
            Decode(reader, out decoded);
        }
Exemple #2
0
        internal static void Decode(AsnReader reader, out Asn1Substring decoded)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            decoded = new Asn1Substring();
            Asn1Tag tag = reader.PeekTag();

            if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 0)))
            {
                if (reader.TryGetPrimitiveOctetStringBytes(new Asn1Tag(TagClass.ContextSpecific, 0), out ReadOnlyMemory <byte> tmpInitial))
                {
                    decoded.Initial = tmpInitial;
                }
                else
                {
                    decoded.Initial = reader.ReadOctetString(new Asn1Tag(TagClass.ContextSpecific, 0));
                }
            }
            else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 1)))
            {
                if (reader.TryGetPrimitiveOctetStringBytes(new Asn1Tag(TagClass.ContextSpecific, 1), out ReadOnlyMemory <byte> tmpAny))
                {
                    decoded.Any = tmpAny;
                }
                else
                {
                    decoded.Any = reader.ReadOctetString(new Asn1Tag(TagClass.ContextSpecific, 1));
                }
            }
            else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 2)))
            {
                if (reader.TryGetPrimitiveOctetStringBytes(new Asn1Tag(TagClass.ContextSpecific, 2), out ReadOnlyMemory <byte> tmpFinal))
                {
                    decoded.Final = tmpFinal;
                }
                else
                {
                    decoded.Final = reader.ReadOctetString(new Asn1Tag(TagClass.ContextSpecific, 2));
                }
            }
            else
            {
                throw new CryptographicException();
            }
        }
        internal static void Decode(AsnReader reader, Asn1Tag expectedTag, out Asn1SubstringFilter decoded)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            decoded = new Asn1SubstringFilter();
            AsnReader sequenceReader = reader.ReadSequence(expectedTag);
            AsnReader collectionReader;


            if (sequenceReader.TryGetPrimitiveOctetStringBytes(out ReadOnlyMemory <byte> tmpType))
            {
                decoded.Type = tmpType;
            }
            else
            {
                decoded.Type = sequenceReader.ReadOctetString();
            }


            // Decode SEQUENCE OF for Substrings
            {
                collectionReader = sequenceReader.ReadSequence();
                var           tmpList = new List <Asn1Substring>();
                Asn1Substring tmpItem;

                while (collectionReader.HasData)
                {
                    Asn1Substring.Decode(collectionReader, out tmpItem);
                    tmpList.Add(tmpItem);
                }

                decoded.Substrings = tmpList.ToArray();
            }


            sequenceReader.ThrowIfNotEmpty();
        }