Skip to content

Commit

Permalink
feat(protocol): ignore padding for base64 url encoding (#95)
Browse files Browse the repository at this point in the history
This adds support to ignore the trailing padding of base64 URL encoded bytes.

Closes #93
  • Loading branch information
james-d-elliott committed Jan 28, 2023
1 parent 3d8dfc7 commit dca408e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions protocol/attestation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ var testAttestationOptions = []string{
"user": {
"name": "self",
"displayName": "self",
"id": "2iEAAAAAAAAAAA"
"id": "2iEAAAAAAAAAAA=="
},
"pubKeyCredParams": [
{
Expand All @@ -116,7 +116,7 @@ var testAttestationOptions = []string{
"user": {
"name": "flort",
"displayName": "flort",
"id": "1DMAAAAAAAAAAA"
"id": "1DMAAAAAAAAAAA=="
},
"pubKeyCredParams": [
{
Expand All @@ -142,7 +142,7 @@ var testAttestationOptions = []string{
"user": {
"name": "testuser1",
"displayName": "testuser1",
"id": "1zMAAAAAAAAAAA"
"id": "1zMAAAAAAAAAAA=="
},
"pubKeyCredParams": [
{
Expand Down
5 changes: 5 additions & 0 deletions protocol/base64.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ func (e *URLEncodedBase64) UnmarshalJSON(data []byte) error {
return nil
}

// TODO: Investigate this line. It is commented as trimming the leading spaces but appears to trim the leading and trailing double quotes instead.
// Trim the leading spaces
data = bytes.Trim(data, "\"")

// Trim the trailing equal characters.
data = bytes.TrimRight(data, "=")

out := make([]byte, base64.RawURLEncoding.DecodedLen(len(data)))
n, err := base64.RawURLEncoding.Decode(out, data)
if err != nil {
Expand Down

0 comments on commit dca408e

Please sign in to comment.