60 lines
1.9 KiB
C#
60 lines
1.9 KiB
C#
using System;
|
|
namespace Unosquare.Swan.Networking.Ldap {
|
|
/// <summary>
|
|
/// Represents a LDAP Modification Request Message.
|
|
/// </summary>
|
|
/// <seealso cref="Unosquare.Swan.Networking.Ldap.LdapMessage" />
|
|
public sealed class LdapModifyRequest : LdapMessage {
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="LdapModifyRequest"/> class.
|
|
/// </summary>
|
|
/// <param name="dn">The dn.</param>
|
|
/// <param name="modifications">The modifications.</param>
|
|
/// <param name="control">The control.</param>
|
|
public LdapModifyRequest(String dn, LdapModification[] modifications, LdapControl[] control)
|
|
: base(LdapOperation.ModifyRequest, new RfcModifyRequest(dn, EncodeModifications(modifications)), control) {
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the dn.
|
|
/// </summary>
|
|
/// <value>
|
|
/// The dn.
|
|
/// </value>
|
|
public String DN => this.Asn1Object.RequestDn;
|
|
|
|
/// <inheritdoc />
|
|
public override String ToString() => this.Asn1Object.ToString();
|
|
|
|
private static Asn1SequenceOf EncodeModifications(LdapModification[] mods) {
|
|
Asn1SequenceOf rfcMods = new Asn1SequenceOf(mods.Length);
|
|
|
|
foreach(LdapModification t in mods) {
|
|
LdapAttribute attr = t.Attribute;
|
|
|
|
Asn1SetOf vals = new Asn1SetOf(attr.Size());
|
|
if(attr.Size() > 0) {
|
|
foreach(SByte[] val in attr.ByteValueArray) {
|
|
vals.Add(new Asn1OctetString(val));
|
|
}
|
|
}
|
|
|
|
Asn1Sequence rfcMod = new Asn1Sequence(2);
|
|
rfcMod.Add(new Asn1Enumerated((Int32)t.Op));
|
|
rfcMod.Add(new RfcAttributeTypeAndValues(attr.Name, vals));
|
|
|
|
rfcMods.Add(rfcMod);
|
|
}
|
|
|
|
return rfcMods;
|
|
}
|
|
|
|
internal class RfcAttributeTypeAndValues : Asn1Sequence {
|
|
public RfcAttributeTypeAndValues(String type, Asn1Object vals)
|
|
: base(2) {
|
|
this.Add(type);
|
|
this.Add(vals);
|
|
}
|
|
}
|
|
}
|
|
} |