示例#1
0
        private static Asn1SequenceOf EncodeModifications(LdapModification[] mods)
        {
            var rfcMods = new Asn1SequenceOf(mods.Length);

            foreach (var t in mods)
            {
                var attr = t.Attribute;

                var vals = new Asn1SetOf(attr.Size());
                if (attr.Size() > 0)
                {
                    foreach (var val in attr.ByteValueArray)
                    {
                        vals.Add(new Asn1OctetString(val));
                    }
                }

                var rfcMod = new Asn1Sequence(2);
                rfcMod.Add(new Asn1Enumerated((int)t.Op));
                rfcMod.Add(new RfcAttributeTypeAndValues(attr.Name, vals));

                rfcMods.Add(rfcMod);
            }

            return(rfcMods);
        }
        /// <summary>
        ///     Encode an array of LdapModifications to ASN.1.
        /// </summary>
        /// <param name="mods">
        ///     an array of LdapModification objects.
        /// </param>
        /// <returns>
        ///     an Asn1SequenceOf object containing the modifications.
        /// </returns>
        private static Asn1SequenceOf EncodeModifications(LdapModification[] mods)
        {
            // Convert Java-API LdapModification[] to RFC2251 SEQUENCE OF SEQUENCE
            var rfcMods = new Asn1SequenceOf(mods.Length);

            for (var i = 0; i < mods.Length; i++)
            {
                var attr = mods[i].Attribute;

                // place modification attribute values in Asn1SetOf
                var vals = new Asn1SetOf(attr.Size());
                if (attr.Size() > 0)
                {
                    var attrEnum = attr.ByteValues;
                    while (attrEnum.MoveNext())
                    {
                        vals.Add(new RfcAttributeValue(attrEnum.Current));
                    }
                }

                // create SEQUENCE containing mod operation and attr type and vals
                var rfcMod = new Asn1Sequence(2);
                rfcMod.Add(new Asn1Enumerated(mods[i].Op));
                rfcMod.Add(new RfcAttributeTypeAndValues(new RfcAttributeDescription(attr.Name), vals));

                // place SEQUENCE into SEQUENCE OF
                rfcMods.Add(rfcMod);
            }

            return(rfcMods);
        }
示例#3
0
        /// <summary>
        ///     Build the attribuite list from an LdapEntry.
        /// </summary>
        /// <param name="entry">
        ///     The LdapEntry associated with this add request.
        /// </param>
        private static RfcAttributeList MakeRfcAttrList(LdapEntry entry)
        {
            // convert Java-API LdapEntry to RFC2251 AttributeList
            var attrSet  = entry.GetAttributeSet();
            var attrList = new RfcAttributeList(attrSet.Count);
            var itr      = attrSet.GetEnumerator();

            while (itr.MoveNext())
            {
                var attr     = (LdapAttribute)itr.Current;
                var vals     = new Asn1SetOf(attr.Size());
                var attrEnum = attr.ByteValues;
                while (attrEnum.MoveNext())
                {
                    vals.Add(new RfcAttributeValue((byte[])attrEnum.Current));
                }

                attrList.Add(new RfcAttributeTypeAndValues(new RfcAttributeDescription(attr.Name), vals));
            }

            return(attrList);
        }