Fix tests - were broken by the refactoring
This commit is contained in:
parent
9078a77850
commit
b0ee5258b1
@ -4,6 +4,8 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/rfjakob/gocryptfs/internal/toggledlog"
|
||||
)
|
||||
|
||||
func TestLoadV1(t *testing.T) {
|
||||
@ -33,7 +35,7 @@ func TestLoadV2(t *testing.T) {
|
||||
|
||||
func TestLoadV2PwdError(t *testing.T) {
|
||||
if !testing.Verbose() {
|
||||
Warn.Enabled = false
|
||||
toggledlog.Warn.Enabled = false
|
||||
}
|
||||
_, _, err := LoadConfFile("config_test/v2.conf", "wrongpassword")
|
||||
if err == nil {
|
||||
|
@ -2,6 +2,11 @@ package contentenc
|
||||
|
||||
import "github.com/rfjakob/gocryptfs/internal/cryptocore"
|
||||
|
||||
const (
|
||||
// Default plaintext block size
|
||||
DefaultBS = 4096
|
||||
)
|
||||
|
||||
type ContentEnc struct {
|
||||
// Cryptographic primitives
|
||||
cryptoCore *cryptocore.CryptoCore
|
||||
|
@ -2,6 +2,8 @@ package contentenc
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/rfjakob/gocryptfs/internal/cryptocore"
|
||||
)
|
||||
|
||||
type testRange struct {
|
||||
@ -20,8 +22,9 @@ func TestSplitRange(t *testing.T) {
|
||||
testRange{0, 65536},
|
||||
testRange{6654, 8945})
|
||||
|
||||
key := make([]byte, KEY_LEN)
|
||||
f := NewCryptFS(key, true, false, true)
|
||||
key := make([]byte, cryptocore.KeyLen)
|
||||
cc := cryptocore.New(key, false, true)
|
||||
f := New(cc, DefaultBS)
|
||||
|
||||
for _, r := range ranges {
|
||||
parts := f.ExplodePlainRange(r.offset, r.length)
|
||||
@ -31,7 +34,7 @@ func TestSplitRange(t *testing.T) {
|
||||
t.Errorf("Duplicate block number %d", p.BlockNo)
|
||||
}
|
||||
lastBlockNo = p.BlockNo
|
||||
if p.Length > DEFAULT_PLAINBS || p.Skip >= DEFAULT_PLAINBS {
|
||||
if p.Length > DefaultBS || p.Skip >= DefaultBS {
|
||||
t.Errorf("Test fail: n=%d, length=%d, offset=%d\n", p.BlockNo, p.Length, p.Skip)
|
||||
}
|
||||
}
|
||||
@ -47,8 +50,9 @@ func TestCiphertextRange(t *testing.T) {
|
||||
testRange{65444, 54},
|
||||
testRange{6654, 8945})
|
||||
|
||||
key := make([]byte, KEY_LEN)
|
||||
f := NewCryptFS(key, true, false, true)
|
||||
key := make([]byte, cryptocore.KeyLen)
|
||||
cc := cryptocore.New(key, false, true)
|
||||
f := New(cc, DefaultBS)
|
||||
|
||||
for _, r := range ranges {
|
||||
|
||||
@ -69,8 +73,9 @@ func TestCiphertextRange(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBlockNo(t *testing.T) {
|
||||
key := make([]byte, KEY_LEN)
|
||||
f := NewCryptFS(key, true, false, true)
|
||||
key := make([]byte, cryptocore.KeyLen)
|
||||
cc := cryptocore.New(key, false, true)
|
||||
f := New(cc, DefaultBS)
|
||||
|
||||
b := f.CipherOffToBlockNo(788)
|
||||
if b != 0 {
|
||||
|
@ -21,8 +21,6 @@ import (
|
||||
"github.com/rfjakob/gocryptfs/internal/configfile"
|
||||
)
|
||||
|
||||
const plainBS = 4096
|
||||
|
||||
type FS struct {
|
||||
pathfs.FileSystem // loopbackFileSystem, see go-fuse/fuse/pathfs/loopback.go
|
||||
args Args // Stores configuration arguments
|
||||
@ -40,7 +38,7 @@ type FS struct {
|
||||
func NewFS(args Args) *FS {
|
||||
|
||||
cryptoCore := cryptocore.New(args.Masterkey, args.OpenSSL, args.GCMIV128)
|
||||
contentEnc := contentenc.New(cryptoCore, plainBS)
|
||||
contentEnc := contentenc.New(cryptoCore, contentenc.DefaultBS)
|
||||
nameTransform := nametransform.New(cryptoCore, args.EMENames)
|
||||
|
||||
return &FS{
|
||||
|
@ -3,6 +3,8 @@ package nametransform
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/rfjakob/gocryptfs/internal/cryptocore"
|
||||
)
|
||||
|
||||
func TestEncryptPathNoIV(t *testing.T) {
|
||||
@ -11,8 +13,9 @@ func TestEncryptPathNoIV(t *testing.T) {
|
||||
s = append(s, "foo12312312312312312313123123123")
|
||||
s = append(s, "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890")
|
||||
|
||||
key := make([]byte, KEY_LEN)
|
||||
fs := NewCryptFS(key, true, false, true)
|
||||
key := make([]byte, cryptocore.KeyLen)
|
||||
cc := cryptocore.New(key, false, true)
|
||||
fs := New(cc, true)
|
||||
|
||||
for _, n := range s {
|
||||
c := fs.EncryptPathNoIV(n)
|
||||
@ -32,19 +35,16 @@ func TestPad16(t *testing.T) {
|
||||
s = append(s, []byte("12345678901234567"))
|
||||
s = append(s, []byte("12345678901234567abcdefg"))
|
||||
|
||||
key := make([]byte, KEY_LEN)
|
||||
fs := NewCryptFS(key, true, false, true)
|
||||
|
||||
for i := range s {
|
||||
orig := s[i]
|
||||
padded := fs.pad16(orig)
|
||||
padded := pad16(orig)
|
||||
if len(padded) <= len(orig) {
|
||||
t.Errorf("Padded length not bigger than orig: %d", len(padded))
|
||||
}
|
||||
if len(padded)%16 != 0 {
|
||||
t.Errorf("Length is not aligend: %d", len(padded))
|
||||
}
|
||||
unpadded, err := fs.unPad16(padded)
|
||||
unpadded, err := unPad16(padded)
|
||||
if err != nil {
|
||||
t.Error("unPad16 returned error:", err)
|
||||
}
|
||||
|
@ -12,15 +12,17 @@ import (
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"fmt"
|
||||
"github.com/rfjakob/gocryptfs/cryptfs"
|
||||
"github.com/spacemonkeygo/openssl"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/spacemonkeygo/openssl"
|
||||
|
||||
"github.com/rfjakob/gocryptfs/internal/cryptocore"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
|
||||
fmt.Printf("Benchmarking AES-GCM-%d with 4kB block size\n", cryptfs.KEY_LEN*8)
|
||||
fmt.Printf("Benchmarking AES-GCM-%d with 4kB block size\n", cryptocore.KeyLen*8)
|
||||
|
||||
r := m.Run()
|
||||
os.Exit(r)
|
||||
@ -30,7 +32,7 @@ func BenchmarkGoEnc4K(b *testing.B) {
|
||||
buf := make([]byte, 1024*4)
|
||||
b.SetBytes(int64(len(buf)))
|
||||
|
||||
var key [cryptfs.KEY_LEN]byte
|
||||
var key [cryptocore.KeyLen]byte
|
||||
var nonce [12]byte
|
||||
aes, _ := aes.NewCipher(key[:])
|
||||
aesgcm, _ := cipher.NewGCM(aes)
|
||||
@ -47,7 +49,7 @@ func BenchmarkGoDec4K(b *testing.B) {
|
||||
buf := make([]byte, 1024*4)
|
||||
b.SetBytes(int64(len(buf)))
|
||||
|
||||
var key [cryptfs.KEY_LEN]byte
|
||||
var key [cryptocore.KeyLen]byte
|
||||
var nonce [12]byte
|
||||
aes, _ := aes.NewCipher(key[:])
|
||||
aesgcm, _ := cipher.NewGCM(aes)
|
||||
@ -67,7 +69,7 @@ func BenchmarkOpensslEnc4K(b *testing.B) {
|
||||
buf := make([]byte, 1024*4)
|
||||
b.SetBytes(int64(len(buf)))
|
||||
|
||||
var key [cryptfs.KEY_LEN]byte
|
||||
var key [cryptocore.KeyLen]byte
|
||||
var nonce [12]byte
|
||||
|
||||
// This would be fileID + blockNo
|
||||
@ -79,7 +81,7 @@ func BenchmarkOpensslEnc4K(b *testing.B) {
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
ciphertext.Reset()
|
||||
ectx, err := openssl.NewGCMEncryptionCipherCtx(cryptfs.KEY_LEN*8, nil, key[:], nonce[:])
|
||||
ectx, err := openssl.NewGCMEncryptionCipherCtx(cryptocore.KeyLen*8, nil, key[:], nonce[:])
|
||||
if err != nil {
|
||||
b.FailNow()
|
||||
}
|
||||
@ -112,7 +114,7 @@ func BenchmarkOpensslDec4K(b *testing.B) {
|
||||
tag := buf[4096:]
|
||||
buf = buf[0:4096]
|
||||
|
||||
var key [cryptfs.KEY_LEN]byte
|
||||
var key [cryptocore.KeyLen]byte
|
||||
var nonce [12]byte
|
||||
|
||||
var plaintext bytes.Buffer
|
||||
@ -121,7 +123,7 @@ func BenchmarkOpensslDec4K(b *testing.B) {
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
plaintext.Reset()
|
||||
dctx, err := openssl.NewGCMDecryptionCipherCtx(cryptfs.KEY_LEN*8, nil, key[:], nonce[:])
|
||||
dctx, err := openssl.NewGCMDecryptionCipherCtx(cryptocore.KeyLen*8, nil, key[:], nonce[:])
|
||||
if err != nil {
|
||||
b.FailNow()
|
||||
}
|
||||
@ -144,12 +146,12 @@ func BenchmarkOpensslDec4K(b *testing.B) {
|
||||
|
||||
func makeOpensslCiphertext() []byte {
|
||||
buf := make([]byte, 1024*4)
|
||||
var key [cryptfs.KEY_LEN]byte
|
||||
var key [cryptocore.KeyLen]byte
|
||||
var nonce [12]byte
|
||||
var ciphertext bytes.Buffer
|
||||
var part []byte
|
||||
|
||||
ectx, _ := openssl.NewGCMEncryptionCipherCtx(cryptfs.KEY_LEN*8, nil, key[:], nonce[:])
|
||||
ectx, _ := openssl.NewGCMEncryptionCipherCtx(cryptocore.KeyLen*8, nil, key[:], nonce[:])
|
||||
part, _ = ectx.EncryptUpdate(buf)
|
||||
ciphertext.Write(part)
|
||||
part, _ = ectx.EncryptFinal()
|
||||
|
Loading…
Reference in New Issue
Block a user