/// <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())); }
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); }
private Asn1Tagged ParseFilterComp() { Asn1Tagged tag = null; var filterComp = (FilterOp)_ft.OpOrAttr; switch (filterComp) { case FilterOp.And: case FilterOp.Or: tag = new Asn1Tagged(new Asn1Identifier((int)filterComp, true), ParseFilterList(), false); break; case FilterOp.Not: tag = new Asn1Tagged(new Asn1Identifier((int)filterComp, true), ParseFilter()); break; default: var filterType = _ft.FilterType; var valueRenamed = _ft.Value; switch (filterType) { case FilterOp.GreaterOrEqual: case FilterOp.LessOrEqual: case FilterOp.ApproxMatch: tag = new Asn1Tagged(new Asn1Identifier((int)filterType, true), new RfcAttributeValueAssertion(_ft.Attr, UnescapeString(valueRenamed)), false); break; case FilterOp.EqualityMatch: if (valueRenamed.Equals("*")) { // present tag = new Asn1Tagged( new Asn1Identifier((int)FilterOp.Present), new Asn1OctetString(_ft.Attr), false); } else if (valueRenamed.IndexOf('*') != -1) { var sub = new Tokenizer(valueRenamed, "*", true); var seq = new Asn1SequenceOf(5); var tokCnt = sub.Count; var cnt = 0; var lastTok = new StringBuilder(string.Empty).ToString(); while (sub.HasMoreTokens()) { var subTok = sub.NextToken(); cnt++; if (subTok.Equals("*")) { // if previous token was '*', and since the current // token is a '*', we need to insert 'any' if (lastTok.Equals(subTok)) { // '**' seq.Add(new Asn1Tagged( new Asn1Identifier((int)SubstringOp.Any), UnescapeString(string.Empty))); } } else { // value (RfcLdapString) if (cnt == 1) { // initial seq.Add(new Asn1Tagged( new Asn1Identifier((int)SubstringOp.Initial), UnescapeString(subTok))); } else if (cnt < tokCnt) { // any seq.Add(new Asn1Tagged( new Asn1Identifier((int)SubstringOp.Any), UnescapeString(subTok))); } else { // final seq.Add(new Asn1Tagged( new Asn1Identifier((int)SubstringOp.Final), UnescapeString(subTok))); } } lastTok = subTok; } tag = new Asn1Tagged( new Asn1Identifier((int)FilterOp.Substrings, true), new RfcSubstringFilter(_ft.Attr, seq), false); } else { tag = new Asn1Tagged( new Asn1Identifier((int)FilterOp.EqualityMatch, true), new RfcAttributeValueAssertion(_ft.Attr, UnescapeString(valueRenamed)), false); } break; case FilterOp.ExtensibleMatch: string type = null, matchingRule = null; var attr = false; var st = new Tokenizer(_ft.Attr, ":"); var first = true; while (st.HasMoreTokens()) { var s = st.NextToken().Trim(); if (first && !s.Equals(":")) { type = s; } else if (s.Equals("dn")) { attr = true; } else if (!s.Equals(":")) { matchingRule = s; } first = false; } tag = new Asn1Tagged( new Asn1Identifier((int)FilterOp.ExtensibleMatch, true), new RfcMatchingRuleAssertion(matchingRule, type, UnescapeString(valueRenamed), attr == false ? null : new Asn1Boolean(true)), false); break; } break; } return(tag); }