From 4ff490806c826cf2da4c2291ed924f0a49383fce Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Mon, 30 Sep 2024 00:58:49 +0200 Subject: feat(tfstated): implement GET and POST methods, states are encrypted in a sqlite3 database --- pkg/scrypto/pkcs5_test.go | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 pkg/scrypto/pkcs5_test.go (limited to 'pkg/scrypto/pkcs5_test.go') 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) + } + } + } +} -- cgit v1.2.3