Add isZeroKey() procedures.
This commit is contained in:
parent
1c2c88cb32
commit
ac8cb31178
|
@ -318,3 +318,17 @@ proc signRawMessage*(data: openarray[byte], seckey: PrivateKey,
|
|||
nil, nil) != 1:
|
||||
return(EthKeysStatus.Error)
|
||||
return(EthKeysStatus.Success)
|
||||
|
||||
proc isZeroKey*(seckey: PrivateKey): bool =
|
||||
## Check if private key `seckey` contains only 0 bytes.
|
||||
result = true
|
||||
for i in seckey.data:
|
||||
if i != byte(0):
|
||||
result = false
|
||||
|
||||
proc isZeroKey*(pubkey: PublicKey): bool =
|
||||
## Check if public key `pubkey` contains only 0 bytes.
|
||||
result = true
|
||||
for i in pubkey.data:
|
||||
if i != byte(0):
|
||||
result = false
|
||||
|
|
|
@ -253,3 +253,15 @@ suite "ECC/ECDSA/ECDHE tests suite":
|
|||
ecdhAgree(aliceSecret, bobPublic, secret1) == Success
|
||||
ecdhAgree(bobSecret, alicePublic, secret2) == Success
|
||||
secret1 == secret2
|
||||
|
||||
test "isZeroKey() checks":
|
||||
var seckey1: PrivateKey
|
||||
var pubkey1: PublicKey
|
||||
var seckey2 = newPrivateKey()
|
||||
var pubkey2 = seckey2.getPublicKey()
|
||||
|
||||
check:
|
||||
seckey1.isZeroKey() == true
|
||||
pubkey1.isZeroKey() == true
|
||||
seckey2.isZeroKey() == false
|
||||
pubkey2.isZeroKey() == false
|
||||
|
|
Loading…
Reference in New Issue