Skip to content
This repository was archived by the owner on Jul 12, 2025. It is now read-only.

Commit f59ff94

Browse files
sravottojackc
authored andcommitted
UnmarshalJSON: removing hex decode
1 parent fd427c0 commit f59ff94

File tree

3 files changed

+8
-20
lines changed

3 files changed

+8
-20
lines changed

json_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -489,10 +489,10 @@ func TestJSONUnmarshalQuery(t *testing.T) {
489489
}
490490

491491
func TestJSONUnmarshalSASLInitialResponse(t *testing.T) {
492-
data := []byte(`{"Type":"SASLInitialResponse", "AuthMechanism":"SCRAM-SHA-256", "Data": "6D"}`)
492+
data := []byte(`{"Type":"SASLInitialResponse", "AuthMechanism":"SCRAM-SHA-256", "Data": "abc"}`)
493493
want := SASLInitialResponse{
494494
AuthMechanism: "SCRAM-SHA-256",
495-
Data: []byte{109},
495+
Data: []byte("abc"),
496496
}
497497

498498
var got SASLInitialResponse
@@ -505,8 +505,10 @@ func TestJSONUnmarshalSASLInitialResponse(t *testing.T) {
505505
}
506506

507507
func TestJSONUnmarshalSASLResponse(t *testing.T) {
508-
data := []byte(`{"Type":"SASLResponse","Message":"abc"}`)
509-
want := SASLResponse{}
508+
data := []byte(`{"Type":"SASLResponse","Data":"abc"}`)
509+
want := SASLResponse{
510+
Data: []byte("abc"),
511+
}
510512

511513
var got SASLResponse
512514
if err := json.Unmarshal(data, &got); err != nil {

sasl_initial_response.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package pgproto3
22

33
import (
44
"bytes"
5-
"encoding/hex"
65
"encoding/json"
76
"errors"
87

@@ -83,12 +82,6 @@ func (dst *SASLInitialResponse) UnmarshalJSON(data []byte) error {
8382
return err
8483
}
8584
dst.AuthMechanism = msg.AuthMechanism
86-
if msg.Data != "" {
87-
decoded, err := hex.DecodeString(msg.Data)
88-
if err != nil {
89-
return err
90-
}
91-
dst.Data = decoded
92-
}
85+
dst.Data = []byte(msg.Data)
9386
return nil
9487
}

sasl_response.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package pgproto3
22

33
import (
4-
"encoding/hex"
54
"encoding/json"
65

76
"github.com/jackc/pgio"
@@ -50,12 +49,6 @@ func (dst *SASLResponse) UnmarshalJSON(data []byte) error {
5049
if err := json.Unmarshal(data, &msg); err != nil {
5150
return err
5251
}
53-
if msg.Data != "" {
54-
decoded, err := hex.DecodeString(msg.Data)
55-
if err != nil {
56-
return err
57-
}
58-
dst.Data = decoded
59-
}
52+
dst.Data = []byte(msg.Data)
6053
return nil
6154
}

0 commit comments

Comments
 (0)