Skip to content

Commit

Permalink
UnmarshalJSON: removing hex decode
Browse files Browse the repository at this point in the history
  • Loading branch information
sravotto authored and jackc committed Sep 10, 2022
1 parent fd427c0 commit f59ff94
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 20 deletions.
10 changes: 6 additions & 4 deletions json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,10 @@ func TestJSONUnmarshalQuery(t *testing.T) {
}

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

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

func TestJSONUnmarshalSASLResponse(t *testing.T) {
data := []byte(`{"Type":"SASLResponse","Message":"abc"}`)
want := SASLResponse{}
data := []byte(`{"Type":"SASLResponse","Data":"abc"}`)
want := SASLResponse{
Data: []byte("abc"),
}

var got SASLResponse
if err := json.Unmarshal(data, &got); err != nil {
Expand Down
9 changes: 1 addition & 8 deletions sasl_initial_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package pgproto3

import (
"bytes"
"encoding/hex"
"encoding/json"
"errors"

Expand Down Expand Up @@ -83,12 +82,6 @@ func (dst *SASLInitialResponse) UnmarshalJSON(data []byte) error {
return err
}
dst.AuthMechanism = msg.AuthMechanism
if msg.Data != "" {
decoded, err := hex.DecodeString(msg.Data)
if err != nil {
return err
}
dst.Data = decoded
}
dst.Data = []byte(msg.Data)
return nil
}
9 changes: 1 addition & 8 deletions sasl_response.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package pgproto3

import (
"encoding/hex"
"encoding/json"

"github.com/jackc/pgio"
Expand Down Expand Up @@ -50,12 +49,6 @@ func (dst *SASLResponse) UnmarshalJSON(data []byte) error {
if err := json.Unmarshal(data, &msg); err != nil {
return err
}
if msg.Data != "" {
decoded, err := hex.DecodeString(msg.Data)
if err != nil {
return err
}
dst.Data = decoded
}
dst.Data = []byte(msg.Data)
return nil
}

0 comments on commit f59ff94

Please sign in to comment.