public static byte[] ComputeHash(byte[] buffer, HashType type, HashSource source) { if (CryptoConfig.AllowOnlyFipsAlgorithms && source != HashSource.SystemNetFips) { throw new SecurityException( "This environment restricts hash algorithms to only those that are FIPS certified."); } switch (source) { case HashSource.SystemNetFips: return(FipsHash(type, buffer)); case HashSource.SodiumCore: return(SodiumHash(type, buffer)); case HashSource.NSec: return(NSecHash(type, buffer)); case HashSource.SystemNetManaged: return(ManagedHash(type, buffer)); default: throw new ArgumentOutOfRangeException(nameof(source), source, null); } }
public Reference(string archiveName, HashSource[] hashesSorted, MemoryStream strings) { this.archiveName = archiveName; this.hashesSorted = hashesSorted; this.strings = strings; }
public bool TryFindHash(Hash hash, out HashSource hashSource, out string path) { int hashIndex = Array.BinarySearch(hashesSorted, new HashSource() { Hash = hash }); if (hashIndex >= 0) { hashSource = hashesSorted[hashIndex]; // Get the path path = GetString(hashSource.Path); hashSource.Path = -1; if (path.StartsWith(@"\")) path = archiveName + path; return true; } else { // Not found hashSource = new HashSource(); path = string.Empty; return false; } }
int WriteToBuffer(Hash hash, Block block) { if (WriteBuffer.Length + block.Length > Settings.MaxZipEntrySize) { FlushBuffer(false); } HashSource hashSource = new HashSource() { Hash = hash, Path = -1, Offset = (int)WriteBuffer.Length, Length = block.Length, }; WriteBuffer.Write(block.Buffer, block.Offset, block.Length); hashes.Add(hashSource); int hashIndex = hashes.Count - 1; HashIndexesForPatching.Add(hashIndex); return hashIndex; }