small fixes in hex parsing.
This commit is contained in:
10
keys.go
10
keys.go
@@ -50,7 +50,9 @@ func SecretKeyFromHex(skh string) (SecretKey, error) {
|
|||||||
|
|
||||||
func MustSecretKeyFromHex(idh string) SecretKey {
|
func MustSecretKeyFromHex(idh string) SecretKey {
|
||||||
id := SecretKey{}
|
id := SecretKey{}
|
||||||
hex.Decode(id[:], unsafe.Slice(unsafe.StringData(idh), 64))
|
if _, err := hex.Decode(id[:], unsafe.Slice(unsafe.StringData(idh), 64)); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,11 +79,13 @@ func (pk *PubKey) UnmarshalJSON(buf []byte) error {
|
|||||||
if len(buf) != 66 {
|
if len(buf) != 66 {
|
||||||
return fmt.Errorf("must be a hex string of 64 characters")
|
return fmt.Errorf("must be a hex string of 64 characters")
|
||||||
}
|
}
|
||||||
_, err := hex.Decode(pk[:], buf[1:65])
|
if _, err := hex.Decode(pk[:], buf[1:65]); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if _, err := schnorr.ParsePubKey(pk[:]); err != nil {
|
if _, err := schnorr.ParsePubKey(pk[:]); err != nil {
|
||||||
return fmt.Errorf("pubkey is not valid %w", err)
|
return fmt.Errorf("pubkey is not valid %w", err)
|
||||||
}
|
}
|
||||||
return err
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func PubKeyFromHex(pkh string) (PubKey, error) {
|
func PubKeyFromHex(pkh string) (PubKey, error) {
|
||||||
|
|||||||
4
types.go
4
types.go
@@ -51,7 +51,9 @@ func IDFromHex(idh string) (ID, error) {
|
|||||||
|
|
||||||
func MustIDFromHex(idh string) ID {
|
func MustIDFromHex(idh string) ID {
|
||||||
id := ID{}
|
id := ID{}
|
||||||
hex.Decode(id[:], unsafe.Slice(unsafe.StringData(idh), 64))
|
if _, err := hex.Decode(id[:], unsafe.Slice(unsafe.StringData(idh), 64)); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user