Skip to content

Commit

Permalink
Remove base64 helper functions (#6583)
Browse files Browse the repository at this point in the history
These helpers are only called in one place each, and provide no real
value via abstraction. Also, they're performing gymnastics in order to
be able to use `base64.URLEncoding`, instead of simply using
`base64.RawURLEncoding`.
  • Loading branch information
aarongable authored Jan 13, 2023
1 parent 8bc4005 commit 3003746
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions core/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,22 +379,9 @@ func (authz *Authorization) SolvedBy() (*AcmeChallenge, error) {
// with stripped padding.
type JSONBuffer []byte

// URL-safe base64 encode that strips padding
func base64URLEncode(data []byte) string {
var result = base64.URLEncoding.EncodeToString(data)
return strings.TrimRight(result, "=")
}

// URL-safe base64 decoder that adds padding
func base64URLDecode(data string) ([]byte, error) {
var missing = (4 - len(data)%4) % 4
data += strings.Repeat("=", missing)
return base64.URLEncoding.DecodeString(data)
}

// MarshalJSON encodes a JSONBuffer for transmission.
func (jb JSONBuffer) MarshalJSON() (result []byte, err error) {
return json.Marshal(base64URLEncode(jb))
return json.Marshal(base64.RawURLEncoding.EncodeToString(jb))
}

// UnmarshalJSON decodes a JSONBuffer to an object.
Expand All @@ -404,7 +391,7 @@ func (jb *JSONBuffer) UnmarshalJSON(data []byte) (err error) {
if err != nil {
return err
}
*jb, err = base64URLDecode(str)
*jb, err = base64.RawURLEncoding.DecodeString(strings.TrimRight(str, "="))
return
}

Expand Down

0 comments on commit 3003746

Please sign in to comment.