diff --git a/SabreTools.Hashing/Aaru.Checksums/Native.cs b/SabreTools.Hashing/Aaru.Checksums/Native.cs deleted file mode 100644 index bcd7973..0000000 --- a/SabreTools.Hashing/Aaru.Checksums/Native.cs +++ /dev/null @@ -1,83 +0,0 @@ -// /*************************************************************************** -// Aaru Data Preservation Suite -// ---------------------------------------------------------------------------- -// -// Filename : Native.cs -// Author(s) : Natalia Portillo -// -// Component : Checksums. -// -// --[ Description ] ---------------------------------------------------------- -// -// Checks that Aaru.Checksums.Native library is available and usable. -// -// --[ 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 . -// -// ---------------------------------------------------------------------------- -// Copyright © 2011-2023 Natalia Portillo -// ****************************************************************************/ - -using System.Runtime.InteropServices; - -namespace Aaru.Checksums; - -/// Handles native implementations of compression algorithms -public static class Native -{ - static bool _checked; - static bool _supported; - - /// Set to return native as never supported - public static bool ForceManaged { get; set; } - - /// - /// If set to true the native library was found and loaded correctly and its reported version is - /// compatible. - /// - public static bool IsSupported - { - get - { - if(ForceManaged) - return false; - - if(_checked) - return _supported; - - ulong version; - _checked = true; - - try - { - version = get_acn_version(); - } - catch - { - _supported = false; - - return false; - } - - // TODO: Check version compatibility - _supported = version >= 0x06000000; - - return _supported; - } - } - - [DllImport("libAaru.Checksums.Native", SetLastError = true)] - static extern ulong get_acn_version(); -} \ No newline at end of file diff --git a/SabreTools.Hashing/Aaru.Helpers/BigEndianBitConverter.cs b/SabreTools.Hashing/Aaru.Helpers/BigEndianBitConverter.cs deleted file mode 100644 index 28bc8cb..0000000 --- a/SabreTools.Hashing/Aaru.Helpers/BigEndianBitConverter.cs +++ /dev/null @@ -1,331 +0,0 @@ -// /*************************************************************************** -// Aaru Data Preservation Suite -// ---------------------------------------------------------------------------- -// -// Filename : BigEndianBitConverter.cs -// Author(s) : Natalia Portillo -// -// Component : Helpers. -// -// --[ Description ] ---------------------------------------------------------- -// -// Override of System.BitConverter that knows how to handle big-endian. -// -// --[ 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 . -// -// ---------------------------------------------------------------------------- -// Copyright © 2011-2023 Natalia Portillo -// ****************************************************************************/ - -using System; - -namespace Aaru.Helpers -{ - /// - /// Converts base data types to an array of bytes, and an array of bytes to base data types. All info taken from - /// the meta data of System.BitConverter. This implementation allows for Endianness consideration. - /// - public static class BigEndianBitConverter - { - /// Converts the specified double-precision floating point number to a 64-bit signed integer. - /// The number to convert. - /// A 64-bit signed integer whose value is equivalent to value. - /// It is not currently implemented - public static long DoubleToInt64Bits(double value) => throw new NotImplementedException(); - - /// Returns the specified Boolean value as an array of bytes. - /// A Boolean value. - /// An array of bytes with length 1. - public static byte[] GetBytes(bool value) => Reverse(BitConverter.GetBytes(value)); - - /// Returns the specified Unicode character value as an array of bytes. - /// A character to convert. - /// An array of bytes with length 2. - public static byte[] GetBytes(char value) => Reverse(BitConverter.GetBytes(value)); - - /// Returns the specified double-precision floating point value as an array of bytes. - /// The number to convert. - /// An array of bytes with length 8. - public static byte[] GetBytes(double value) => Reverse(BitConverter.GetBytes(value)); - - /// Returns the specified single-precision floating point value as an array of bytes. - /// The number to convert. - /// An array of bytes with length 4. - public static byte[] GetBytes(float value) => Reverse(BitConverter.GetBytes(value)); - - /// Returns the specified 32-bit signed integer value as an array of bytes. - /// The number to convert. - /// An array of bytes with length 4. - public static byte[] GetBytes(int value) => Reverse(BitConverter.GetBytes(value)); - - /// Returns the specified 64-bit signed integer value as an array of bytes. - /// The number to convert. - /// An array of bytes with length 8. - public static byte[] GetBytes(long value) => Reverse(BitConverter.GetBytes(value)); - - /// Returns the specified 16-bit signed integer value as an array of bytes. - /// The number to convert. - /// An array of bytes with length 2. - public static byte[] GetBytes(short value) => Reverse(BitConverter.GetBytes(value)); - - /// Returns the specified 32-bit unsigned integer value as an array of bytes. - /// The number to convert. - /// An array of bytes with length 4. - public static byte[] GetBytes(uint value) => Reverse(BitConverter.GetBytes(value)); - - /// Returns the specified 64-bit unsigned integer value as an array of bytes. - /// The number to convert. - /// An array of bytes with length 8. - public static byte[] GetBytes(ulong value) => Reverse(BitConverter.GetBytes(value)); - - /// Returns the specified 16-bit unsigned integer value as an array of bytes. - /// The number to convert. - /// An array of bytes with length 2. - public static byte[] GetBytes(ushort value) => Reverse(BitConverter.GetBytes(value)); - - /// Converts the specified 64-bit signed integer to a double-precision floating point number. - /// The number to convert. - /// A double-precision floating point number whose value is equivalent to value. - public static double Int64BitsToDouble(long value) => throw new NotImplementedException(); - - /// Returns a Boolean value converted from one byte at a specified position in a byte array. - /// An array of bytes. - /// The starting position within value. - /// true if the byte at in value is nonzero; otherwise, false. - /// value is null. - /// - /// is less than zero or greater than the - /// length of value minus 1. - /// - public static bool ToBoolean(byte[] value, int startIndex) => throw new NotImplementedException(); - - /// Returns a Unicode character converted from two bytes at a specified position in a byte array. - /// An array. - /// The starting position within value. - /// A character formed by two bytes beginning at . - /// equals the length of value minus 1. - /// value is null. - /// - /// is less than zero or greater than the - /// length of value minus 1. - /// - public static char ToChar(byte[] value, int startIndex) => throw new NotImplementedException(); - - /// - /// Returns a double-precision floating point number converted from eight bytes at a specified position in a byte - /// array. - /// - /// An array of bytes. - /// The starting position within value. - /// A double precision floating point number formed by eight bytes beginning at . - /// - /// is greater than or equal to the length of value - /// minus 7, and is less than or equal to the length of value minus 1. - /// - /// value is null. - /// - /// is less than zero or greater than the - /// length of value minus 1. - /// - public static double ToDouble(byte[] value, int startIndex) => throw new NotImplementedException(); - - /// Returns a 16-bit signed integer converted from two bytes at a specified position in a byte array. - /// An array of bytes. - /// The starting position within value. - /// A 16-bit signed integer formed by two bytes beginning at . - /// equals the length of value minus 1. - /// value is null. - /// - /// startIndex is less than zero or greater than the length of value - /// minus 1. - /// - public static short ToInt16(byte[] value, int startIndex) => - BitConverter.ToInt16(Reverse(value), value.Length - sizeof(short) - startIndex); - - /// Returns a 32-bit signed integer converted from four bytes at a specified position in a byte array. - /// An array of bytes. - /// The starting position within value. - /// A 32-bit signed integer formed by four bytes beginning at . - /// - /// is greater than or equal to the length of value - /// minus 3, and is less than or equal to the length of value minus 1. - /// - /// value is null. - /// - /// startIndex is less than zero or greater than the length of value - /// minus 1. - /// - public static int ToInt32(byte[] value, int startIndex) => - BitConverter.ToInt32(Reverse(value), value.Length - sizeof(int) - startIndex); - - /// Returns a 64-bit signed integer converted from eight bytes at a specified position in a byte array. - /// An array of bytes. - /// The starting position within value. - /// A 64-bit signed integer formed by eight bytes beginning at . - /// - /// is greater than or equal to the length of value - /// minus 7, and is less than or equal to the length of value minus 1. - /// - /// value is null. - /// - /// is less than zero or greater than the - /// length of value minus 1. - /// - public static long ToInt64(byte[] value, int startIndex) => - BitConverter.ToInt64(Reverse(value), value.Length - sizeof(long) - startIndex); - - /// - /// Returns a single-precision floating point number converted from four bytes at a specified position in a byte - /// array. - /// - /// An array of bytes. - /// The starting position within value. - /// A single-precision floating point number formed by four bytes beginning at . - /// - /// is greater than or equal to the length of value - /// minus 3, and is less than or equal to the length of value minus 1. - /// - /// value is null. - /// - /// is less than zero or greater than the - /// length of value minus 1. - /// - public static float ToSingle(byte[] value, int startIndex) => - BitConverter.ToSingle(Reverse(value), value.Length - sizeof(float) - startIndex); - - /// - /// Converts the numeric value of each element of a specified array of bytes to its equivalent hexadecimal string - /// representation. - /// - /// An array of bytes. - /// - /// A System.String of hexadecimal pairs separated by hyphens, where each pair represents the corresponding - /// element in value; for example, "7F-2C-4A". - /// - /// value is null. - public static string ToString(byte[] value) => BitConverter.ToString(Reverse(value)); - - /// - /// Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal - /// string representation. - /// - /// An array of bytes. - /// The starting position within value. - /// - /// A System.String of hexadecimal pairs separated by hyphens, where each pair represents the corresponding - /// element in a subarray of value; for example, "7F-2C-4A". - /// - /// value is null. - /// - /// startIndex is less than zero or greater than the length of value - /// minus 1. - /// - public static string ToString(byte[] value, int startIndex) => - BitConverter.ToString(Reverse(value), startIndex); - - /// - /// Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal - /// string representation. - /// - /// An array of bytes. - /// The starting position within value. - /// The number of array elements in value to convert. - /// - /// A System.String of hexadecimal pairs separated by hyphens, where each pair represents the corresponding - /// element in a subarray of value; for example, "7F-2C-4A". - /// - /// value is null. - /// - /// startIndex or length is less than zero. -or- startIndex is greater - /// than zero and is greater than or equal to the length of value. - /// - /// - /// The combination of startIndex and length does not specify a position within - /// value; that is, the startIndex parameter is greater than the length of value minus the length parameter. - /// - public static string ToString(byte[] value, int startIndex, int length) => - BitConverter.ToString(Reverse(value), startIndex, length); - - /// Returns a 16-bit unsigned integer converted from two bytes at a specified position in a byte array. - /// The array of bytes. - /// The starting position within value. - /// A 16-bit unsigned integer formed by two bytes beginning at startIndex. - /// startIndex equals the length of value minus 1. - /// value is null. - /// - /// startIndex is less than zero or greater than the length of value - /// minus 1. - /// - public static ushort ToUInt16(byte[] value, int startIndex) => - BitConverter.ToUInt16(Reverse(value), value.Length - sizeof(ushort) - startIndex); - - /// Returns a 32-bit unsigned integer converted from four bytes at a specified position in a byte array. - /// An array of bytes. - /// The starting position within value. - /// A 32-bit unsigned integer formed by four bytes beginning at startIndex. - /// - /// startIndex is greater than or equal to the length of value minus 3, and is - /// less than or equal to the length of value minus 1. - /// - /// value is null. - /// - /// startIndex is less than zero or greater than the length of value - /// minus 1. - /// - public static uint ToUInt32(byte[] value, int startIndex) => - BitConverter.ToUInt32(Reverse(value), value.Length - sizeof(uint) - startIndex); - - /// Returns a 64-bit unsigned integer converted from eight bytes at a specified position in a byte array. - /// An array of bytes. - /// The starting position within value. - /// A 64-bit unsigned integer formed by the eight bytes beginning at startIndex. - /// - /// startIndex is greater than or equal to the length of value minus 7, and is - /// less than or equal to the length of value minus 1. - /// - /// value is null. - /// - /// startIndex is less than zero or greater than the length of value - /// minus 1. - /// - public static ulong ToUInt64(byte[] value, int startIndex) => - BitConverter.ToUInt64(Reverse(value), value.Length - sizeof(ulong) - startIndex); - - /// Converts a big endian byte array representation of a GUID into the .NET Guid structure - /// Byte array containing a GUID in big endian - /// Start of the byte array to process - /// Processed Guid - public static Guid ToGuid(byte[] value, int startIndex) => new Guid(ToUInt32(value, 0 + startIndex), - ToUInt16(value, 4 + startIndex), - ToUInt16(value, 6 + startIndex), - value[8 + startIndex + 0], - value[8 + startIndex + 1], - value[8 + startIndex + 2], - value[8 + startIndex + 3], - value[8 + startIndex + 5], - value[8 + startIndex + 5], - value[8 + startIndex + 6], - value[8 + startIndex + 7]); - - - // Additional helper method to replace single Linq use - private static T[] Reverse(T[] value) - { - Array.Reverse(value); - return value; - } - } -} \ No newline at end of file diff --git a/SabreTools.Hashing/Aaru.Helpers/Extensions.cs b/SabreTools.Hashing/Aaru.Helpers/Extensions.cs deleted file mode 100644 index 38332d2..0000000 --- a/SabreTools.Hashing/Aaru.Helpers/Extensions.cs +++ /dev/null @@ -1,72 +0,0 @@ -// /*************************************************************************** -// Aaru Data Preservation Suite -// ---------------------------------------------------------------------------- -// -// Filename : Extensions.cs -// Author(s) : Natalia Portillo -// -// Component : Helpers. -// -// --[ Description ] ---------------------------------------------------------- -// -// Provides class extensions. -// -// --[ 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 . -// -// ---------------------------------------------------------------------------- -// Copyright © 2011-2023 Natalia Portillo -// ****************************************************************************/ - -using System.IO; - -namespace Aaru.Helpers; - -public static class Extensions -{ - /// - /// When overridden in a derived class, reads a sequence of bytes from the current stream and advances the - /// position within the stream by the number of bytes read.
Guarantees the whole count of bytes is read or EOF is - /// found - ///
- /// Stream to extend - /// - /// An array of bytes. When this method returns, the buffer contains the specified byte array with the - /// values between and ( + - 1) replaced by the bytes - /// read from the current source. - /// - /// - /// The zero-based byte offset in at which to begin storing the data read from - /// the current stream. - /// - /// The maximum number of bytes to be read from the current stream. - /// - /// The total number of bytes read into the buffer. This can be less than the number of bytes requested if the end - /// of the stream has been reached. - /// - public static int EnsureRead(Stream s, byte[] buffer, int offset, int count) - { - var pos = 0; - int read; - - do - { - read = s.Read(buffer, pos + offset, count - pos); - pos += read; - } while(read > 0); - - return pos; - } -} \ No newline at end of file diff --git a/SabreTools.Hashing/SabreTools.Hashing.csproj b/SabreTools.Hashing/SabreTools.Hashing.csproj index defd39e..617c0ad 100644 --- a/SabreTools.Hashing/SabreTools.Hashing.csproj +++ b/SabreTools.Hashing/SabreTools.Hashing.csproj @@ -49,8 +49,4 @@ - - - - \ No newline at end of file