Table of Contents

ChecksumBuilder Class

Definition

Namespace
Cuemon.Data.Integrity
Assemblies
Cuemon.Data.Integrity.dll
Source
src/Cuemon.Data.Integrity/ChecksumBuilder.cs

Provides a way to fluently represent checksum values of arbitrary data.

public class ChecksumBuilder : IDataIntegrity, IEquatable<ChecksumBuilder>
Inheritance
ChecksumBuilder
Implements
Derived

Examples

The following example demonstrates how to use ChecksumBuilder to compute and compare checksums for arbitrary data.

using System;
using System.Text;
using Cuemon.Data.Integrity;
using Cuemon.Security;

namespace MyApp.Examples
{
    public sealed class ChecksumBuilderExample
    {
        public void Demonstrate()
        {
            var builder = new ChecksumBuilder(() => HashFactory.CreateFnv128());
            Console.WriteLine($"Empty checksum: {builder.Checksum.ToHexadecimalString()}");

            builder.CombineWith(BitConverter.GetBytes(42L));
            builder.CombineWith(Encoding.UTF8.GetBytes("Hello, World!"));

            var comparison = new ChecksumBuilder(BitConverter.GetBytes(42L), () => HashFactory.CreateFnv128());
            comparison.CombineWith(Encoding.UTF8.GetBytes("Hello, World!"));

            Console.WriteLine($"Current checksum: {builder}");
            Console.WriteLine($"Checksums match: {builder.Equals(comparison)}");
            Console.WriteLine($"Hash code: {builder.GetHashCode()}");
        }
    }
}

Constructors

Name Description
ChecksumBuilder(byte[], Func<Hash>)

Initializes a new instance of the ChecksumBuilder class.

ChecksumBuilder(Func<Hash>)

Initializes a new instance of the ChecksumBuilder class.

Properties

Name Description
Bytes

Gets a byte array that is the result of the associated ChecksumBuilder.

Checksum

Gets a HashResult containing a computed hash value of the data this instance represents.

ComputedHash

Gets or sets the computed checksum of Bytes.

HashFactory

Gets the value factory of this instance.

Methods

Name Description
CombineWith(byte[])

Combines the additionalChecksum to the representation of this instance.

Equals(ChecksumBuilder)

Indicates whether the current object is equal to another object of the same type.

Equals(object)

Determines whether the specified Object is equal to this instance.

GetHashCode()

Returns a hash code for this instance.

ToString()

Converts the the Bytes of this instance to its equivalent hexadecimal representation.