aboutsummaryrefslogtreecommitdiff
path: root/internal/contentenc
diff options
context:
space:
mode:
authorJakob Unterwurzacher2021-05-24 15:28:02 +0200
committerJakob Unterwurzacher2021-05-26 13:17:56 +0200
commit2a5ac3e9ba1fb3cdf2220524bc1633755092c794 (patch)
tree95b55fbc624afff81e2dd385b081a5041cda2716 /internal/contentenc
parent9695f0e524aa2debd173d676a8fd56ad26603c5a (diff)
tests: contentenc: add TestSizeToSize
TestSizeToSize tests CipherSizeToPlainSize and PlainSizeToCipherSize. Fails at the moment due to CipherSizeToPlainSize non-moniticity.
Diffstat (limited to 'internal/contentenc')
-rw-r--r--internal/contentenc/offsets_test.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/internal/contentenc/offsets_test.go b/internal/contentenc/offsets_test.go
new file mode 100644
index 0000000..4bc3762
--- /dev/null
+++ b/internal/contentenc/offsets_test.go
@@ -0,0 +1,52 @@
+package contentenc
+
+import (
+ "fmt"
+ "testing"
+
+ "github.com/rfjakob/gocryptfs/internal/cryptocore"
+)
+
+// TestSizeToSize tests CipherSizeToPlainSize and PlainSizeToCipherSize
+func TestSizeToSize(t *testing.T) {
+ key := make([]byte, cryptocore.KeyLen)
+ cc := cryptocore.New(key, cryptocore.BackendGoGCM, DefaultIVBits, true, false)
+ ce := New(cc, DefaultBS, false)
+
+ const rangeMax = 10000
+
+ var c2p [rangeMax]uint64
+ var p2c [rangeMax]uint64
+
+ // Calculate values
+ for i := range c2p {
+ c2p[i] = ce.CipherSizeToPlainSize(uint64(i))
+ p2c[i] = ce.PlainSizeToCipherSize(uint64(i))
+ }
+
+ // Print data table
+ fmt.Print("x\tToPlainSize\tToCipherSize\n")
+ for i := range c2p {
+ if i > 1 && i < rangeMax-1 {
+ // If the point before has value-1 and the point after has value+1,
+ // it is not interesting. Don't print it out.
+ if c2p[i] == c2p[i-1]+1 && p2c[i] == p2c[i-1]+1 && c2p[i+1] == c2p[i]+1 && p2c[i+1] == p2c[i]+1 {
+ continue
+ }
+ }
+ fmt.Printf("%d\t%d\t%d\n", i, c2p[i], p2c[i])
+ }
+
+ // Monotonicity check
+ for i := range c2p {
+ if i < 1 {
+ continue
+ }
+ if c2p[i-1] > c2p[i] {
+ t.Errorf("error: c2p is non-monotonic: c2p[%d]=%d c2p[%d]=%d ", i-1, c2p[i-1], i, c2p[i])
+ }
+ if p2c[i-1] > p2c[i] {
+ t.Errorf("error: p2c is non-monotonic: p2c[%d]=%d p2c[%d]=%d ", i-1, p2c[i-1], i, p2c[i])
+ }
+ }
+}