Optimize public/private keypair JSON encoding
This commit is contained in:
parent
c103c46561
commit
ff1b712f32
|
@ -166,7 +166,11 @@ func (k *PrivateKeyBytes) UnmarshalJSON(b []byte) error {
|
|||
}
|
||||
|
||||
func (k *PrivateKeyBytes) MarshalJSON() ([]byte, error) {
|
||||
return utils.MarshalJSON(k.String())
|
||||
var buf [PrivateKeySize*2 + 2]byte
|
||||
buf[0] = '"'
|
||||
buf[PrivateKeySize*2+1] = '"'
|
||||
hex.Encode(buf[1:], k[:])
|
||||
return buf[:], nil
|
||||
}
|
||||
|
||||
type PrivateKeySlice []byte
|
||||
|
@ -245,7 +249,11 @@ func (k *PrivateKeySlice) UnmarshalJSON(b []byte) error {
|
|||
}
|
||||
|
||||
func (k *PrivateKeySlice) MarshalJSON() ([]byte, error) {
|
||||
return utils.MarshalJSON(k.String())
|
||||
var buf [PrivateKeySize*2 + 2]byte
|
||||
buf[0] = '"'
|
||||
buf[PrivateKeySize*2+1] = '"'
|
||||
hex.Encode(buf[1:], (*k)[:])
|
||||
return buf[:], nil
|
||||
}
|
||||
|
||||
func deriveKeyExchangeSecretCofactor(private *PrivateKeyScalar, public *PublicKeyPoint) *PublicKeyPoint {
|
||||
|
|
|
@ -149,7 +149,11 @@ func (k *PublicKeyBytes) UnmarshalJSON(b []byte) error {
|
|||
}
|
||||
|
||||
func (k *PublicKeyBytes) MarshalJSON() ([]byte, error) {
|
||||
return utils.MarshalJSON(k.String())
|
||||
var buf [PublicKeySize*2 + 2]byte
|
||||
buf[0] = '"'
|
||||
buf[PublicKeySize*2+1] = '"'
|
||||
hex.Encode(buf[1:], k[:])
|
||||
return buf[:], nil
|
||||
}
|
||||
|
||||
type PublicKeySlice []byte
|
||||
|
@ -215,5 +219,9 @@ func (k *PublicKeySlice) UnmarshalJSON(b []byte) error {
|
|||
}
|
||||
|
||||
func (k *PublicKeySlice) MarshalJSON() ([]byte, error) {
|
||||
return utils.MarshalJSON(k.String())
|
||||
var buf [PublicKeySize*2 + 2]byte
|
||||
buf[0] = '"'
|
||||
buf[PublicKeySize*2+1] = '"'
|
||||
hex.Encode(buf[1:], (*k)[:])
|
||||
return buf[:], nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue