forked from TrueCloudLab/neoneo-go
crypto: add nil check for PublicKeys Copy()
Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
This commit is contained in:
parent
df2a56908b
commit
7c8d2c3ec5
2 changed files with 7 additions and 1 deletions
|
@ -78,8 +78,12 @@ func (keys PublicKeys) Contains(pKey *PublicKey) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
// Copy returns a copy of keys.
|
||||
// Copy returns a shallow copy of the PublicKeys slice. It creates a new slice with the same elements,
|
||||
// but does not perform a deep copy of the elements themselves.
|
||||
func (keys PublicKeys) Copy() PublicKeys {
|
||||
if keys == nil {
|
||||
return nil
|
||||
}
|
||||
res := make(PublicKeys, len(keys))
|
||||
copy(res, keys)
|
||||
return res
|
||||
|
|
|
@ -40,6 +40,8 @@ func TestEncodeDecodePublicKey(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPublicKeys_Copy(t *testing.T) {
|
||||
require.Nil(t, (PublicKeys)(nil).Copy())
|
||||
|
||||
pubs := make(PublicKeys, 5)
|
||||
for i := range pubs {
|
||||
priv, err := NewPrivateKey()
|
||||
|
|
Loading…
Reference in a new issue