using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace UniversalEditor.Checksum
{
///
/// Provides the minimal functionality required to create a checksum calculation module.
///
public abstract class ChecksumModule
{
///
/// The name of this checksum calculation module.
///
public abstract string Name { get; }
private long mvarValue = 0;
///
/// The current value of the checksum being calculated.
///
public virtual long Value { get { return mvarValue; } protected set { mvarValue = value; } }
///
/// Calculates the checksum based on the given input.
///
/// The array of bytes used as input to the checksum calculation routine.
/// A that represents the checksum of the given input.
public long Calculate(byte[] input)
{
Reset();
Update(input);
return Value;
}
///
/// Resets the checksum as if no update was ever called.
///
public virtual void Reset()
{
mvarValue = 0;
}
///
/// Updates the checksum with the bytes taken from the array.
///
/// The array of bytes used as input to the checksum calculation routine.
public void Update(byte[] buffer)
{
if (buffer == null) throw new ArgumentNullException("buffer");
Update(buffer, 0, buffer.Length);
}
///
/// Updates the checksum with a count of bytes taken from the array beginning at offset
/// .
///
/// The array of bytes used as input to the checksum calculation routine.
/// The offset into from which calculation starts.
/// The number of bytes to use in the checksum calculation.
public abstract void Update(byte[] buffer, int offset, int count);
///
/// Calculates the checksum based on the given input.
///
/// The value used as input to the checksum calculation routine.
public abstract void Update(int input);
}
}