diff --git a/pkg/crypto/symmetric/list_ciphers.go b/pkg/crypto/symmetric/list_ciphers.go
index 4cce4361..cc6dabfc 100644
--- a/pkg/crypto/symmetric/list_ciphers.go
+++ b/pkg/crypto/symmetric/list_ciphers.go
@@ -10,14 +10,14 @@ var (
type sListCiphers struct {
fMtx *sync.RWMutex
- fMap map[string]interface{}
+ fMap map[string]struct{}
fList []ICipher
}
func NewListCiphers(pCiphers ...ICipher) IListCiphers {
listCiphers := &sListCiphers{
fMtx: &sync.RWMutex{},
- fMap: make(map[string]interface{}, 128),
+ fMap: make(map[string]struct{}, 128),
fList: make([]ICipher, 0, 128),
}
for _, v := range pCiphers {
diff --git a/pkg/crypto/symmetric/list_ciphers_test.go b/pkg/crypto/symmetric/list_ciphers_test.go
new file mode 100644
index 00000000..66e26bbb
--- /dev/null
+++ b/pkg/crypto/symmetric/list_ciphers_test.go
@@ -0,0 +1,53 @@
+package symmetric
+
+import (
+ "testing"
+
+ "github.com/number571/go-peer/pkg/crypto/random"
+)
+
+func TestListCiphersPanic(t *testing.T) {
+ t.Parallel()
+
+ defer func() {
+ if r := recover(); r == nil {
+ t.Error("nothing panics")
+ return
+ }
+ }()
+
+ cipher1 := NewCipherGCM(random.NewRandom().GetBytes(CCipherKeySize))
+ list := NewListCiphers(
+ NewCipherGCM(random.NewRandom().GetBytes(CCipherKeySize)),
+ )
+
+ _list := list.(*sListCiphers)
+ _list.fMap[cipher1.ToString()] = struct{}{}
+
+ _ = list.Del(cipher1)
+}
+
+func TestListCiphers(t *testing.T) {
+ t.Parallel()
+
+ cipher1 := NewCipherGCM(random.NewRandom().GetBytes(CCipherKeySize))
+ list := NewListCiphers(
+ cipher1,
+ NewCipherGCM(random.NewRandom().GetBytes(CCipherKeySize)),
+ NewCipherGCM(random.NewRandom().GetBytes(CCipherKeySize)),
+ )
+
+ if ok := list.Add(cipher1); ok {
+ t.Fatal("success add double cipher")
+ }
+ if ok := list.Del(cipher1); !ok {
+ t.Fatal("failed delete exist cipher")
+ }
+ if ok := list.Del(cipher1); ok {
+ t.Fatal("success delete unknown cipher")
+ }
+
+ if len(list.Get()) != 2 {
+ t.Fatal("invalid length of list")
+ }
+}
diff --git a/test/result/badge_coverage.svg b/test/result/badge_coverage.svg
index 65824887..9fd7bd14 100644
--- a/test/result/badge_coverage.svg
+++ b/test/result/badge_coverage.svg
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/test/result/coverage.svg b/test/result/coverage.svg
index bddf977b..e5914e4d 100644
--- a/test/result/coverage.svg
+++ b/test/result/coverage.svg
@@ -7,7 +7,7 @@
>
-
+
-
+
-
+
-
+
-
+
-
+
-
+
symmetric
@@ -419,7 +419,7 @@
-
+
-
+
list_ciphers.go