Optimize public/private keypair JSON encoding

This commit is contained in:
DataHoarder 2023-05-27 15:38:26 +02:00
parent c103c46561
commit ff1b712f32
Signed by: DataHoarder
SSH key fingerprint: SHA256:OLTRf6Fl87G52SiR7sWLGNzlJt4WOX+tfI2yxo0z7xk
2 changed files with 20 additions and 4 deletions

View file

@ -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 {

View file

@ -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
}