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();
            }
        }
Exemplo n.º 2
0
        internal static void Decode(AsnReader reader, Asn1Tag expectedTag, out Asn1BindRequest decoded)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

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


            if (!sequenceReader.TryReadUInt8(out decoded.Version))
            {
                sequenceReader.ThrowIfNotEmpty();
            }


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

            Asn1AuthenticationChoice.Decode(sequenceReader, out decoded.Authentication);

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

            reader.ReadNull(expectedTag);
            Decode(reader, out decoded);
        }