Skip to content

Comparer is an ongoing project aimed at comparing reference types based on their contents rather than their memory references, ensuring that objects with identical data are considered equal regardless of their instance in memory.

License

Notifications You must be signed in to change notification settings

m2eyes/Comparer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Comparer

Overview

Comparer is an ongoing project aimed at comparing reference types based on their contents rather than their memory references, ensuring that objects with identical data are considered equal regardless of their instance in memory.

ByteArrayComparer

The ByteArrayComparer class provides a method to compare two byte arrays for equality. This method is specifically written to prevent timing attacks by ensuring that the loop is not optimized.

Method

EqualsByValue

public static bool EqualsByValue(this byte[] firstArray, byte[] secondArray)

Parameters

  • firstArray: The first byte array to compare.
  • secondArray: The second byte array to compare.

Returns

  • true if the byte arrays are equal.
  • false otherwise.

Remarks

This method is specifically written so that the loop is not optimized. This is done to prevent timing attacks.

Example Usage

using Comparer;

class Program
{
    static void Main()
    {
        byte[] array1 = { 1, 2, 3, 4, 5 };
        byte[] array2 = { 1, 2, 3, 4, 5 };
        byte[] array3 = { 1, 2, 3, 4, 6 };

        bool result1 = array1.EqualsByValue(array2); // true
        bool result2 = array1.EqualsByValue(array3); // false

        Console.WriteLine($"Array1 equals Array2: {result1}");
        Console.WriteLine($"Array1 equals Array3: {result2}");
    }
}

License

This project is licensed under the MIT License.

About

Comparer is an ongoing project aimed at comparing reference types based on their contents rather than their memory references, ensuring that objects with identical data are considered equal regardless of their instance in memory.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages