computeHashWithNonce takes the nonce and encrypts the contents of src with it, and calculates the hash given by HashType on the fly Note that we break lots of encapsulation in this function.
(ctx context.Context, nonce nonce, src fs.Object, hashType hash.Type)
| 782 | // |
| 783 | // Note that we break lots of encapsulation in this function. |
| 784 | func (f *Fs) computeHashWithNonce(ctx context.Context, nonce nonce, src fs.Object, hashType hash.Type) (hashStr string, err error) { |
| 785 | // Open the src for input |
| 786 | in, err := src.Open(ctx) |
| 787 | if err != nil { |
| 788 | return "", fmt.Errorf("failed to open src: %w", err) |
| 789 | } |
| 790 | defer fs.CheckClose(in, &err) |
| 791 | |
| 792 | // Now encrypt the src with the nonce |
| 793 | out, err := f.cipher.newEncrypter(in, &nonce) |
| 794 | if err != nil { |
| 795 | return "", fmt.Errorf("failed to make encrypter: %w", err) |
| 796 | } |
| 797 | |
| 798 | // pipe into hash |
| 799 | m, err := hash.NewMultiHasherTypes(hash.NewHashSet(hashType)) |
| 800 | if err != nil { |
| 801 | return "", fmt.Errorf("failed to make hasher: %w", err) |
| 802 | } |
| 803 | _, err = io.Copy(m, out) |
| 804 | if err != nil { |
| 805 | return "", fmt.Errorf("failed to hash data: %w", err) |
| 806 | } |
| 807 | |
| 808 | return m.Sums()[hashType], nil |
| 809 | } |
| 810 | |
| 811 | // ComputeHash takes the nonce from o, and encrypts the contents of |
| 812 | // src with it, and calculates the hash given by HashType on the fly |
no test coverage detected