コード例 #1
0
ファイル: Asn1Serializer.cs プロジェクト: zivillian/ldap.net
 internal static byte[] Serialize(Asn1LdapMessage message)
 {
     using (var writer = new AsnWriter(AsnEncodingRules.BER))
     {
         message.Encode(writer);
         return(writer.Encode());
     }
 }
コード例 #2
0
        internal static void Decode(AsnReader reader, out Asn1LdapMessage decoded)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            Decode(reader, Asn1Tag.Sequence, out decoded);
        }
コード例 #3
0
ファイル: Asn1Serializer.cs プロジェクト: zivillian/ldap.net
 internal static Asn1LdapMessage Deserialize(ReadOnlyMemory <byte> data)
 {
     try
     {
         return(Asn1LdapMessage.Decode(data, AsnEncodingRules.BERFlexible));
     }
     catch (CryptographicException ex)
     {
         throw new LdapProtocolException("invalid BER encoding", ex);
     }
 }
コード例 #4
0
        internal static void Decode(AsnReader reader, Asn1Tag expectedTag, out Asn1LdapMessage decoded)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

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


            if (!sequenceReader.TryReadInt32(out decoded.MessageID))
            {
                sequenceReader.ThrowIfNotEmpty();
            }

            Asn1ProtocolOp.Decode(sequenceReader, out decoded.ProtocolOp);

            if (sequenceReader.HasData && sequenceReader.PeekTag().HasSameClassAndValue(new Asn1Tag(TagClass.ContextSpecific, 0)))
            {
                // Decode SEQUENCE OF for Controls
                {
                    collectionReader = sequenceReader.ReadSequence(new Asn1Tag(TagClass.ContextSpecific, 0));
                    var         tmpList = new List <Asn1Control>();
                    Asn1Control tmpItem;

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

                    decoded.Controls = tmpList.ToArray();
                }
            }


            sequenceReader.ThrowIfNotEmpty();
        }