1
0
mirror of https://github.com/gilbertchen/duplicacy synced 2025-12-14 07:13:30 +00:00

Run goimports on all source files

This commit is contained in:
Gilbert Chen
2017-09-20 23:07:43 -04:00
parent 978212fd75
commit 923cd0aa63
49 changed files with 13570 additions and 13631 deletions

View File

@@ -5,69 +5,68 @@
package duplicacy
import (
"testing"
"bytes"
crypto_rand "crypto/rand"
"math/rand"
"bytes"
crypto_rand "crypto/rand"
"math/rand"
"testing"
)
func TestChunk(t *testing.T) {
key := []byte("duplicacydefault")
key := []byte("duplicacydefault")
config := CreateConfig()
config.HashKey = key
config.IDKey = key
config.MinimumChunkSize = 100
config.CompressionLevel = DEFAULT_COMPRESSION_LEVEL
maxSize := 1000000
config := CreateConfig()
config.HashKey = key
config.IDKey = key
config.MinimumChunkSize = 100
config.CompressionLevel = DEFAULT_COMPRESSION_LEVEL
maxSize := 1000000
for i := 0; i < 500; i++ {
for i := 0; i < 500; i++ {
size := rand.Int() % maxSize
size := rand.Int() % maxSize
plainData := make([]byte, size)
crypto_rand.Read(plainData)
chunk := CreateChunk(config, true)
chunk.Reset(true)
chunk.Write(plainData)
plainData := make([]byte, size)
crypto_rand.Read(plainData)
chunk := CreateChunk(config, true)
chunk.Reset(true)
chunk.Write(plainData)
hash := chunk.GetHash()
id := chunk.GetID()
hash := chunk.GetHash()
id := chunk.GetID()
err := chunk.Encrypt(key, "")
if err != nil {
t.Errorf("Failed to encrypt the data: %v", err)
continue
}
err := chunk.Encrypt(key, "")
if err != nil {
t.Errorf("Failed to encrypt the data: %v", err)
continue
}
encryptedData := make([]byte, chunk.GetLength())
copy(encryptedData, chunk.GetBytes())
encryptedData := make([]byte, chunk.GetLength())
copy(encryptedData, chunk.GetBytes())
chunk.Reset(false)
chunk.Write(encryptedData)
err = chunk.Decrypt(key, "")
if err != nil {
t.Errorf("Failed to decrypt the data: %v", err)
continue
}
chunk.Reset(false)
chunk.Write(encryptedData)
err = chunk.Decrypt(key, "")
if err != nil {
t.Errorf("Failed to decrypt the data: %v", err)
continue
}
decryptedData := chunk.GetBytes()
decryptedData := chunk.GetBytes()
if hash != chunk.GetHash() {
t.Errorf("Original hash: %x, decrypted hash: %x", hash, chunk.GetHash())
}
if hash != chunk.GetHash() {
t.Errorf("Original hash: %x, decrypted hash: %x", hash, chunk.GetHash())
}
if id != chunk.GetID() {
t.Errorf("Original id: %s, decrypted hash: %s", id, chunk.GetID())
}
if id != chunk.GetID() {
t.Errorf("Original id: %s, decrypted hash: %s", id, chunk.GetID())
}
if bytes.Compare(plainData, decryptedData) != 0 {
t.Logf("orginal length: %d, decrypted length: %d", len(plainData), len(decryptedData))
t.Errorf("Original data:\n%x\nDecrypted data:\n%x\n", plainData, decryptedData)
}
if bytes.Compare(plainData, decryptedData) != 0 {
t.Logf("orginal length: %d, decrypted length: %d", len(plainData), len(decryptedData))
t.Errorf("Original data:\n%x\nDecrypted data:\n%x\n", plainData, decryptedData)
}
}
}
}