mirror of
https://github.com/restic/restic.git
synced 2025-12-04 03:38:25 +00:00
Rename crypto functions and constants
This commit is contained in:
@@ -17,7 +17,7 @@ import (
|
||||
var testLargeCrypto = flag.Bool("test.largecrypto", false, "also test crypto functions with large payloads")
|
||||
|
||||
func TestEncryptDecrypt(t *testing.T) {
|
||||
k := crypto.GenerateRandomKeys()
|
||||
k := crypto.GenerateKey()
|
||||
|
||||
tests := []int{5, 23, 2<<18 + 23, 1 << 20}
|
||||
if *testLargeCrypto {
|
||||
@@ -43,7 +43,7 @@ func TestEncryptDecrypt(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSmallBuffer(t *testing.T) {
|
||||
k := crypto.GenerateRandomKeys()
|
||||
k := crypto.GenerateKey()
|
||||
|
||||
size := 600
|
||||
data := make([]byte, size)
|
||||
@@ -65,7 +65,7 @@ func TestLargeEncrypt(t *testing.T) {
|
||||
t.SkipNow()
|
||||
}
|
||||
|
||||
k := crypto.GenerateRandomKeys()
|
||||
k := crypto.GenerateKey()
|
||||
|
||||
for _, size := range []int{chunker.MaxSize, chunker.MaxSize + 1, chunker.MaxSize + 1<<20} {
|
||||
data := make([]byte, size)
|
||||
@@ -75,7 +75,7 @@ func TestLargeEncrypt(t *testing.T) {
|
||||
_, err = io.ReadFull(f, data)
|
||||
OK(t, err)
|
||||
|
||||
ciphertext := make([]byte, size+crypto.CiphertextExtension)
|
||||
ciphertext := make([]byte, size+crypto.Extension)
|
||||
n, err := crypto.Encrypt(k, ciphertext, data)
|
||||
OK(t, err)
|
||||
|
||||
@@ -90,7 +90,7 @@ func BenchmarkEncryptWriter(b *testing.B) {
|
||||
size := 8 << 20 // 8MiB
|
||||
rd := RandomReader(23, size)
|
||||
|
||||
k := crypto.GenerateRandomKeys()
|
||||
k := crypto.GenerateKey()
|
||||
|
||||
b.ResetTimer()
|
||||
b.SetBytes(int64(size))
|
||||
@@ -108,8 +108,8 @@ func BenchmarkEncrypt(b *testing.B) {
|
||||
size := 8 << 20 // 8MiB
|
||||
data := make([]byte, size)
|
||||
|
||||
k := crypto.GenerateRandomKeys()
|
||||
buf := make([]byte, len(data)+crypto.CiphertextExtension)
|
||||
k := crypto.GenerateKey()
|
||||
buf := make([]byte, len(data)+crypto.Extension)
|
||||
|
||||
b.ResetTimer()
|
||||
b.SetBytes(int64(size))
|
||||
@@ -123,9 +123,9 @@ func BenchmarkEncrypt(b *testing.B) {
|
||||
func BenchmarkDecryptReader(b *testing.B) {
|
||||
size := 8 << 20 // 8MiB
|
||||
buf := Random(23, size)
|
||||
k := crypto.GenerateRandomKeys()
|
||||
k := crypto.GenerateKey()
|
||||
|
||||
ciphertext := make([]byte, len(buf)+crypto.CiphertextExtension)
|
||||
ciphertext := make([]byte, len(buf)+crypto.Extension)
|
||||
_, err := crypto.Encrypt(k, ciphertext, buf)
|
||||
OK(b, err)
|
||||
|
||||
@@ -145,7 +145,7 @@ func BenchmarkDecryptReader(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkEncryptDecryptReader(b *testing.B) {
|
||||
k := crypto.GenerateRandomKeys()
|
||||
k := crypto.GenerateKey()
|
||||
|
||||
size := 8 << 20 // 8MiB
|
||||
rd := RandomReader(23, size)
|
||||
@@ -176,7 +176,7 @@ func BenchmarkDecrypt(b *testing.B) {
|
||||
size := 8 << 20 // 8MiB
|
||||
data := make([]byte, size)
|
||||
|
||||
k := crypto.GenerateRandomKeys()
|
||||
k := crypto.GenerateKey()
|
||||
|
||||
ciphertext := restic.GetChunkBuf("BenchmarkDecrypt")
|
||||
defer restic.FreeChunkBuf("BenchmarkDecrypt", ciphertext)
|
||||
@@ -196,7 +196,7 @@ func BenchmarkDecrypt(b *testing.B) {
|
||||
}
|
||||
|
||||
func TestEncryptStreamWriter(t *testing.T) {
|
||||
k := crypto.GenerateRandomKeys()
|
||||
k := crypto.GenerateKey()
|
||||
|
||||
tests := []int{5, 23, 2<<18 + 23, 1 << 20}
|
||||
if *testLargeCrypto {
|
||||
@@ -215,7 +215,7 @@ func TestEncryptStreamWriter(t *testing.T) {
|
||||
OK(t, err)
|
||||
OK(t, wr.Close())
|
||||
|
||||
l := len(data) + crypto.CiphertextExtension
|
||||
l := len(data) + crypto.Extension
|
||||
Assert(t, len(ciphertext.Bytes()) == l,
|
||||
"wrong ciphertext length: expected %d, got %d",
|
||||
l, len(ciphertext.Bytes()))
|
||||
@@ -230,7 +230,7 @@ func TestEncryptStreamWriter(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDecryptStreamReader(t *testing.T) {
|
||||
k := crypto.GenerateRandomKeys()
|
||||
k := crypto.GenerateKey()
|
||||
|
||||
tests := []int{5, 23, 2<<18 + 23, 1 << 20}
|
||||
if *testLargeCrypto {
|
||||
@@ -242,14 +242,14 @@ func TestDecryptStreamReader(t *testing.T) {
|
||||
_, err := io.ReadFull(RandomReader(42, size), data)
|
||||
OK(t, err)
|
||||
|
||||
ciphertext := make([]byte, size+crypto.CiphertextExtension)
|
||||
ciphertext := make([]byte, size+crypto.Extension)
|
||||
|
||||
// encrypt with default function
|
||||
n, err := crypto.Encrypt(k, ciphertext, data)
|
||||
OK(t, err)
|
||||
Assert(t, n == len(data)+crypto.CiphertextExtension,
|
||||
Assert(t, n == len(data)+crypto.Extension,
|
||||
"wrong number of bytes returned after encryption: expected %d, got %d",
|
||||
len(data)+crypto.CiphertextExtension, n)
|
||||
len(data)+crypto.Extension, n)
|
||||
|
||||
rd, err := crypto.DecryptFrom(k, bytes.NewReader(ciphertext))
|
||||
OK(t, err)
|
||||
@@ -264,7 +264,7 @@ func TestDecryptStreamReader(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEncryptWriter(t *testing.T) {
|
||||
k := crypto.GenerateRandomKeys()
|
||||
k := crypto.GenerateKey()
|
||||
|
||||
tests := []int{5, 23, 2<<18 + 23, 1 << 20}
|
||||
if *testLargeCrypto {
|
||||
@@ -285,7 +285,7 @@ func TestEncryptWriter(t *testing.T) {
|
||||
|
||||
ciphertext := buf.Bytes()
|
||||
|
||||
l := len(data) + crypto.CiphertextExtension
|
||||
l := len(data) + crypto.Extension
|
||||
Assert(t, len(ciphertext) == l,
|
||||
"wrong ciphertext length: expected %d, got %d",
|
||||
l, len(ciphertext))
|
||||
|
||||
Reference in New Issue
Block a user