-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(protocol): trailing credential data skipped (#191)
This fixes an issue where the trailing data in the credential parsing functions would be ignored. This also adds some clarity documentation and cleanup to the ParseCredentialCreationResponse and ParseCredentialRequestResponseBody functions. Fixes #189
- Loading branch information
1 parent
f23bfd6
commit e5a5571
Showing
6 changed files
with
125 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package protocol | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"io" | ||
) | ||
|
||
func decodeBody(body io.Reader, v any) (err error) { | ||
decoder := json.NewDecoder(body) | ||
|
||
if err = decoder.Decode(v); err != nil { | ||
return err | ||
} | ||
|
||
_, err = decoder.Token() | ||
|
||
if !errors.Is(err, io.EOF) { | ||
return errors.New("The body contains trailing data") | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package protocol | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func AssertIsProtocolError(t *testing.T, err error, errType, errDetails, errInfo string) { | ||
var e *Error | ||
|
||
require.True(t, errors.As(err, &e)) | ||
|
||
assert.Equal(t, errType, e.Type) | ||
assert.Equal(t, errDetails, e.Details) | ||
assert.Equal(t, errInfo, e.DevInfo) | ||
} |