Minor code cleanup

This commit is contained in:
MichaelGrafnetter 2016-01-02 16:30:17 +01:00
parent 421a33e102
commit 2251526bfa
3 changed files with 26 additions and 17 deletions

View File

@ -1,6 +1,9 @@
 
namespace DSInternals.Common.Cryptography namespace DSInternals.Common.Cryptography
{ {
/// <summary>
/// Implements the CRC32 algorithm, as used by AD replication.
/// </summary>
public static class Crc32 public static class Crc32
{ {
private static readonly uint[] crcTable = new uint[] { private static readonly uint[] crcTable = new uint[] {
@ -76,7 +79,7 @@ namespace DSInternals.Common.Cryptography
uint crc = uint.MaxValue; uint crc = uint.MaxValue;
for(int i = 0; i < buffer.Length; i++) for(int i = 0; i < buffer.Length; i++)
{ {
crc = crcTable[(crc ^ buffer[i]) & 0xFF] ^ (crc >> 8); crc = crcTable[(crc ^ buffer[i]) & byte.MaxValue] ^ (crc >> 8 );
} }
return crc ^ uint.MaxValue; return crc ^ uint.MaxValue;
} }

View File

@ -59,6 +59,7 @@
public const string OrganizationalUnitName = "ou"; public const string OrganizationalUnitName = "ou";
public const string ParentDNTag = "PDNT"; public const string ParentDNTag = "PDNT";
public const string PEKList = "pekList"; public const string PEKList = "pekList";
public const string PEKChangeInterval = "pekKeyChangeInterval";
public const string PrimaryGroupId = "primaryGroupID"; public const string PrimaryGroupId = "primaryGroupID";
public const int PrimaryGroupIdId = 589922; public const int PrimaryGroupIdId = 589922;
public const string PropertyMetaData = "replPropertyMetaData"; public const string PropertyMetaData = "replPropertyMetaData";

View File

@ -12,6 +12,10 @@ namespace DSInternals.DataStore
private const string linkDNCol = "link_DNT"; private const string linkDNCol = "link_DNT";
private const string backlinkDNCol = "backlink_DNT"; private const string backlinkDNCol = "backlink_DNT";
private const string linkBaseCol = "link_base"; private const string linkBaseCol = "link_base";
private const string linkDataCol = "link_data";
private const string linkMetadataCol = "link_metadata";
private const string linkDeletedTimeCol = "link_deltime";
private const string linkDeactivatedTimeCol = "link_deactivetime";
private const string linkIndex = "link_present_active_index"; private const string linkIndex = "link_present_active_index";
private Cursor cursor; private Cursor cursor;
@ -27,29 +31,25 @@ namespace DSInternals.DataStore
public int? GetLinkedDNTag(int dnTag, string attributeName) public int? GetLinkedDNTag(int dnTag, string attributeName)
{ {
int[] result = this.GetLinkedDNTags(dnTag, attributeName); try
switch(result.Length)
{ {
case 0: return this.GetLinkedDNTags(dnTag, attributeName).SingleOrDefault();
return null; }
case 1: catch(InvalidOperationException)
return result[0]; {
default: // TODO: Make this a special exception type. Move message to resources.
// TODO: Make this a special exception type. Move message to resources. throw new Exception("More than 1 objects have been found.");
throw new Exception("More than 1 objects have been found.");
} }
} }
public int[] GetLinkedDNTags(int dnTag, string attributeName) public IEnumerable<int> GetLinkedDNTags(int dnTag, string attributeName)
{ {
var result = new List<int>();
SchemaAttribute attr = this.schema.FindAttribute(attributeName); SchemaAttribute attr = this.schema.FindAttribute(attributeName);
if(!attr.LinkId.HasValue) if(!attr.LinkId.HasValue)
{ {
// This is not a linked multivalue attribute.
//TODO: Throw a proper exception //TODO: Throw a proper exception
throw new Exception(); // TODO: Check that attribute type is DN
throw new Exception("This is not a linked multivalue attribute.");
} }
int linkId = attr.LinkId.Value; int linkId = attr.LinkId.Value;
// Remove the rightmost bit that indicates if this is a forward link or a backlink. // Remove the rightmost bit that indicates if this is a forward link or a backlink.
@ -62,9 +62,14 @@ namespace DSInternals.DataStore
{ {
// TODO: Not deactivated? // TODO: Not deactivated?
int foundTag = (int)cursor.IndexRecord[backlinkDNCol]; int foundTag = (int)cursor.IndexRecord[backlinkDNCol];
result.Add(foundTag); yield return foundTag;
} }
return result.ToArray(); }
public IEnumerable<byte[]> GetDNBinaryValues(int dnTag, string attributeName)
{
// TODO: Implement DN-Binary attribute value retrieval from linktable.
throw new NotImplementedException();
} }
public void Dispose() public void Dispose()