From dca408e85f0ae0b78c25661a594f1dabfb61f1c7 Mon Sep 17 00:00:00 2001 From: James Elliott Date: Sun, 29 Jan 2023 10:33:51 +1100 Subject: [PATCH] feat(protocol): ignore padding for base64 url encoding (#95) This adds support to ignore the trailing padding of base64 URL encoded bytes. Closes #93 --- protocol/attestation_test.go | 6 +++--- protocol/base64.go | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/protocol/attestation_test.go b/protocol/attestation_test.go index 2bee34d..cfe5e24 100644 --- a/protocol/attestation_test.go +++ b/protocol/attestation_test.go @@ -91,7 +91,7 @@ var testAttestationOptions = []string{ "user": { "name": "self", "displayName": "self", - "id": "2iEAAAAAAAAAAA" + "id": "2iEAAAAAAAAAAA==" }, "pubKeyCredParams": [ { @@ -116,7 +116,7 @@ var testAttestationOptions = []string{ "user": { "name": "flort", "displayName": "flort", - "id": "1DMAAAAAAAAAAA" + "id": "1DMAAAAAAAAAAA==" }, "pubKeyCredParams": [ { @@ -142,7 +142,7 @@ var testAttestationOptions = []string{ "user": { "name": "testuser1", "displayName": "testuser1", - "id": "1zMAAAAAAAAAAA" + "id": "1zMAAAAAAAAAAA==" }, "pubKeyCredParams": [ { diff --git a/protocol/base64.go b/protocol/base64.go index 99362b2..37a151b 100644 --- a/protocol/base64.go +++ b/protocol/base64.go @@ -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 {