aboutsummaryrefslogtreecommitdiff
path: root/ec_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'ec_test.go')
-rw-r--r--ec_test.go64
1 files changed, 64 insertions, 0 deletions
diff --git a/ec_test.go b/ec_test.go
new file mode 100644
index 0000000..b0874c6
--- /dev/null
+++ b/ec_test.go
@@ -0,0 +1,64 @@
+package ecookie
+
+import (
+ "encoding/json"
+ "testing"
+)
+
+type test struct {
+ Foo string
+ Bar string
+}
+
+const pattr string = "ecookie: --- %v --"
+
+const (
+ foo = "foo string"
+ bar = "bar string"
+)
+
+var key = []byte{
+ 0x11, 0x12, 0x13, 0x14,
+ 0x11, 0x12, 0x13, 0x14,
+ 0x11, 0x12, 0x13, 0x14,
+ 0x11, 0x12, 0x13, 0x14,
+}
+
+func TestEcookie(t *testing.T) {
+ enc, err := NewEncryptor(key)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ tx := &test{Foo: foo, Bar: bar}
+ bx := new(test)
+ bt, err := json.Marshal(tx)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ ct, err := enc.Encrypt(bt)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ t.Logf(pattr, string(ct))
+
+ dec, err := NewDecryptor(key)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ pt, err := dec.Decrypt(ct)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ if err := json.Unmarshal(pt, bx); err != nil {
+ t.Fatal(err)
+ }
+
+ if !(*tx == *bx) {
+ t.Error("error: tx != bx.. test failed")
+ }
+}

Snix LLC Git Repository Holder Copyright(C) 2022 All Rights Reserved Email To Snix.IR