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> /// Constructs a sort control with multiple sort keys. /// </summary> /// <param name="keys An"> /// array of sort key objects, to be processed in /// order. /// </param> /// <param name="critical True"> /// if the search operation is to fail if the /// server does not support this control. /// </param> public LdapSortControl(LdapSortKey[] keys, bool critical) : base(RequestOid, critical, null) { var sortKeyList = new Asn1SequenceOf(); for (var i = 0; i < keys.Length; i++) { var key = new Asn1Sequence(); key.Add(new Asn1OctetString(keys[i].Key)); if (keys[i].MatchRule != null) { key.Add(new Asn1Tagged( new Asn1Identifier(Asn1Identifier.Context, false, OrderingRule), new Asn1OctetString(keys[i].MatchRule), false)); } if (keys[i].Reverse) { // only add if true key.Add(new Asn1Tagged( new Asn1Identifier(Asn1Identifier.Context, false, ReverseOrder), new Asn1Boolean(true), false)); } sortKeyList.Add(key); } SetValue(sortKeyList.GetEncoding(new LberEncoder())); }
/// <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); }
/// <summary>Private method used to construct the ber encoded control /// </summary> private void BuildPagedSearchRequest() { /* Create a new Asn1Sequence object */ m_pagedSearchRequest = new Asn1Sequence(2); /* Add the pageSize and cookie to the sequence */ m_pagedSearchRequest.Add(new Asn1Integer(m_pageSize)); m_pagedSearchRequest.Add(new Asn1OctetString(m_cookie)); return; }
/// <summary> /// Constructs an LdapPersistSearchControl object according to the /// supplied parameters. The resulting control is used to specify a /// persistent search. /// </summary> /// <param name="changeTypes"> /// the change types to monitor. The bitwise OR of any /// of the following values: /// <li> LdapPersistSearchControl.ADD</li> /// <li> LdapPersistSearchControl.DELETE</li> /// <li> LdapPersistSearchControl.MODIFY</li> /// <li> LdapPersistSearchControl.MODDN</li> /// To track all changes the value can be set to:. /// <li> LdapPersistSearchControl.ANY</li> /// </param> /// <param name="changesOnly"> /// true if you do not want the server to return /// all existing entries in the directory that match the search /// criteria. (Use this if you just want the changed entries to be /// returned.). /// </param> /// <param name="returnControls"> /// true if you want the server to return entry /// change controls with each entry in the search results. You need to /// return entry change controls to discover what type of change /// and other additional information about the change. /// </param> /// <param name="isCritical"> /// true if this control is critical to the search /// operation. If true and the server does not support this control, /// the server will not perform the search at all. /// </param> public LdapPersistSearchControl(int changeTypes, bool changesOnly, bool returnControls, bool isCritical) : base(RequestOid, isCritical, null) { _mChangeTypes = changeTypes; _mChangesOnly = changesOnly; _mReturnControls = returnControls; _mSequence = new Asn1Sequence(SequenceSize); _mSequence.Add(new Asn1Integer(_mChangeTypes)); _mSequence.Add(new Asn1Boolean(_mChangesOnly)); _mSequence.Add(new Asn1Boolean(_mReturnControls)); SetValue(); }
/// <summary> /// Creates a new ExtendedDnControl using the specified flag. /// </summary> /// <param name="flag">The format of the GUID that will be returned.</param> /// <param name="critical">True if the LDAP operation should be discarded if the /// control is not supported. False if the operation can be processed without /// the control.</param> public ExtendedDnControl(GuidFormatFlag flag, bool critical) : base(ExtendedDnControlOID, critical, null) { _controlValue.Add(new Asn1Integer((int)flag)); try { using (var encodedData = new MemoryStream()) { _controlValue.Encode(_encoder, encodedData); SetValue(encodedData.ToArray()); } } catch (IOException e) { // Shouldn't occur unless there is a serious failure throw new InvalidOperationException("Unable to create instance of ExtendedDnControl", e); } }
private void BuildTypedPagedRequest() { _request = new Asn1Sequence(2); _request.Add(new Asn1Integer(Size)); _request.Add(new Asn1OctetString(Cookie)); }