예제 #1
0
        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);
            }
        }
예제 #2
0
 public Reference(string archiveName, HashSource[] hashesSorted, MemoryStream strings)
 {
     this.archiveName = archiveName;
     this.hashesSorted = hashesSorted;
     this.strings = strings;
 }
예제 #3
0
        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;
            }
        }
예제 #4
0
        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;
        }