public static IDictionary ComputeHashes()

in net/JetBrains.SignatureVerifier/src/HashUtil.cs [29:63]


    public static IDictionary<AlgorithmIdentifier, byte[]> ComputeHashes(Stream stream, ComputeHashInfo computeHashInfo, IEnumerable<string> algorithmNames)
      => ComputeHashes(stream, computeHashInfo, algorithmNames.Select(alg => new AlgorithmIdentifier(DigestUtilities.GetObjectIdentifier(alg))));

    public static IDictionary<AlgorithmIdentifier, byte[]> ComputeHashes(Stream stream, ComputeHashInfo computeHashInfo, IEnumerable<AlgorithmIdentifier> algorithmIdentifiers)
    {
      Dictionary<AlgorithmIdentifier, IDigest> algorithms = new Dictionary<AlgorithmIdentifier, IDigest>();

      foreach (var algorithmIdentifier in algorithmIdentifiers)
      {
        if (!algorithms.ContainsKey(algorithmIdentifier))
        {
          IDigest digest = DigestUtilities.GetDigest(algorithmIdentifier.Algorithm);
          algorithms.Add(algorithmIdentifier, digest);
        }
      }

      // Read from the stream and update the digest
      computeHashInfo.WalkOnHashRanges(stream, (buffer, index, count) =>
      {
        foreach (var digest in algorithms.Values)
          digest.BlockUpdate(buffer, index, count);
      });

      Dictionary<AlgorithmIdentifier, byte[]> hashes = new Dictionary<AlgorithmIdentifier, byte[]>();

      // Finalize hashes calculation
      foreach (var algorithm in algorithms)
      {
        byte[] hash = new byte[algorithm.Value.GetDigestSize()];
        algorithm.Value.DoFinal(hash, 0);
        hashes.Add(algorithm.Key, hash);
      }

      return hashes;
    }