Skip to content

Commit

Permalink
refactor(profiles): rename GetProfile to GetProfileManifest for clarity
Browse files Browse the repository at this point in the history
Signed-off-by: Priyanshu Thapliyal <[email protected]>
  • Loading branch information
Priyanshuthapliyal2005 authored and setrofim committed Jan 20, 2025
1 parent de08a3a commit 834cb46
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
6 changes: 3 additions & 3 deletions corim/example_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ func Example_profile_marshal() {
panic(err)
}

profile, ok := GetProfile(profileID)
profileManifest, ok := GetProfileManifest(profileID)
if !ok {
log.Fatalf("profile %v not found", profileID)
}

myCorim := profile.GetUnsignedCorim()
myComid := profile.GetComid().
myCorim := profileManifest.GetUnsignedCorim()
myComid := profileManifest.GetComid().
SetLanguage("en-GB").
SetTagIdentity("example", 0).
// Adding an entity to the Entities collection also registers
Expand Down
28 changes: 14 additions & 14 deletions corim/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ func UnmarshalUnsignedCorimFromJSON(buf []byte) (*UnsignedCorim, error) {
func UnmarshalComidFromCBOR(buf []byte, profileID *eat.Profile) (*comid.Comid, error) {
var ret *comid.Comid

profile, ok := GetProfile(profileID)
profileManifest, ok := GetProfileManifest(profileID)
if ok {
ret = profile.GetComid()
ret = profileManifest.GetComid()
} else {
ret = comid.NewComid()
}
Expand All @@ -140,7 +140,7 @@ func GetSignedCorim(profileID *eat.Profile) *SignedCorim {
if profileID == nil {
ret = NewSignedCorim()
} else {
profile, ok := GetProfile(profileID)
profileManifest, ok := GetProfileManifest(profileID)
if !ok {
// unknown profile -- treat here like an unprofiled
// CoRIM. While the CoRIM spec states that unknown
Expand All @@ -153,7 +153,7 @@ func GetSignedCorim(profileID *eat.Profile) *SignedCorim {
// additional fields may not be registered.
ret = NewSignedCorim()
} else {
ret = profile.GetSignedCorim()
ret = profileManifest.GetSignedCorim()
}
}

Expand All @@ -169,7 +169,7 @@ func GetUnsignedCorim(profileID *eat.Profile) *UnsignedCorim {
if profileID == nil {
ret = NewUnsignedCorim()
} else {
profile, ok := GetProfile(profileID)
profileManifest, ok := GetProfileManifest(profileID)
if !ok {
// unknown profile -- treat here like an unprofiled
// CoRIM. While the CoRIM spec states that unknown
Expand All @@ -182,22 +182,22 @@ func GetUnsignedCorim(profileID *eat.Profile) *UnsignedCorim {
// additional fields may not be registered.
ret = NewUnsignedCorim()
} else {
ret = profile.GetUnsignedCorim()
ret = profileManifest.GetUnsignedCorim()
}
}

return ret
}

// Profile associates an EAT profile ID with a set of extensions. It allows
// ProfileManifest associates an EAT profile ID with a set of extensions. It allows
// obtaining new CoRIM and CoMID structures that had associated extensions
// registered.
type ProfileManifest struct {
ID *eat.Profile
MapExtensions extensions.Map
}

// GetComid returns a pointer to a new comid.Comid that had the Profile's
// GetComid returns a pointer to a new comid.Comid that had the ProfileManifest's
// extensions (if any) registered.
func (o *ProfileManifest) GetComid() *comid.Comid {
ret := comid.NewComid()
Expand All @@ -206,7 +206,7 @@ func (o *ProfileManifest) GetComid() *comid.Comid {
}

// GetUnsignedCorim returns a pointer to a new UnsignedCorim that had the
// Profile's extensions (if any) registered.
// ProfileManifest's extensions (if any) registered.
func (o *ProfileManifest) GetUnsignedCorim() *UnsignedCorim {
ret := NewUnsignedCorim()
ret.Profile = o.ID
Expand All @@ -215,7 +215,7 @@ func (o *ProfileManifest) GetUnsignedCorim() *UnsignedCorim {
}

// GetSignedCorim returns a pointer to a new SignedCorim that had the
// Profile's extensions (if any) registered.
// ProfileManifest's extensions (if any) registered.
func (o *ProfileManifest) GetSignedCorim() *SignedCorim {
ret := NewSignedCorim()
ret.UnsignedCorim.Profile = o.ID
Expand Down Expand Up @@ -288,10 +288,10 @@ func UnregisterProfile(id *eat.Profile) bool {
return false
}

// GetProfile returns the Profile associated with the specified ID, or an empty
// profile if no Profile has been registered for the id. The second return
// value indicates whether a profile for the ID has been found.
func GetProfile(id *eat.Profile) (ProfileManifest, bool) {
// GetProfileManifest returns the ProfileManifest associated with the specified ID, or an empty
// profileManifest if no ProfileManifest has been registered for the id. The second return
// value indicates whether a profileManifest for the ID has been found.
func GetProfileManifest(id *eat.Profile) (ProfileManifest, bool) {
if id == nil {
return ProfileManifest{}, false
}
Expand Down
24 changes: 12 additions & 12 deletions corim/profiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/veraison/eat"
)

func TestProfile_registration(t *testing.T) {
func TestProfileManifest_registration(t *testing.T) {
exts := extensions.NewMap()

err := RegisterProfile(&eat.Profile{}, exts)
Expand Down Expand Up @@ -40,11 +40,11 @@ func TestProfile_registration(t *testing.T) {
err = RegisterProfile(p2, exts)
assert.NoError(t, err)

prof, ok := GetProfile(p1)
prof, ok := GetProfileManifest(p1)
assert.True(t, ok)
assert.Equal(t, exts, prof.MapExtensions)

_, ok = GetProfile(&eat.Profile{})
_, ok = GetProfileManifest(&eat.Profile{})
assert.False(t, ok)

p3, err := eat.NewProfile("2.3.4")
Expand All @@ -61,30 +61,30 @@ func TestProfile_registration(t *testing.T) {
UnregisterProfile(p1)
}

func TestProfile_getters(t *testing.T) {
func TestProfileManifest_getters(t *testing.T) {
id, err := eat.NewProfile("1.2.3")
require.NoError(t, err)

profile := ProfileManifest{
profileManifest := ProfileManifest{
ID: id,
MapExtensions: extensions.NewMap().
Add(comid.ExtComid, &struct{}{}).
Add(ExtUnsignedCorim, &struct{}{}).
Add(ExtSigner, &struct{}{}),
}

c := profile.GetComid()
c := profileManifest.GetComid()
assert.NotNil(t, c.Extensions.IMapValue)

u := profile.GetUnsignedCorim()
u := profileManifest.GetUnsignedCorim()
assert.NotNil(t, u.Extensions.IMapValue)

s := profile.GetSignedCorim()
s := profileManifest.GetSignedCorim()
assert.NotNil(t, s.UnsignedCorim.Extensions.IMapValue)
assert.NotNil(t, s.Meta.Signer.Extensions.IMapValue)
}

func TestProfile_marshaling(t *testing.T) {
func TestProfileManifest_marshaling(t *testing.T) {
type corimExtensions struct {
Extension1 *string `cbor:"-1,keyasint,omitempty" json:"ext1,omitempty"`
}
Expand Down Expand Up @@ -117,7 +117,7 @@ func TestProfile_marshaling(t *testing.T) {
assert.Equal(t, profID, c.Profile)
assert.Equal(t, "foo", c.Extensions.MustGetString("Extension1"))

profile, ok := GetProfile(c.Profile)
profileManifest, ok := GetProfileManifest(c.Profile)
assert.True(t, ok)

cmd, err := UnmarshalComidFromCBOR(c.Tags[0], c.Profile)
Expand Down Expand Up @@ -158,11 +158,11 @@ func TestProfile_marshaling(t *testing.T) {
assert.Equal(t, profID, c.Profile)
assert.Equal(t, "foo", c.Extensions.MustGetString("Extension1"))

cmd = profile.GetComid()
cmd = profileManifest.GetComid()
err = cmd.FromJSON(testComidJSON)
assert.NoError(t, err)

cmd = profile.GetComid()
cmd = profileManifest.GetComid()
err = cmd.FromJSON(testComidWithExtensionsJSON)
assert.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion extensions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func main() {

Map extensions may be grouped into profiles. A profile is registered,
associating an `eat.Profile` with an `extensions.Map`. A registered profile can
be obtained by calling `corim.GetProfile()`, which returns a `corim.Profile`
be obtained by calling `corim.GetProfileManifest()`, which returns a `corim.ProfileManifest`
object which can be used to obtain `corim.UnsignedCorim`, `corim.SignedCorim`
and `comid.Comid` instances that have the associated extensions registered.
`corim.UnmarshalUnsignedCorimFromCBOR()` will automatically look up a
Expand Down

0 comments on commit 834cb46

Please sign in to comment.