diff --git a/backend/crypt/crypt.go b/backend/crypt/crypt.go index 002fbc8cc..8b6d38ad4 100644 --- a/backend/crypt/crypt.go +++ b/backend/crypt/crypt.go @@ -1049,6 +1049,10 @@ func (o *ObjectInfo) Hash(ctx context.Context, hash hash.Type) (string, error) { } // if this is wrapping a local object then we work out the hash if srcObj.Fs().Features().IsLocal { + if o.f.opt.NoDataEncryption { + // If no encryption, just return the hash of the underlying object + return srcObj.Hash(ctx, hash) + } // Read the data and encrypt it to calculate the hash fs.Debugf(o, "Computing %v hash of encrypted source", hash) return o.f.computeHashWithNonce(ctx, o.nonce, srcObj, hash) diff --git a/backend/crypt/crypt_internal_test.go b/backend/crypt/crypt_internal_test.go index 2f7f1f8b3..62adb4952 100644 --- a/backend/crypt/crypt_internal_test.go +++ b/backend/crypt/crypt_internal_test.go @@ -77,7 +77,11 @@ func testObjectInfo(t *testing.T, f *Fs, wrap bool) { enc, err := f.cipher.newEncrypter(inBuf, nil) require.NoError(t, err) nonce := enc.nonce // read the nonce at the start - _, err = io.Copy(&outBuf, enc) + if f.opt.NoDataEncryption { + _, err = outBuf.WriteString(contents) + } else { + _, err = io.Copy(&outBuf, enc) + } require.NoError(t, err) var oi fs.ObjectInfo = obj @@ -96,7 +100,12 @@ func testObjectInfo(t *testing.T, f *Fs, wrap bool) { assert.NotEqual(t, path, src.Remote()) // Test ObjectInfo.Hash - wantHash := md5.Sum(outBuf.Bytes()) + var wantHash [md5.Size]byte + if f.opt.NoDataEncryption { + wantHash = md5.Sum([]byte(contents)) + } else { + wantHash = md5.Sum(outBuf.Bytes()) + } gotHash, err := src.Hash(ctx, hash.MD5) require.NoError(t, err) assert.Equal(t, fmt.Sprintf("%x", wantHash), gotHash)