diff --git a/CHANGELOG.md b/CHANGELOG.md
index b122f2b0..4beccebe 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,8 @@
### CHANGES
+- `pkg/crypto/asymmetric`: NewHasher(pubKey.ToBytes()) -> NewHasher(pubKey.ToString())
+- `pkg/crypto/hashing`: NewHasher([]byte) -> NewHasher(interface{})
- `cmd/tools`: deleted
- `build`: deleted
diff --git a/pkg/crypto/asymmetric/key.go b/pkg/crypto/asymmetric/key.go
index dc14b995..6b7e19a3 100644
--- a/pkg/crypto/asymmetric/key.go
+++ b/pkg/crypto/asymmetric/key.go
@@ -116,7 +116,7 @@ func NewPubKey(pKEM IKEMPubKey, pSigner IDSAPubKey) IPubKey {
fKEM: pKEM,
fSigner: pSigner,
}
- pubKeyChain.fHasher = hashing.NewHasher(pubKeyChain.ToBytes())
+ pubKeyChain.fHasher = hashing.NewHasher(pubKeyChain.ToString())
return pubKeyChain
}
@@ -152,7 +152,7 @@ func LoadPubKey(pKeychain interface{}) IPubKey {
}
func (p *sPubKey) GetHasher() hashing.IHasher {
- return p.fHasher
+ return p.fHasher // NewHasher(p.ToString())
}
func (p *sPubKey) ToBytes() []byte {
diff --git a/pkg/crypto/asymmetric/key_test.go b/pkg/crypto/asymmetric/key_test.go
index 0cc129a7..76ccdb4c 100644
--- a/pkg/crypto/asymmetric/key_test.go
+++ b/pkg/crypto/asymmetric/key_test.go
@@ -164,7 +164,7 @@ func TestPubKey(t *testing.T) {
return
}
- if keychain.GetHasher().ToString() != hashing.NewHasher(keychain.ToBytes()).ToString() {
+ if keychain.GetHasher().ToString() != hashing.NewHasher(keychain.ToString()).ToString() {
t.Error("got invalid keychain hasher")
return
}
diff --git a/pkg/crypto/asymmetric/map_pubkeys.go b/pkg/crypto/asymmetric/map_pubkeys.go
index 94f3906d..6a1bfe3c 100644
--- a/pkg/crypto/asymmetric/map_pubkeys.go
+++ b/pkg/crypto/asymmetric/map_pubkeys.go
@@ -27,7 +27,7 @@ func NewMapPubKeys(pPubKeys ...IPubKey) IMapPubKeys {
}
// Check the existence of a friend in the list by the public key.
-func (p *sMapPubKeys) GetPubKey(pHash []byte) IPubKey {
+func (p *sMapPubKeys) GetPubKey(pHash IPubKeyHash) IPubKey {
p.fMutex.RLock()
defer p.fMutex.RUnlock()
diff --git a/pkg/crypto/hashing/hashing.go b/pkg/crypto/hashing/hashing.go
index df96be99..cca0d8cb 100644
--- a/pkg/crypto/hashing/hashing.go
+++ b/pkg/crypto/hashing/hashing.go
@@ -21,8 +21,17 @@ type sSHA512Hasher struct {
fHashStr string
}
-func NewHasher(pData []byte) IHasher {
- s := sha512.Sum384(pData)
+func NewHasher(pData interface{}) IHasher {
+ var d []byte
+ switch x := pData.(type) {
+ case []byte:
+ d = x
+ case string:
+ d = []byte(x)
+ default:
+ panic("invalid type of data")
+ }
+ s := sha512.Sum384(d)
return &sSHA512Hasher{fHash: s[:]}
}
diff --git a/pkg/crypto/hashing/hashing_test.go b/pkg/crypto/hashing/hashing_test.go
index 1d9480be..f3ceae94 100644
--- a/pkg/crypto/hashing/hashing_test.go
+++ b/pkg/crypto/hashing/hashing_test.go
@@ -7,18 +7,21 @@ import (
func TestHasher(t *testing.T) {
t.Parallel()
- msg := []byte("hello, world!")
+ msg := "hello, world!"
+ msgBytes := []byte(msg)
+
+ if NewHasher(msg).ToString() != NewHasher(msgBytes).ToString() {
+ t.Fatal("hash invalid with same data")
+ }
hash := NewHasher(msg).ToString()
if hash != NewHasher(msg).ToString() {
- t.Error("hash is not determined")
- return
+ t.Fatal("hash is not determinated")
}
- msg[3] ^= 8
- if hash == NewHasher(msg).ToString() {
- t.Error("bit didn't change the result ")
- return
+ msgBytes[3] ^= 8
+ if hash == NewHasher(msgBytes).ToString() {
+ t.Fatal("bit didn't change the result")
}
}
diff --git a/test/result/badge_codelines.svg b/test/result/badge_codelines.svg
index a379333a..803da97d 100644
--- a/test/result/badge_codelines.svg
+++ b/test/result/badge_codelines.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 42c7bd31..7c3ba44f 100644
--- a/test/result/coverage.svg
+++ b/test/result/coverage.svg
@@ -7,7 +7,7 @@
>
-
+
-
+
-
+
-
+
-
+
client
@@ -65,12 +65,12 @@
-
+
crypto
@@ -78,12 +78,12 @@
-
+
encoding
@@ -91,12 +91,12 @@
-
+
logger
@@ -104,12 +104,12 @@
-
+
message
@@ -117,7 +117,7 @@
-
+
-
+
payload
@@ -143,12 +143,12 @@
-
+
state
@@ -156,12 +156,12 @@
-
+
storage
@@ -169,12 +169,12 @@
-
+
action.go
@@ -182,13 +182,13 @@
-
+
-
+
-
+
-
+
head.go
@@ -220,12 +220,12 @@
-
+
logger/log_builder.go
@@ -233,12 +233,12 @@
-
+
queue
@@ -246,12 +246,12 @@
-
+
settings.go
@@ -259,12 +259,12 @@
-
+
client.go
@@ -272,12 +272,12 @@
-
+
asymmetric
@@ -285,12 +285,12 @@
-
+
hashing
@@ -298,12 +298,18 @@
-
+
+
+
+
+
+
+
puzzle/puzzle.go
@@ -311,12 +317,12 @@
-
+
random/random.go
@@ -324,12 +330,12 @@
-
+
symmetric/symmetric.go
@@ -337,12 +343,12 @@
-
+
bytes.go
@@ -350,30 +356,30 @@
-
+
-
+
-
+
-
+
serialize_yaml.go
@@ -381,12 +387,12 @@
-
+
logger.go
@@ -394,18 +400,18 @@
-
+
-
+
layer1
@@ -413,12 +419,12 @@
-
+
layer2
@@ -426,12 +432,12 @@
-
+
conn
@@ -439,12 +445,12 @@
-
+
connkeeper
@@ -452,25 +458,25 @@
-
+
network.go
-
+
settings.go
@@ -478,12 +484,12 @@
-
+
joiner
@@ -491,12 +497,12 @@
-
+
payload32.go
@@ -504,12 +510,12 @@
-
+
payload64.go
@@ -517,12 +523,12 @@
-
+
state.go
@@ -530,12 +536,12 @@
-
+
cache/lru.go
@@ -543,12 +549,12 @@
-
+
database
@@ -556,18 +562,18 @@
-
+
-
+
queue.go
@@ -575,12 +581,12 @@
-
+
settings.go
@@ -588,12 +594,12 @@
-
+
dsa.go
@@ -601,12 +607,12 @@
-
+
kem.go
@@ -614,12 +620,12 @@
-
+
key.go
@@ -627,24 +633,31 @@
-
+
-
-
-
-
-
-
-
+
hashing.go
+
+
+
+
+
+
+
+hmac.go
@@ -652,18 +665,18 @@
-
+
-
+
message.go
@@ -671,12 +684,12 @@
-
+
settings.go
@@ -684,12 +697,12 @@
-
+
message.go
@@ -697,12 +710,12 @@
-
+
conn.go
@@ -710,12 +723,12 @@
-
+
settings.go
@@ -723,12 +736,12 @@
-
+
connkeeper.go
@@ -736,24 +749,24 @@
-
+
-
+
-
+
joiner32.go
@@ -761,12 +774,12 @@
-
+
database.go