-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement struct extension mechanism and add extension points in places specified by https://www.ietf.org/archive/id/draft-ietf-rats-corim-02.html Extensions are implemented via Extensions object that allows registering user-defined structs are extensions. Fields from these user-defined structs are merged into the parent struct that embeds the Extensions object via some custom serialization code (this required updating the cbor dependency to v2.5.0, and go version to 1.19). Extensions also implements Viper*-like accessor methods for convenient access to the extension fields from the parent struct. (* see github.com/spf13/viper) Signed-off-by: Sergei Trofimov <[email protected]>
- Loading branch information
Showing
36 changed files
with
2,472 additions
and
44 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
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,51 @@ | ||
package comid | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"github.com/veraison/swid" | ||
) | ||
|
||
func Test_Comid_Extensions(t *testing.T) { | ||
c := NewComid() | ||
assert.Nil(t, c.GetExtensions()) | ||
assert.Equal(t, "", c.MustGetString("field-one")) | ||
|
||
err := c.Set("field-one", "foo") | ||
assert.EqualError(t, err, "extension not found: field-one") | ||
|
||
type ComidExt struct { | ||
FieldOne string `cbor:"-1,keyasint" json:"field-one"` | ||
} | ||
|
||
c.RegisterExtensions(&ComidExt{}) | ||
|
||
err = c.Set("field-one", "foo") | ||
assert.NoError(t, err) | ||
assert.Equal(t, "foo", c.MustGetString("-1")) | ||
} | ||
|
||
func Test_Comid_ToJSONPretty(t *testing.T) { | ||
c := NewComid() | ||
|
||
_, err := c.ToJSONPretty(" ") | ||
assert.EqualError(t, err, "tag-identity validation failed: empty tag-id") | ||
|
||
c.TagIdentity = TagIdentity{TagID: *swid.NewTagID("test"), TagVersion: 1} | ||
c.Triples = Triples{ReferenceValues: &[]ReferenceValue{}} | ||
|
||
expected := `{ | ||
"tag-identity": { | ||
"id": "test", | ||
"version": 1 | ||
}, | ||
"triples": { | ||
"reference-values": [] | ||
} | ||
}` | ||
v, err := c.ToJSONPretty(" ") | ||
require.NoError(t, err) | ||
assert.Equal(t, expected, string(v)) | ||
} |
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
Oops, something went wrong.