summaryrefslogtreecommitdiff
path: root/internal/pathiv/pathiv_test.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2017-05-28 20:43:48 +0200
committerJakob Unterwurzacher2017-05-30 17:04:46 +0200
commit9a217ce786581ee7ec18b27e46f0096763c85f9e (patch)
tree973b358e56e0df5a7749f8d714748b0c0710aaca /internal/pathiv/pathiv_test.go
parente43eb36da3e72cd0f59ac978cf76a94fa87ca7cd (diff)
pathiv: move block IV algorithm into this package
This was implemented in fusefrontend_reverse, but we need it in fusefrontend as well. Move the algorithm into pathiv.BlockIV().
Diffstat (limited to 'internal/pathiv/pathiv_test.go')
-rw-r--r--internal/pathiv/pathiv_test.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/internal/pathiv/pathiv_test.go b/internal/pathiv/pathiv_test.go
new file mode 100644
index 0000000..0cecba1
--- /dev/null
+++ b/internal/pathiv/pathiv_test.go
@@ -0,0 +1,28 @@
+package pathiv
+
+import (
+ "bytes"
+ "encoding/hex"
+ "testing"
+)
+
+// TestBlockIV makes sure we don't change the block iv derivation algorithm "BlockIV()"
+// inadvertedly.
+func TestBlockIV(t *testing.T) {
+ b0 := make([]byte, 16)
+ b0x := BlockIV(b0, 0)
+ if !bytes.Equal(b0, b0x) {
+ t.Errorf("b0x should be equal to b0")
+ }
+ b27 := BlockIV(b0, 0x27)
+ expected, _ := hex.DecodeString("00000000000000000000000000000027")
+ if !bytes.Equal(b27, expected) {
+ t.Error()
+ }
+ bff := bytes.Repeat([]byte{0xff}, 16)
+ b28 := BlockIV(bff, 0x28)
+ expected, _ = hex.DecodeString("ffffffffffffffff0000000000000027")
+ if !bytes.Equal(b28, expected) {
+ t.Errorf("\nhave=%s\nwant=%s", hex.EncodeToString(b28), hex.EncodeToString(expected))
+ }
+}