static void EncodeString(byte[] buf, ref int index, NtlmAttribute attr, string value, bool unicode) { var encoding = unicode ? Encoding.Unicode : Encoding.UTF8; int length = encoding.GetByteCount(value); EncodeTypeAndLength(buf, ref index, attr, (short)length); encoding.GetBytes(value, 0, value.Length, buf, index); index += length; }
static void EncodeFlags(byte[] buf, ref int index, NtlmAttribute attr, int value, short size) { EncodeTypeAndLength(buf, ref index, attr, size); switch (size) { case 2: EncodeInt16(buf, ref index, (short)value); break; default: EncodeInt32(buf, ref index, value); break; } }
NtlmAttributeValuePair GetAvPair(NtlmAttribute attr) { for (int i = 0; i < attributes.Count; i++) { if (attributes[i].Attribute == attr) { return(attributes[i]); } } return(null); }
static void EncodeTimestamp(byte[] buf, ref int index, NtlmAttribute attr, long value, short size) { EncodeTypeAndLength(buf, ref index, attr, size); switch (size) { case 2: EncodeInt16(buf, ref index, (short)(value & 0xffff)); break; case 4: EncodeInt32(buf, ref index, (int)(value & 0xffffffff)); break; default: EncodeInt32(buf, ref index, (int)(value & 0xffffffff)); EncodeInt32(buf, ref index, (int)(value >> 32)); break; } }
void SetAvPairString(NtlmAttribute attr, string value) { var pair = (NtlmAttributeStringValuePair)GetAvPair(attr); if (pair == null) { if (value != null) { attributes.Add(new NtlmAttributeStringValuePair(attr, value)); } } else if (value != null) { pair.Value = value; } else { attributes.Remove(pair); } }
void SetAvPairByteArray(NtlmAttribute attr, byte[] value) { var pair = (NtlmAttributeByteArrayValuePair)GetAvPair(attr); if (pair == null) { if (value != null) { attributes.Add(new NtlmAttributeByteArrayValuePair(attr, value)); } } else if (value != null) { pair.Value = value; } else { attributes.Remove(pair); } }
/// <summary> /// Initializes a new instance of the <see cref="NtlmAttributeFlagsValuePair"/> class. /// </summary> /// <remarks> /// Creates a new NTLM attribute and value pair consisting of a flags value. /// </remarks> /// <param name="attr">The NTLM attribute.</param> /// <param name="value">The NTLM attribute value.</param> /// <param name="size">The size of the encoded flags value.</param> internal NtlmAttributeFlagsValuePair(NtlmAttribute attr, int value, short size) : base(attr) { Value = value; Size = size; }
/// <summary> /// Initializes a new instance of the <see cref="NtlmAttributeTimestampValuePair"/> class. /// </summary> /// <remarks> /// Creates a new NTLM attribute and value pair consisting of a timestamp value. /// </remarks> /// <param name="attr">The NTLM attribute.</param> /// <param name="value">The NTLM attribute value.</param> /// <param name="size">The size of the encoded flags value.</param> internal NtlmAttributeTimestampValuePair(NtlmAttribute attr, long value, short size) : base(attr) { Value = value; Size = size; }
/// <summary> /// Initializes a new instance of the <see cref="NtlmAttributeTimestampValuePair"/> class. /// </summary> /// <remarks> /// Creates a new NTLM attribute and value pair consisting of a timestamp value. /// </remarks> /// <param name="attr">The NTLM attribute.</param> /// <param name="value">The NTLM attribute value.</param> public NtlmAttributeTimestampValuePair(NtlmAttribute attr, long value) : this(attr, value, 8) { }
/// <summary> /// Initializes a new instance of the <see cref="NtlmAttributeByteArrayValuePair"/> class. /// </summary> /// <remarks> /// Creates a new NTLM attribute and value pair consisting of a byte array value. /// </remarks> /// <param name="attr">The NTLM attribute.</param> /// <param name="value">The NTLM attribute value.</param> public NtlmAttributeByteArrayValuePair(NtlmAttribute attr, byte[] value) : base(attr) { Value = value; }
static void EncodeByteArray(byte[] buf, ref int index, NtlmAttribute attr, byte[] value) { EncodeTypeAndLength(buf, ref index, attr, (short)value.Length); Buffer.BlockCopy(value, 0, buf, index, value.Length); index += value.Length; }
static void EncodeTypeAndLength(byte[] buf, ref int index, NtlmAttribute attr, short length) { EncodeInt16(buf, ref index, (short)attr); EncodeInt16(buf, ref index, length); }
byte[] GetAvPairByteArray(NtlmAttribute attr) { return(((NtlmAttributeByteArrayValuePair)GetAvPair(attr))?.Value); }
/// <summary> /// Initializes a new instance of the <see cref="NtlmAttributeFlagsValuePair"/> class. /// </summary> /// <remarks> /// Creates a new NTLM attribute and value pair consisting of a flags value. /// </remarks> /// <param name="attr">The NTLM attribute.</param> /// <param name="value">The NTLM attribute value.</param> public NtlmAttributeFlagsValuePair(NtlmAttribute attr, int value) : this(attr, value, 4) { }
string GetAvPairString(NtlmAttribute attr) { return(((NtlmAttributeStringValuePair)GetAvPair(attr))?.Value); }
/// <summary> /// Initializes a new instance of the <see cref="NtlmAttributeStringValuePair"/> class. /// </summary> /// <remarks> /// Creates a new NTLM attribute and value pair consisting of a string value. /// </remarks> /// <param name="attr">The NTLM attribute.</param> /// <param name="value">The NTLM attribute value.</param> public NtlmAttributeStringValuePair(NtlmAttribute attr, string value) : base(attr) { Value = value; }
/// <summary> /// Initializes a new instance of the <see cref="NtlmAttributeValuePair"/> class. /// </summary> /// <remarks> /// Creates a new NTLM attribute and value pair. /// </remarks> /// <param name="attr">The NTLM attribute.</param> protected NtlmAttributeValuePair(NtlmAttribute attr) { Attribute = attr; }