MCPcopy Index your code
hub / github.com/rclone/rclone / computeHashWithNonce

Method computeHashWithNonce

backend/crypt/crypt.go:784–809  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

782//
783// Note that we break lots of encapsulation in this function.
784func (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

Callers 2

ComputeHashMethod · 0.95
HashMethod · 0.80

Calls 8

CheckCloseFunction · 0.92
NewMultiHasherTypesFunction · 0.92
NewHashSetFunction · 0.92
newEncrypterMethod · 0.80
SumsMethod · 0.80
OpenMethod · 0.65
CopyMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected