internal static void Decode(AsnReader reader, out Asn1AuthenticationChoice decoded)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

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

            if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 0)))
            {
                if (reader.TryGetPrimitiveOctetStringBytes(new Asn1Tag(TagClass.ContextSpecific, 0), out ReadOnlyMemory <byte> tmpSimple))
                {
                    decoded.Simple = tmpSimple;
                }
                else
                {
                    decoded.Simple = reader.ReadOctetString(new Asn1Tag(TagClass.ContextSpecific, 0));
                }
            }
            else if (tag.HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 3)))
            {
                Asn1SaslCredentials tmpSasl;
                Asn1SaslCredentials.Decode(reader, new Asn1Tag(TagClass.ContextSpecific, 3), out tmpSasl);
                decoded.Sasl = tmpSasl;
            }
            else
            {
                throw new CryptographicException();
            }
        }
Пример #2
0
        internal static void Decode(AsnReader reader, out Asn1SaslCredentials decoded)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            Decode(reader, Asn1Tag.Sequence, out decoded);
        }
Пример #3
0
        internal static void Decode(AsnReader reader, Asn1Tag expectedTag, out Asn1SaslCredentials decoded)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

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


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


            if (sequenceReader.HasData && sequenceReader.PeekTag().HasSameClassAndValue(Asn1Tag.PrimitiveOctetString))
            {
                if (sequenceReader.TryGetPrimitiveOctetStringBytes(out ReadOnlyMemory <byte> tmpCredentials))
                {
                    decoded.Credentials = tmpCredentials;
                }
                else
                {
                    decoded.Credentials = sequenceReader.ReadOctetString();
                }
            }


            sequenceReader.ThrowIfNotEmpty();
        }