From 9eaa24ea65299c49aea80cdd77764ec14aaad906 Mon Sep 17 00:00:00 2001 From: James Elliott Date: Mon, 10 Jun 2024 09:14:00 +1000 Subject: [PATCH] feat: refactor --- metadata/decode.go | 2 +- metadata/doc.go | 2 ++ metadata/metadata.go | 2 +- metadata/providers/cached/doc.go | 5 ++--- metadata/providers/cached/util.go | 5 +++-- metadata/providers/memory/doc.go | 5 ++--- metadata/providers/memory/provider.go | 1 + protocol/attestation_tpm_test.go | 2 +- protocol/base64_test.go | 5 +++-- 9 files changed, 16 insertions(+), 13 deletions(-) create mode 100644 metadata/doc.go diff --git a/metadata/decode.go b/metadata/decode.go index f290012..896e417 100644 --- a/metadata/decode.go +++ b/metadata/decode.go @@ -74,7 +74,7 @@ func (d *Decoder) Parse(payload *PayloadJSON) (metadata *Metadata, err error) { } if n := len(metadata.Unparsed); n != 0 && !d.ignoreEntryParsingErrors { - return metadata, fmt.Errorf("error occured parsing metadata: %d entries had errors during parsing", n) + return metadata, fmt.Errorf("error occurred parsing metadata: %d entries had errors during parsing", n) } return metadata, nil diff --git a/metadata/doc.go b/metadata/doc.go new file mode 100644 index 0000000..7db8c71 --- /dev/null +++ b/metadata/doc.go @@ -0,0 +1,2 @@ +// Package metadata handles metadata validation instrumentation. +package metadata diff --git a/metadata/metadata.go b/metadata/metadata.go index 58dfb4b..194a6fe 100644 --- a/metadata/metadata.go +++ b/metadata/metadata.go @@ -368,7 +368,7 @@ func (j StatementJSON) Parse() (statement Statement, err error) { if len(j.AaGUID) != 0 { if aaguid, err = uuid.Parse(j.AaGUID); err != nil { - return statement, fmt.Errorf("error occurred parsing statement with description '%s': error occured parsing AAGUID value: %w", j.Description, err) + return statement, fmt.Errorf("error occurred parsing statement with description '%s': error occurred parsing AAGUID value: %w", j.Description, err) } } diff --git a/metadata/providers/cached/doc.go b/metadata/providers/cached/doc.go index ca370b4..cb18e91 100644 --- a/metadata/providers/cached/doc.go +++ b/metadata/providers/cached/doc.go @@ -1,9 +1,8 @@ -package cached - -// The cached package handles a metadata.Provider implementation that both downloads and caches the MDS3 blob. This +// Package cached handles a metadata.Provider implementation that both downloads and caches the MDS3 blob. This // effectively is the recommended provider in most instances as it's fairly robust. Alternatively we suggest // implementing a similar provider that leverages the memory.Provider as an underlying element. // // This provider only specifically performs updates at the time it's initialized. It has no automatic update // functionality. This may change in the future however if you want this functionality at this time we recommend making // your own implementation. +package cached diff --git a/metadata/providers/cached/util.go b/metadata/providers/cached/util.go index 7d401ac..98d7dad 100644 --- a/metadata/providers/cached/util.go +++ b/metadata/providers/cached/util.go @@ -1,10 +1,11 @@ package cached import ( - "github.com/go-webauthn/webauthn/metadata" - "github.com/go-webauthn/webauthn/metadata/providers/memory" "io" "os" + + "github.com/go-webauthn/webauthn/metadata" + "github.com/go-webauthn/webauthn/metadata/providers/memory" ) func doTruncateCopyAndSeekStart(f *os.File, rc io.ReadCloser) (err error) { diff --git a/metadata/providers/memory/doc.go b/metadata/providers/memory/doc.go index 95c077d..bc2679f 100644 --- a/metadata/providers/memory/doc.go +++ b/metadata/providers/memory/doc.go @@ -1,5 +1,4 @@ -package memory - -// The memory package handles a metadata.Provider implementation that solely exists in memory. It's intended as a basis +// Package memory handles a metadata.Provider implementation that solely exists in memory. It's intended as a basis // for other providers and generally not recommended to use directly unless you're implementing your own logic to handle // the download and potential caching of the MDS3 blob yourself. +package memory diff --git a/metadata/providers/memory/provider.go b/metadata/providers/memory/provider.go index 052b7e9..7eef9da 100644 --- a/metadata/providers/memory/provider.go +++ b/metadata/providers/memory/provider.go @@ -3,6 +3,7 @@ package memory import ( "context" "fmt" + "github.com/google/uuid" "github.com/go-webauthn/webauthn/metadata" diff --git a/protocol/attestation_tpm_test.go b/protocol/attestation_tpm_test.go index 3f33763..d8f6a4e 100644 --- a/protocol/attestation_tpm_test.go +++ b/protocol/attestation_tpm_test.go @@ -11,12 +11,12 @@ import ( "crypto/x509/pkix" "encoding/asn1" "encoding/binary" - "github.com/stretchr/testify/require" "math/big" "testing" "github.com/google/go-tpm/legacy/tpm2" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/go-webauthn/webauthn/protocol/webauthncbor" "github.com/go-webauthn/webauthn/protocol/webauthncose" diff --git a/protocol/base64_test.go b/protocol/base64_test.go index 2540a54..6ec2132 100644 --- a/protocol/base64_test.go +++ b/protocol/base64_test.go @@ -4,10 +4,11 @@ import ( "encoding/base64" "encoding/json" "fmt" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "strings" "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestBase64UnmarshalJSON(t *testing.T) {