summaryrefslogtreecommitdiff
path: root/pkg/scrypto/pkcs5_test.go
diff options
context:
space:
mode:
authorJulien Dessaux2024-09-30 00:58:49 +0200
committerJulien Dessaux2024-09-30 01:00:59 +0200
commit4ff490806c826cf2da4c2291ed924f0a49383fce (patch)
tree6870f4883cd03a824095b969500f08fb59f04038 /pkg/scrypto/pkcs5_test.go
parentchore(tfstated): rename tfstate to tfstated (diff)
downloadtfstated-4ff490806c826cf2da4c2291ed924f0a49383fce.tar.gz
tfstated-4ff490806c826cf2da4c2291ed924f0a49383fce.tar.bz2
tfstated-4ff490806c826cf2da4c2291ed924f0a49383fce.zip
feat(tfstated): implement GET and POST methods, states are encrypted in a sqlite3 database
Diffstat (limited to 'pkg/scrypto/pkcs5_test.go')
-rw-r--r--pkg/scrypto/pkcs5_test.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/pkg/scrypto/pkcs5_test.go b/pkg/scrypto/pkcs5_test.go
new file mode 100644
index 0000000..8bd1a1d
--- /dev/null
+++ b/pkg/scrypto/pkcs5_test.go
@@ -0,0 +1,52 @@
+package scrypto
+
+import (
+ "slices"
+ "testing"
+)
+
+func TestPadPKCS5(t *testing.T) {
+ tests := []struct {
+ data []byte
+ want []byte
+ }{
+ {data: []byte(""), want: []byte("\x04\x04\x04\x04")},
+ {data: []byte("a"), want: []byte("a\x03\x03\x03")},
+ {data: []byte("ab"), want: []byte("ab\x02\x02")},
+ {data: []byte("abc"), want: []byte("abc\x01")},
+ {data: []byte("abcd"), want: []byte("abcd\x04\x04\x04\x04")},
+ {data: []byte("abcde"), want: []byte("abcde\x03\x03\x03")},
+ {data: []byte("abcdefgh"), want: []byte("abcdefgh\x04\x04\x04\x04")},
+ }
+ for _, tt := range tests {
+ got := PadPKCS5(tt.data, 4)
+ if slices.Compare(got, tt.want) != 0 {
+ t.Errorf("got %v, want %v", got, tt.want)
+ }
+ }
+}
+
+func TestUnpadPKCS5(t *testing.T) {
+ tests := []struct {
+ data []byte
+ want []byte
+ }{
+ {data: []byte("\x04\x04\x04\x04"), want: []byte("")},
+ {data: []byte("a\x03\x03\x03"), want: []byte("a")},
+ {data: []byte("ab\x02\x02"), want: []byte("ab")},
+ {data: []byte("abc\x01"), want: []byte("abc")},
+ {data: []byte("abcd\x04\x04\x04\x04"), want: []byte("abcd")},
+ {data: []byte("abcde\x03\x03\x03"), want: []byte("abcde")},
+ {data: []byte("abcdefgh\x04\x04\x04\x04"), want: []byte("abcdefgh")},
+ }
+ for _, tt := range tests {
+ got, err := UnpadPKCS5(tt.data, 4)
+ if err != nil {
+ t.Errorf("got err %+v while wanted %v", err, tt.want)
+ } else {
+ if slices.Compare(got, tt.want) != 0 {
+ t.Errorf("got %v, want %v", got, tt.want)
+ }
+ }
+ }
+}