aboutsummaryrefslogtreecommitdiff
path: root/cryptfs/content_test.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2015-11-01 12:11:36 +0100
committerJakob Unterwurzacher2015-11-01 12:11:36 +0100
commit902babdf22199d73171716e643f1ffbb65e6fb48 (patch)
treec3194bce9fd9b4db0a569fca3b5041abd278be70 /cryptfs/content_test.go
parent14276c96328a1a1ad2b354c65d8db7fa720559e1 (diff)
Refactor ciphertext <-> plaintext offset translation functions
Move all the intelligence into the new file address_translation.go. That the calculations were spread out too much became apparent when adding the file header. This should make the code much easier to modify in the future.
Diffstat (limited to 'cryptfs/content_test.go')
-rw-r--r--cryptfs/content_test.go22
1 files changed, 13 insertions, 9 deletions
diff --git a/cryptfs/content_test.go b/cryptfs/content_test.go
index 4e1b447..37635f0 100644
--- a/cryptfs/content_test.go
+++ b/cryptfs/content_test.go
@@ -16,7 +16,7 @@ func TestSplitRange(t *testing.T) {
testRange{0, 10},
testRange{234, 6511},
testRange{65444, 54},
- testRange{0, 1024*1024},
+ testRange{0, 1024 * 1024},
testRange{0, 65536},
testRange{6654, 8945})
@@ -24,8 +24,8 @@ func TestSplitRange(t *testing.T) {
f := NewCryptFS(key, true)
for _, r := range ranges {
- parts := f.SplitRange(r.offset, r.length)
- var lastBlockNo uint64 = 1<<63
+ parts := f.ExplodePlainRange(r.offset, r.length)
+ var lastBlockNo uint64 = 1 << 63
for _, p := range parts {
if p.BlockNo == lastBlockNo {
t.Errorf("Duplicate block number %d", p.BlockNo)
@@ -51,11 +51,15 @@ func TestCiphertextRange(t *testing.T) {
f := NewCryptFS(key, true)
for _, r := range ranges {
- alignedOffset, alignedLength, skipBytes := f.CiphertextRange(r.offset, r.length)
+
+ blocks := f.ExplodePlainRange(r.offset, r.length)
+ alignedOffset, alignedLength := blocks[0].JointCiphertextRange(blocks)
+ skipBytes := blocks[0].Skip
+
if alignedLength < r.length {
t.Errorf("alignedLength=%s is smaller than length=%d", alignedLength, r.length)
}
- if (alignedOffset - HEADER_LEN)%f.cipherBS != 0 {
+ if (alignedOffset-HEADER_LEN)%f.cipherBS != 0 {
t.Errorf("alignedOffset=%d is not aligned", alignedOffset)
}
if r.offset%f.plainBS != 0 && skipBytes == 0 {
@@ -68,19 +72,19 @@ func TestBlockNo(t *testing.T) {
key := make([]byte, KEY_LEN)
f := NewCryptFS(key, true)
- b := f.BlockNoCipherOff(788)
+ b := f.CipherOffToBlockNo(788)
if b != 0 {
t.Errorf("actual: %d", b)
}
- b = f.BlockNoCipherOff(HEADER_LEN + f.CipherBS())
+ b = f.CipherOffToBlockNo(HEADER_LEN + f.cipherBS)
if b != 1 {
t.Errorf("actual: %d", b)
}
- b = f.BlockNoPlainOff(788)
+ b = f.PlainOffToBlockNo(788)
if b != 0 {
t.Errorf("actual: %d", b)
}
- b = f.BlockNoPlainOff(f.PlainBS())
+ b = f.PlainOffToBlockNo(f.plainBS)
if b != 1 {
t.Errorf("actual: %d", b)
}