This commit is contained in:
number571 2026-05-22 12:13:06 +07:00
parent 499388d726
commit de99d3768a
4 changed files with 67 additions and 14 deletions

View File

@ -10,14 +10,14 @@ var (
type sListCiphers struct { type sListCiphers struct {
fMtx *sync.RWMutex fMtx *sync.RWMutex
fMap map[string]interface{} fMap map[string]struct{}
fList []ICipher fList []ICipher
} }
func NewListCiphers(pCiphers ...ICipher) IListCiphers { func NewListCiphers(pCiphers ...ICipher) IListCiphers {
listCiphers := &sListCiphers{ listCiphers := &sListCiphers{
fMtx: &sync.RWMutex{}, fMtx: &sync.RWMutex{},
fMap: make(map[string]interface{}, 128), fMap: make(map[string]struct{}, 128),
fList: make([]ICipher, 0, 128), fList: make([]ICipher, 0, 128),
} }
for _, v := range pCiphers { for _, v := range pCiphers {

View File

@ -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")
}
}

View File

@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="coverage: 96%"><title>coverage: 96%</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="96" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="61" height="20" fill="#555"/><rect x="61" width="35" height="20" fill="#97ca00"/><rect width="96" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="315" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="510">coverage</text><text x="315" y="140" transform="scale(.1)" fill="#fff" textLength="510">coverage</text><text aria-hidden="true" x="775" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">96%</text><text x="775" y="140" transform="scale(.1)" fill="#fff" textLength="250">96%</text></g></svg> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="coverage: 97%"><title>coverage: 97%</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="96" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="61" height="20" fill="#555"/><rect x="61" width="35" height="20" fill="#97ca00"/><rect width="96" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="315" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="510">coverage</text><text x="315" y="140" transform="scale(.1)" fill="#fff" textLength="510">coverage</text><text aria-hidden="true" x="775" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">97%</text><text x="775" y="140" transform="scale(.1)" fill="#fff" textLength="250">97%</text></g></svg>

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -7,7 +7,7 @@
> >
<g> <g>
<rect x="20.000000" y="20.000000" width="988.000000" height="600.000000" style="fill: rgb(6, 119, 63);opacity:1;fill-opacity:1.00;stroke:rgb(128,128,128);stroke-width:1px;stroke-opacity:1.00;" /> <rect x="20.000000" y="20.000000" width="988.000000" height="600.000000" style="fill: rgb(4, 115, 61);opacity:1;fill-opacity:1.00;stroke:rgb(128,128,128);stroke-width:1px;stroke-opacity:1.00;" />
<text <text
data-notex="1" data-notex="1"
@ -20,7 +20,7 @@
<g> <g>
<rect x="28.000000" y="41.600000" width="962.046875" height="570.400000" style="fill: rgb(6, 120, 63);opacity:1;fill-opacity:1.00;stroke:rgb(128,128,128);stroke-width:1px;stroke-opacity:1.00;" /> <rect x="28.000000" y="41.600000" width="962.046875" height="570.400000" style="fill: rgb(4, 115, 61);opacity:1;fill-opacity:1.00;stroke:rgb(128,128,128);stroke-width:1px;stroke-opacity:1.00;" />
<text <text
data-notex="1" data-notex="1"
@ -39,7 +39,7 @@
<g> <g>
<rect x="380.119512" y="63.200000" width="455.092998" height="286.478049" style="fill: rgb(3, 112, 59);opacity:1;fill-opacity:1.00;stroke:rgb(128,128,128);stroke-width:1px;stroke-opacity:1.00;" /> <rect x="380.119512" y="63.200000" width="455.092998" height="286.478049" style="fill: rgb(3, 114, 60);opacity:1;fill-opacity:1.00;stroke:rgb(128,128,128);stroke-width:1px;stroke-opacity:1.00;" />
<text <text
data-notex="1" data-notex="1"
@ -52,7 +52,7 @@
<g> <g>
<rect x="36.000000" y="63.200000" width="336.119512" height="540.800000" style="fill: rgb(11, 128, 67);opacity:1;fill-opacity:1.00;stroke:rgb(128,128,128);stroke-width:1px;stroke-opacity:1.00;" /> <rect x="36.000000" y="63.200000" width="336.119512" height="540.800000" style="fill: rgb(3, 113, 60);opacity:1;fill-opacity:1.00;stroke:rgb(128,128,128);stroke-width:1px;stroke-opacity:1.00;" />
<text <text
data-notex="1" data-notex="1"
@ -91,7 +91,7 @@
<g> <g>
<rect x="380.119512" y="357.678049" width="455.092998" height="246.321951" style="fill: rgb(8, 122, 64);opacity:1;fill-opacity:1.00;stroke:rgb(128,128,128);stroke-width:1px;stroke-opacity:1.00;" /> <rect x="380.119512" y="357.678049" width="455.092998" height="246.321951" style="fill: rgb(9, 124, 65);opacity:1;fill-opacity:1.00;stroke:rgb(128,128,128);stroke-width:1px;stroke-opacity:1.00;" />
<text <text
data-notex="1" data-notex="1"
@ -175,7 +175,7 @@
<g> <g>
<rect x="388.119512" y="84.800000" width="245.352699" height="256.878049" style="fill: rgb(1, 109, 57);opacity:1;fill-opacity:1.00;stroke:rgb(128,128,128);stroke-width:1px;stroke-opacity:1.00;" /> <rect x="388.119512" y="84.800000" width="245.352699" height="256.878049" style="fill: rgb(2, 111, 59);opacity:1;fill-opacity:1.00;stroke:rgb(128,128,128);stroke-width:1px;stroke-opacity:1.00;" />
<text <text
data-notex="1" data-notex="1"
@ -317,13 +317,13 @@
<g> <g>
<rect x="44.000000" y="484.579131" width="235.480910" height="111.420869" style="fill: rgb(89, 182, 95);opacity:1;fill-opacity:1.00;stroke:rgb(128,128,128);stroke-width:1px;stroke-opacity:1.00;" /> <rect x="44.000000" y="484.579131" width="235.480910" height="111.420869" style="fill: rgb(0, 104, 55);opacity:1;fill-opacity:1.00;stroke:rgb(128,128,128);stroke-width:1px;stroke-opacity:1.00;" />
<text <text
data-notex="1" data-notex="1"
text-anchor="start" text-anchor="start"
transform="translate(52.000000,500.179131) scale(1.000000)" transform="translate(52.000000,500.179131) scale(1.000000)"
style="font-family: Open Sans, verdana, arial, sans-serif !important; font-size: 12px; fill: rgb(0, 0, 0); fill-opacity: 1.00; white-space: pre;" style="font-family: Open Sans, verdana, arial, sans-serif !important; font-size: 12px; fill: rgb(255, 255, 255); fill-opacity: 1.00; white-space: pre;"
data-math="N">symmetric</text> data-math="N">symmetric</text>
</g> </g>
@ -419,7 +419,7 @@
<g> <g>
<rect x="388.119512" y="379.278049" width="208.487136" height="216.721951" style="fill: rgb(20, 142, 75);opacity:1;fill-opacity:1.00;stroke:rgb(128,128,128);stroke-width:1px;stroke-opacity:1.00;" /> <rect x="388.119512" y="379.278049" width="208.487136" height="216.721951" style="fill: rgb(22, 146, 77);opacity:1;fill-opacity:1.00;stroke:rgb(128,128,128);stroke-width:1px;stroke-opacity:1.00;" />
<text <text
data-notex="1" data-notex="1"
@ -691,13 +691,13 @@
<g> <g>
<rect x="52.000000" y="506.179131" width="76.576236" height="81.820869" style="fill: rgb(250, 253, 182);opacity:1;fill-opacity:1.00;stroke:rgb(128,128,128);stroke-width:1px;stroke-opacity:1.00;" /> <rect x="52.000000" y="506.179131" width="76.576236" height="81.820869" style="fill: rgb(0, 104, 55);opacity:1;fill-opacity:1.00;stroke:rgb(128,128,128);stroke-width:1px;stroke-opacity:1.00;" />
<text <text
data-notex="1" data-notex="1"
text-anchor="start" text-anchor="start"
transform="translate(60.000000,521.779131) scale(0.420668)" transform="translate(60.000000,521.779131) scale(0.420668)"
style="font-family: Open Sans, verdana, arial, sans-serif !important; font-size: 12px; fill: rgb(0, 0, 0); fill-opacity: 1.00; white-space: pre;" style="font-family: Open Sans, verdana, arial, sans-serif !important; font-size: 12px; fill: rgb(255, 255, 255); fill-opacity: 1.00; white-space: pre;"
data-math="N">list_ciphers.go</text> data-math="N">list_ciphers.go</text>
</g> </g>

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 32 KiB