internal static byte[] Serialize(Asn1LdapMessage message) { using (var writer = new AsnWriter(AsnEncodingRules.BER)) { message.Encode(writer); return(writer.Encode()); } }
internal static void Decode(AsnReader reader, out Asn1LdapMessage decoded) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } Decode(reader, Asn1Tag.Sequence, out decoded); }
internal static Asn1LdapMessage Deserialize(ReadOnlyMemory <byte> data) { try { return(Asn1LdapMessage.Decode(data, AsnEncodingRules.BERFlexible)); } catch (CryptographicException ex) { throw new LdapProtocolException("invalid BER encoding", ex); } }
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(); }