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

Function testEncryptDecrypt

backend/crypt/cipher_test.go:1080–1101  ·  view source on GitHub ↗

Test encrypt decrypt with different buffer sizes

(t *testing.T, bufSize int, copySize int64)

Source from the content-addressed store, hash-verified

1078
1079// Test encrypt decrypt with different buffer sizes
1080func testEncryptDecrypt(t *testing.T, bufSize int, copySize int64) {
1081 c, err := newCipher(NameEncryptionStandard, "", "", true, nil)
1082 assert.NoError(t, err)
1083 c.cryptoRand = &zeroes{} // zero out the nonce
1084 buf := make([]byte, bufSize)
1085 source := newRandomSource(copySize)
1086 encrypted, err := c.newEncrypter(source, nil)
1087 assert.NoError(t, err)
1088 decrypted, err := c.newDecrypter(io.NopCloser(encrypted))
1089 assert.NoError(t, err)
1090 sink := newRandomSource(copySize)
1091 n, err := io.CopyBuffer(sink, decrypted, buf)
1092 assert.NoError(t, err)
1093 assert.Equal(t, copySize, n)
1094 blocks := copySize / blockSize
1095 if (copySize % blockSize) != 0 {
1096 blocks++
1097 }
1098 var expectedNonce = nonce{byte(blocks), byte(blocks >> 8), byte(blocks >> 16), byte(blocks >> 32)}
1099 assert.Equal(t, expectedNonce, encrypted.nonce)
1100 assert.Equal(t, expectedNonce, decrypted.nonce)
1101}
1102
1103func TestEncryptDecrypt1(t *testing.T) {
1104 testEncryptDecrypt(t, 1, 1e7)

Callers 5

TestEncryptDecrypt1Function · 0.85
TestEncryptDecrypt32Function · 0.85
TestEncryptDecrypt4096Function · 0.85
TestEncryptDecrypt65536Function · 0.85
TestEncryptDecrypt65537Function · 0.85

Calls 5

newCipherFunction · 0.85
newRandomSourceFunction · 0.85
newEncrypterMethod · 0.80
newDecrypterMethod · 0.80
EqualMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…