2017-05-27 18:20:27 +01:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:23 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2017-05-27 18:20:27 +01:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : CompareBytes.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : Helpers.
|
2017-05-27 18:20:27 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Compares two byte arrays.
|
2017-05-27 18:20:27 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// This library is free software; you can redistribute it and/or modify
|
|
|
|
|
|
// it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
|
// published by the Free Software Foundation; either version 2.1 of the
|
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
|
//
|
|
|
|
|
|
// This library is distributed in the hope that it will be useful, but
|
|
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
|
|
//
|
|
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
|
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2022-12-03 16:07:08 +00:00
|
|
|
|
// Copyright © 2011-2023 Natalia Portillo
|
2017-05-27 18:20:27 +01:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
2022-03-06 13:29:37 +00:00
|
|
|
|
namespace Aaru.Helpers;
|
|
|
|
|
|
|
|
|
|
|
|
public static partial class ArrayHelpers
|
2017-05-27 18:20:27 +01:00
|
|
|
|
{
|
2022-03-06 13:29:37 +00:00
|
|
|
|
/// <summary>Compares two byte arrays</summary>
|
|
|
|
|
|
/// <param name="different"><c>true</c> if they are different in any way</param>
|
|
|
|
|
|
/// <param name="sameSize"><c>true</c> if they have the same size</param>
|
|
|
|
|
|
/// <param name="compareArray1">Left array</param>
|
|
|
|
|
|
/// <param name="compareArray2">Right array</param>
|
2022-03-07 07:36:42 +00:00
|
|
|
|
public static void CompareBytes(out bool different, out bool sameSize, byte[] compareArray1, byte[] compareArray2)
|
2017-05-27 18:20:27 +01:00
|
|
|
|
{
|
2022-03-06 13:29:37 +00:00
|
|
|
|
different = false;
|
|
|
|
|
|
sameSize = true;
|
2017-05-27 18:20:27 +01:00
|
|
|
|
|
2022-03-06 13:29:37 +00:00
|
|
|
|
long leastBytes;
|
2019-11-25 00:54:39 +00:00
|
|
|
|
|
2022-03-06 13:29:37 +00:00
|
|
|
|
if(compareArray1.LongLength < compareArray2.LongLength)
|
|
|
|
|
|
{
|
|
|
|
|
|
sameSize = false;
|
|
|
|
|
|
leastBytes = compareArray1.LongLength;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(compareArray1.LongLength > compareArray2.LongLength)
|
|
|
|
|
|
{
|
|
|
|
|
|
sameSize = false;
|
|
|
|
|
|
leastBytes = compareArray2.LongLength;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
leastBytes = compareArray1.LongLength;
|
2017-05-27 18:20:27 +01:00
|
|
|
|
|
2022-03-06 13:29:37 +00:00
|
|
|
|
for(long i = 0; i < leastBytes; i++)
|
2023-10-03 23:25:24 +01:00
|
|
|
|
{
|
2022-03-06 13:29:37 +00:00
|
|
|
|
if(compareArray1[i] != compareArray2[i])
|
|
|
|
|
|
{
|
|
|
|
|
|
different = true;
|
2019-11-25 00:54:39 +00:00
|
|
|
|
|
2022-03-06 13:29:37 +00:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-10-03 23:25:24 +01:00
|
|
|
|
}
|
2017-05-27 18:20:27 +01:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|