// // ChecksumModule.cs - provides the minimal functionality required to create a checksum calculation module // // Author: // Michael Becker // // Copyright (c) 2020 Mike Becker's Software // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program 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 General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . using System; 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); } }