Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RfcLdapResult"/> class.
 /// Constructs an RfcLdapResult from parameters
 /// </summary>
 /// <param name="resultCode">the result code of the operation</param>
 /// <param name="matchedDN">the matched DN returned from the server</param>
 /// <param name="errorMessage">the diagnostic message returned from the server</param>
 /// <param name="referral">the referral(s) returned by the server</param>
 public RfcLdapResult(Asn1Enumerated resultCode, RfcLdapDN matchedDN, RfcLdapString errorMessage, Asn1SequenceOf referral = null)
     : base(4)
 {
     Add(resultCode);
     Add(matchedDN);
     Add(errorMessage);
     if (referral != null)
     {
         Add(referral);
     }
 }
 /// <summary> Constructs an RfcLdapResult from parameters
 ///
 /// </summary>
 /// <param name="resultCode">the result code of the operation
 ///
 /// </param>
 /// <param name="matchedDN">the matched DN returned from the server
 ///
 /// </param>
 /// <param name="errorMessage">the diagnostic message returned from the server
 ///
 /// </param>
 /// <param name="referral">the referral(s) returned by the server
 /// </param>
 public RfcLdapResult(Asn1Enumerated resultCode, RfcLdapDN matchedDN, RfcLdapString errorMessage, RfcReferral referral) : base(4)
 {
     add(resultCode);
     add(matchedDN);
     add(errorMessage);
     if (referral != null)
     {
         add(referral);
     }
     return;
 }
Exemplo n.º 3
0
        //*************************************************************************
        // Constructors for SearchRequest
        //*************************************************************************

        /*
         *
         */
        public RfcSearchRequest(RfcLdapDN baseObject, Asn1Enumerated scope, Asn1Enumerated derefAliases, Asn1Integer sizeLimit, Asn1Integer timeLimit, Asn1Boolean typesOnly, RfcFilter filter, RfcAttributeDescriptionList attributes) : base(8)
        {
            add(baseObject);
            add(scope);
            add(derefAliases);
            add(sizeLimit);
            add(timeLimit);
            add(typesOnly);
            add(filter);
            add(attributes);
            return;
        }
Exemplo n.º 4
0
 /// <summary>
 ///     Constructs an RfcLdapResult from parameters.
 /// </summary>
 /// <param name="resultCode">
 ///     the result code of the operation.
 /// </param>
 /// <param name="matchedDn">
 ///     the matched DN returned from the server.
 /// </param>
 /// <param name="errorMessage">
 ///     the diagnostic message returned from the server.
 /// </param>
 /// <param name="referral">
 ///     the referral(s) returned by the server.
 /// </param>
 public RfcLdapResult(Asn1Enumerated resultCode, RfcLdapDn matchedDn, RfcLdapString errorMessage,
                      RfcReferral referral)
     : base(4)
 {
     Add(resultCode);
     Add(matchedDn);
     Add(errorMessage);
     if (referral != null)
     {
         Add(referral);
     }
 }
Exemplo n.º 5
0
        public void WriteEnumerated(string correctResultHex, TestEnum valueToTest)
        {
            var encoded = Helpers.GetExampleBytes(correctResultHex);

            using (var ms = new MemoryStream())
            {
                var asn1Enumerated = new Asn1Enumerated(new System.Numerics.BigInteger((int)valueToTest));
                new DerWriter(ms).Write(asn1Enumerated);

                var res = Enumerable.SequenceEqual(encoded, ms.ToArray());
                Assert.True(res);
            }
        }
Exemplo n.º 6
0
 /// <summary> Constructs an RfcModifyResponse from parameters.
 ///
 /// </summary>
 /// <param name="resultCode">the result code of the operation
 ///
 /// </param>
 /// <param name="matchedDN">the matched DN returned from the server
 ///
 /// </param>
 /// <param name="errorMessage">the diagnostic message returned from the server
 ///
 /// </param>
 /// <param name="referral">the referral(s) returned by the server
 /// </param>
 public RfcModifyResponse(Asn1Enumerated resultCode, RfcLdapDN matchedDN, RfcLdapString errorMessage, RfcReferral referral) : base(resultCode, matchedDN, errorMessage, referral)
 {
     return;
 }
        //*************************************************************************
        // Constructors for RfcLdapResult
        //*************************************************************************

        /// <summary> Constructs an RfcLdapResult from parameters
        ///
        /// </summary>
        /// <param name="resultCode">the result code of the operation
        ///
        /// </param>
        /// <param name="matchedDN">the matched DN returned from the server
        ///
        /// </param>
        /// <param name="errorMessage">the diagnostic message returned from the server
        /// </param>
        public RfcLdapResult(Asn1Enumerated resultCode, RfcLdapDN matchedDN, RfcLdapString errorMessage) : this(resultCode, matchedDN, errorMessage, null)
        {
            return;
        }
Exemplo n.º 8
0
 /// <summary> Constructs an RfcSearchResultDone from parameters.
 ///
 /// </summary>
 /// <param name="resultCode">the result code of the operation
 ///
 /// </param>
 /// <param name="matchedDN">the matched DN returned from the server
 ///
 /// </param>
 /// <param name="errorMessage">the diagnostic message returned from the server
 ///
 /// </param>
 /// <param name="referral">the referral(s) returned by the server
 /// </param>
 public RfcSearchResultDone(Asn1Enumerated resultCode, RfcLdapDN matchedDN, RfcLdapString errorMessage, RfcReferral referral)
     : base(resultCode, matchedDN, errorMessage, referral)
 {
 }
Exemplo n.º 9
0
        // *************************************************************************
        // Constructors for RfcLdapResult
        // *************************************************************************

        /// <summary>
        ///     Constructs an RfcLdapResult from parameters.
        /// </summary>
        /// <param name="resultCode">
        ///     the result code of the operation.
        /// </param>
        /// <param name="matchedDn">
        ///     the matched DN returned from the server.
        /// </param>
        /// <param name="errorMessage">
        ///     the diagnostic message returned from the server.
        /// </param>
        public RfcLdapResult(Asn1Enumerated resultCode, RfcLdapDn matchedDn, RfcLdapString errorMessage)
            : this(resultCode, matchedDn, errorMessage, null)
        {
        }
Exemplo n.º 10
0
 /// <summary>
 ///     Constructs an RfcCompareResponse from parameters.
 /// </summary>
 /// <param name="resultCode">
 ///     the result code of the operation.
 /// </param>
 /// <param name="matchedDn">
 ///     the matched DN returned from the server.
 /// </param>
 /// <param name="errorMessage">
 ///     the diagnostic message returned from the server.
 /// </param>
 /// <param name="referral">
 ///     the referral(s) returned by the server.
 /// </param>
 public RfcCompareResponse(Asn1Enumerated resultCode, RfcLdapDn matchedDn, RfcLdapString errorMessage,
                           RfcReferral referral)
     : base(resultCode, matchedDn, errorMessage, referral)
 {
 }
Exemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RfcModifyResponse"/> class.
 /// </summary>
 /// <param name="resultCode">the result code of the operation</param>
 /// <param name="matchedDN">the matched DN returned from the server</param>
 /// <param name="errorMessage">the diagnostic message returned from the server</param>
 public RfcModifyResponse(Asn1Enumerated resultCode, RfcLdapDN matchedDN, RfcLdapString errorMessage)
     : base(resultCode, matchedDN, errorMessage)
 {
 }
Exemplo n.º 12
0
        private static T MakeInstanceOfAsn1Object <T>(long nodeStartOffset, Asn1Class asn1Class, bool constructed, int tag, SubStream content)
            where T : Asn1ObjectBase
        {
            T foundObject;
            Asn1ObjectBase shouldBeType = null;

            if (asn1Class == Asn1Class.ContextSpecific)
            {
                shouldBeType = new Asn1ContextSpecific(constructed, tag, content);
            }
            else
            {
                switch ((Asn1Type)tag)
                {
                case Asn1Type.Eoc:
                    shouldBeType = new Asn1Eoc();
                    break;

                case Asn1Type.Boolean:
                    shouldBeType = new Asn1Boolean(content, constructed);
                    break;

                case Asn1Type.Integer:
                    shouldBeType = new Asn1Integer(content, constructed);
                    break;

                case Asn1Type.BitString:
                    shouldBeType = new Asn1BitString(content, constructed);
                    break;

                case Asn1Type.OctetString:
                    shouldBeType = new Asn1OctetString(content, constructed);
                    break;

                case Asn1Type.Null:
                    shouldBeType = new Asn1Null(constructed);
                    break;

                case Asn1Type.ObjectIdentifier:
                    shouldBeType = new Asn1ObjectIdentifier(content, constructed);
                    break;

                case Asn1Type.Real:
                    shouldBeType = new Asn1Real(content, constructed);
                    break;

                case Asn1Type.Enumerated:
                    shouldBeType = new Asn1Enumerated(content, constructed);
                    break;

                case Asn1Type.Utf8String:
                    shouldBeType = new Asn1Utf8String(content, constructed);
                    break;

                case Asn1Type.RelativeOid:
                    shouldBeType = new Asn1RelativeOid(content, constructed);
                    break;

                case Asn1Type.Sequence:
                    shouldBeType = new Asn1Sequence(asn1Class, content, constructed);
                    break;

                case Asn1Type.Set:
                    shouldBeType = new Asn1Set(asn1Class, content, constructed);
                    break;

                case Asn1Type.NumericString:
                    shouldBeType = new Asn1NumericString(content, constructed);
                    break;

                case Asn1Type.PrintableString:
                    shouldBeType = new Asn1PrintableString(content, constructed);
                    break;

                case Asn1Type.T61String:
                    shouldBeType = new Asn1T61String(content, constructed);
                    break;

                case Asn1Type.Ia5String:
                    shouldBeType = new Asn1Ia5String(content, constructed);
                    break;

                case Asn1Type.UtcTime:
                    shouldBeType = new Asn1UtcTime(content, constructed);
                    break;

                case Asn1Type.GeneralizedTime:
                    shouldBeType = new Asn1GeneralizedTime(content, constructed);
                    break;

                case Asn1Type.GraphicString:
                    shouldBeType = new Asn1GraphicString(content, constructed);
                    break;

                case Asn1Type.GeneralString:
                    shouldBeType = new Asn1GeneralString(content, constructed);
                    break;

                case Asn1Type.UniversalString:
                    shouldBeType = new Asn1UniversalString(content, constructed);
                    break;

                case Asn1Type.BmpString:
                    shouldBeType = new Asn1BmpString(content, constructed);
                    break;

                case Asn1Type.ObjectDescriptor:
                case Asn1Type.External:
                case Asn1Type.EmbeddedPdv:
                case Asn1Type.VideotexString:
                case Asn1Type.VisibleString:
                case Asn1Type.CharacterString:
                case Asn1Type.LongForm:
                default:
                    throw new NotSupportedException($"ASN.1 tag {tag} is unsupported.");
                }
            }

            foundObject = shouldBeType as T;

            // sanity check
            if (foundObject == null)
            {
                throw new FormatException(FormattableString.Invariant($"ASN.1 node at offset {nodeStartOffset} is of type {shouldBeType.GetType()} but expected type was {typeof(T)}"));
            }

            return(foundObject);
        }