Skip to content

Commit d00f3c8

Browse files
fix: secp256r1 json missing quotes (#20060)
1 parent eeefcf9 commit d00f3c8

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

crypto/keys/secp256r1/privkey.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ func (sk ecdsaSK) Marshal() ([]byte, error) {
6464
// MarshalJSON implements customProtobufType.
6565
func (sk ecdsaSK) MarshalJSON() ([]byte, error) {
6666
b64 := base64.StdEncoding.EncodeToString(sk.PrivKey.Bytes())
67-
return []byte(b64), nil
67+
return []byte("\"" + b64 + "\""), nil
6868
}
6969

7070
// UnmarshalJSON implements customProtobufType.
7171
func (sk *ecdsaSK) UnmarshalJSON(data []byte) error {
72-
bz, err := base64.StdEncoding.DecodeString(string(data))
72+
bz, err := base64.StdEncoding.DecodeString(string(data[1 : len(data)-1]))
7373
if err != nil {
7474
return err
7575
}

crypto/keys/secp256r1/pubkey.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,13 @@ func (pk ecdsaPK) Marshal() ([]byte, error) {
7373
// MarshalJSON implements customProtobufType.
7474
func (pk ecdsaPK) MarshalJSON() ([]byte, error) {
7575
b64 := base64.StdEncoding.EncodeToString(pk.PubKey.Bytes())
76-
return []byte(b64), nil
76+
return []byte("\"" + b64 + "\""), nil
7777
}
7878

7979
// UnmarshalJSON implements customProtobufType.
8080
func (pk *ecdsaPK) UnmarshalJSON(data []byte) error {
81-
bz, err := base64.StdEncoding.DecodeString(string(data))
81+
// the string is quoted so we need to remove them
82+
bz, err := base64.StdEncoding.DecodeString(string(data[1 : len(data)-1]))
8283
if err != nil {
8384
return err
8485
}

0 commit comments

Comments
 (0)