//-----------------------------------------------------------------------
//
// Copyright (c) ParanoidMike. All rights reserved.
//
//-----------------------------------------------------------------------
namespace ParanoidMike
{
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using Microsoft.Win32;
///
/// Reusable functions for many uses.
///
public static class Utility
{
///
/// Compares the values of two byte arrays, and returns true only if every array member is identical
///
///
/// First array to be compared.
///
///
/// Second array to be compared.
///
///
/// True if first array is identical to second array.
/// False if the arrays are not identical.
///
public static bool DoByteArraysMatch(
byte[] firstArray,
byte[] secondArray)
{
// Check to be sure they two arrays match in length before doing anything else; if not, then they cannot possibly match
int upperBound = firstArray.GetUpperBound(0);
try
{
if (upperBound != secondArray.GetUpperBound(0))
{
// Caller must've screwed something up, as this function is only intended to compare arrays with the same number of elements
throw (new NotSupportedException("EFSConfiguration.EFSConfiguration.MismatchInSize"));
}
}
catch (NullReferenceException)
{
// One of the arrays is null
throw;
}
// Perform comparison of each byte[i] array value; if any comparison fails, the arrays must be unequal
for (int i = 0; i < upperBound; i++)
{
if (firstArray[i] != secondArray[i])
{
////Console.WriteLine("Array contents are dissimilar: element " + i.ToString + " is equal to \"" + firstArray[i].ToString + "\" in ");
////Console.WriteLine("the first array and \"" + secondArray[i].ToString + "\" in the second array.", Environment.NewLine);
return false;
}
}
// If function has made it this far, then the byte arrays are (almost) certainly identical
return true;
}
}
}