Beispiel #1
0
        internal void RetrieveMessages()
        {
            var decoder = new LBERDecoder();

            while (!_cts.IsCancellationRequested)
            {
                try
                {
                    var asn1Id = new Asn1Identifier(_conn.ActiveStream);

                    if (asn1Id.Tag != Asn1Sequence.Tag)
                    {
                        continue; // loop looking for an RfcLdapMessage identifier
                    }

                    // Turn the message into an RfcMessage class
                    var asn1Len = new Asn1Length(_conn.ActiveStream);

                    Messages.Add(new RfcLdapMessage(decoder, _conn.ActiveStream, asn1Len.Length));
                }
                catch (System.IO.IOException)
                {
                    // ignore
                }
            }

            // ReSharper disable once FunctionNeverReturns
        }
Beispiel #2
0
        /// <summary>
        ///     Decode an LBER encoded value into an Asn1Object from an InputStream.
        ///     This method also returns the total length of this encoded
        ///     Asn1Object (length of type + length of length + length of content)
        ///     in the parameter len. This information is helpful when decoding
        ///     structured types.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <param name="len">The length.</param>
        /// <returns>
        ///     Decoded Asn1Obect.
        /// </returns>
        /// <exception cref="EndOfStreamException">Unknown tag.</exception>
        public static Asn1Object Decode(Stream stream, int[] len)
        {
            var asn1Id  = new Asn1Identifier(stream);
            var asn1Len = new Asn1Length(stream);

            var length = asn1Len.Length;

            len[0] = asn1Id.EncodedLength + asn1Len.EncodedLength + length;

            if (asn1Id.Universal == false)
            {
                return(new Asn1Tagged(stream, length, (Asn1Identifier)asn1Id.Clone()));
            }

            switch (asn1Id.Tag)
            {
            case Asn1Sequence.Tag:
                return(new Asn1Sequence(stream, length));

            case Asn1Set.Tag:
                return(new Asn1Set(stream, length));

            case Asn1Boolean.Tag:
                return(new Asn1Boolean(stream, length));

            case Asn1Integer.Tag:
                return(new Asn1Integer(stream, length));

            case Asn1OctetString.Tag:
                return(new Asn1OctetString(stream, length));

            case Asn1Enumerated.Tag:
                return(new Asn1Enumerated(stream, length));

            case Asn1Null.Tag:
                return(new Asn1Null());    // has no content to decode.

            default:
                throw new EndOfStreamException("Unknown tag");
            }
        }
Beispiel #3
0
 public LBERDecoder()
 {
     asn1ID  = new Asn1Identifier();
     asn1Len = new Asn1Length();
 }