Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
number571 committed Jan 8, 2025
1 parent db25e83 commit f74c40c
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 10 deletions.
3 changes: 1 addition & 2 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/number571/go-peer/pkg/crypto/hashing"
"github.com/number571/go-peer/pkg/crypto/random"
"github.com/number571/go-peer/pkg/crypto/symmetric"
"github.com/number571/go-peer/pkg/encoding"
"github.com/number571/go-peer/pkg/message/layer2"
"github.com/number571/go-peer/pkg/payload/joiner"
)
Expand Down Expand Up @@ -148,7 +147,7 @@ func (p *sClient) DecryptMessage(pMapPubKeys asymmetric.IMapPubKeys, pMsg []byte
)

// Get public key from map by pkid (hash)
sPubKey := pMapPubKeys.GetPubKey(encoding.HexEncode(pkid))
sPubKey := pMapPubKeys.GetPubKey(pkid)
if sPubKey == nil {
return nil, nil, ErrDecodePublicKey
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/crypto/asymmetric/map_pubkeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package asymmetric

import (
"sync"

"github.com/number571/go-peer/pkg/encoding"
)

var (
Expand All @@ -25,11 +27,11 @@ func NewMapPubKeys(pPubKeys ...IPubKey) IMapPubKeys {
}

// Check the existence of a friend in the list by the public key.
func (p *sMapPubKeys) GetPubKey(pHash string) IPubKey {
func (p *sMapPubKeys) GetPubKey(pHash []byte) IPubKey {
p.fMutex.RLock()
defer p.fMutex.RUnlock()

pubKey, ok := p.fMapping[pHash]
pubKey, ok := p.fMapping[encoding.HexEncode(pHash)]
if !ok {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/crypto/asymmetric/map_pubkeys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestMapPubKeys(t *testing.T) {
}

mapping := NewMapPubKeys(pubKeys...)
pkHash := pubKeys[1].GetHasher().ToString()
pkHash := pubKeys[1].GetHasher().ToBytes()
if pk := mapping.GetPubKey(pkHash); pk == nil {
t.Error("get invalid pub key")
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/crypto/asymmetric/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

type IMapPubKeys interface {
GetPubKey(string) IPubKey
GetPubKey([]byte) IPubKey
DelPubKey(IPubKey)
SetPubKey(IPubKey)
}
Expand Down
2 changes: 1 addition & 1 deletion test/result/badge_codelines.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions test/result/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f74c40c

Please sign in to comment.