diff --git a/comid/comid.go b/comid/comid.go index c62adde0..9521b1ce 100644 --- a/comid/comid.go +++ b/comid/comid.go @@ -140,9 +140,9 @@ func (o *Comid) AddEntity(name string, regID *string, roles ...Role) *Comid { } e := Entity{ - EntityName: MustNewStringEntityName(name), - RegID: uri, - Roles: rs, + Name: MustNewStringEntityName(name), + RegID: uri, + Roles: rs, } if o.Entities == nil { diff --git a/comid/entity.go b/comid/entity.go index cb1735c9..46760208 100644 --- a/comid/entity.go +++ b/comid/entity.go @@ -15,9 +15,9 @@ import ( // Entity stores an entity-map capable of CBOR and JSON serializations. type Entity struct { - EntityName *EntityName `cbor:"0,keyasint" json:"name"` - RegID *TaggedURI `cbor:"1,keyasint,omitempty" json:"regid,omitempty"` - Roles Roles `cbor:"2,keyasint" json:"roles"` + Name *EntityName `cbor:"0,keyasint" json:"name"` + RegID *TaggedURI `cbor:"1,keyasint,omitempty" json:"regid,omitempty"` + Roles Roles `cbor:"2,keyasint" json:"roles"` Extensions } @@ -41,13 +41,13 @@ func (o *Entity) GetExtensions() extensions.IValue { return o.Extensions.IValue } -// SetEntityName is used to set the EntityName field of Entity using supplied name -func (o *Entity) SetEntityName(name string) *Entity { +// SetName is used to set the Name field of Entity using supplied name +func (o *Entity) SetName(name string) *Entity { if o != nil { if name == "" { return nil } - o.EntityName = MustNewStringEntityName(name) + o.Name = MustNewStringEntityName(name) } return o } @@ -74,11 +74,11 @@ func (o *Entity) SetRoles(roles ...Role) *Entity { // Valid checks for validity of the fields within each Entity func (o Entity) Valid() error { - if o.EntityName == nil { + if o.Name == nil { return fmt.Errorf("invalid entity: empty entity-name") } - if err := o.EntityName.Valid(); err != nil { + if err := o.Name.Valid(); err != nil { return fmt.Errorf("invalid entity: %w", err) } diff --git a/comid/entity_test.go b/comid/entity_test.go index 10ff2e13..3feade43 100644 --- a/comid/entity_test.go +++ b/comid/entity_test.go @@ -22,7 +22,7 @@ func TestEntity_Valid_empty(t *testing.T) { func TestEntity_Valid_name_but_no_roles(t *testing.T) { tv := Entity{} - require.NotNil(t, tv.SetEntityName("ACME Ltd.")) + require.NotNil(t, tv.SetName("ACME Ltd.")) err := tv.Valid() assert.EqualError(t, err, "invalid entity: empty roles") @@ -31,7 +31,7 @@ func TestEntity_Valid_name_but_no_roles(t *testing.T) { func TestEntity_Valid_name_regid_but_no_roles(t *testing.T) { tv := Entity{} - require.NotNil(t, tv.SetEntityName("ACME Ltd.")) + require.NotNil(t, tv.SetName("ACME Ltd.")) require.NotNil(t, tv.SetRegID("https://acme.example")) err := tv.Valid() @@ -41,7 +41,7 @@ func TestEntity_Valid_name_regid_but_no_roles(t *testing.T) { func TestEntity_Valid_name_regid_and_roles(t *testing.T) { tv := Entity{} - require.NotNil(t, tv.SetEntityName("ACME Ltd.")) + require.NotNil(t, tv.SetName("ACME Ltd.")) require.NotNil(t, tv.SetRegID("https://acme.example")) require.NotNil(t, tv.SetRoles(RoleTagCreator)) @@ -62,7 +62,7 @@ func TestEntities_Valid_ok(t *testing.T) { e := &Entity{} require.NotNil(t, - e.SetEntityName("ACME Ltd."). + e.SetName("ACME Ltd."). SetRegID("https://acme.example"). SetRoles(RoleTagCreator, RoleCreator), ) @@ -77,7 +77,7 @@ func TestEntities_Valid_ok(t *testing.T) { func TestEntity_SetEntityName_empty(t *testing.T) { e := Entity{} - assert.Nil(t, e.SetEntityName("")) + assert.Nil(t, e.SetName("")) } func TestEntity_SetRegID_empty(t *testing.T) { diff --git a/corim/entity.go b/corim/entity.go index 2a141cbe..06ad26a6 100644 --- a/corim/entity.go +++ b/corim/entity.go @@ -16,9 +16,9 @@ import ( // Entity stores an entity-map capable of CBOR and JSON serializations. type Entity struct { - EntityName *EntityName `cbor:"0,keyasint" json:"name"` - RegID *comid.TaggedURI `cbor:"1,keyasint,omitempty" json:"regid,omitempty"` - Roles Roles `cbor:"2,keyasint" json:"roles"` + Name *EntityName `cbor:"0,keyasint" json:"name"` + RegID *comid.TaggedURI `cbor:"1,keyasint,omitempty" json:"regid,omitempty"` + Roles Roles `cbor:"2,keyasint" json:"roles"` Extensions } @@ -46,14 +46,14 @@ func (o *Entity) GetExtensions() extensions.IValue { return o.Extensions.IValue } -// SetEntityName is used to set the EntityName field of Entity using supplied name -func (o *Entity) SetEntityName(name any) *Entity { +// SetName is used to set the EntityName field of Entity using supplied name +func (o *Entity) SetName(name any) *Entity { if o != nil { if name == "" { return nil } - o.EntityName = MustNewStringEntityName(name) + o.Name = MustNewStringEntityName(name) } return o } @@ -87,11 +87,11 @@ func (o *Entity) SetRoles(roles ...Role) *Entity { // Valid checks for validity of the fields within each Entity func (o Entity) Valid() error { - if o.EntityName == nil { + if o.Name == nil { return fmt.Errorf("invalid entity: empty entity-name") } - if err := o.EntityName.Valid(); err != nil { + if err := o.Name.Valid(); err != nil { return fmt.Errorf("invalid entity: %w", err) } diff --git a/corim/entity_test.go b/corim/entity_test.go index be23a0d4..893ae92d 100644 --- a/corim/entity_test.go +++ b/corim/entity_test.go @@ -23,7 +23,7 @@ func TestEntity_Valid_uninitialized(t *testing.T) { func TestEntity_Valid_empty_name(t *testing.T) { tv := Entity{ - EntityName: MustNewStringEntityName(""), + Name: MustNewStringEntityName(""), } err := tv.Valid() @@ -35,8 +35,8 @@ func TestEntity_Valid_non_nil_empty_URI(t *testing.T) { emptyRegID := comid.TaggedURI("") tv := Entity{ - EntityName: MustNewStringEntityName("ACME Ltd."), - RegID: &emptyRegID, + Name: MustNewStringEntityName("ACME Ltd."), + RegID: &emptyRegID, } err := tv.Valid() @@ -48,8 +48,8 @@ func TestEntity_Valid_missing_roles(t *testing.T) { regID := comid.TaggedURI("http://acme.example") tv := Entity{ - EntityName: MustNewStringEntityName("ACME Ltd."), - RegID: ®ID, + Name: MustNewStringEntityName("ACME Ltd."), + RegID: ®ID, } err := tv.Valid() @@ -61,9 +61,9 @@ func TestEntity_Valid_unknown_role(t *testing.T) { regID := comid.TaggedURI("http://acme.example") tv := Entity{ - EntityName: MustNewStringEntityName("ACME Ltd."), - RegID: ®ID, - Roles: Roles{Role(666)}, + Name: MustNewStringEntityName("ACME Ltd."), + RegID: ®ID, + Roles: Roles{Role(666)}, } err := tv.Valid() @@ -73,7 +73,7 @@ func TestEntity_Valid_unknown_role(t *testing.T) { func TestEntities_Valid_ok(t *testing.T) { e := NewEntity(). - SetEntityName("ACME Ltd."). + SetName("ACME Ltd."). SetRegID("http://acme.example"). SetRoles(RoleManifestCreator) require.NotNil(t, e) diff --git a/corim/example_profile_test.go b/corim/example_profile_test.go index 435ba476..e545c3ae 100644 --- a/corim/example_profile_test.go +++ b/corim/example_profile_test.go @@ -98,7 +98,7 @@ func Example_profile_unmarshal() { } fmt.Printf("Language: %s\n", *extractedComid.Language) - fmt.Printf("Entity: %s\n", *extractedComid.Entities.Values[0].EntityName) + fmt.Printf("Entity: %s\n", *extractedComid.Entities.Values[0].Name) fmt.Printf(" %s\n", extractedComid.Entities.Values[0]. Extensions.MustGetString("Address")) diff --git a/corim/extensions_test.go b/corim/extensions_test.go index 0c76235c..d0a57399 100644 --- a/corim/extensions_test.go +++ b/corim/extensions_test.go @@ -18,7 +18,7 @@ type TestExtensions struct { } func (o TestExtensions) ConstrainEntity(ent *Entity) error { - if ent.EntityName.String() != "Futurama" { + if ent.Name.String() != "Futurama" { return errors.New(`EntityName must be "Futurama"`) // nolint:golint } @@ -35,7 +35,7 @@ func (o TestExtensions) ConstrainSigner(_ *Signer) error { func TestEntityExtensions_Valid(t *testing.T) { ent := NewEntity() - ent.SetEntityName("The Simpsons") + ent.SetName("The Simpsons") ent.SetRoles(RoleManifestCreator) err := ent.Valid() @@ -48,7 +48,7 @@ func TestEntityExtensions_Valid(t *testing.T) { err = ent.Valid() assert.EqualError(t, err, `EntityName must be "Futurama"`) - ent.SetEntityName("Futurama") + ent.SetName("Futurama") err = ent.Valid() assert.NoError(t, err) @@ -84,7 +84,7 @@ func TestEntityExtensions_CBOR(t *testing.T) { err = cbor.Unmarshal(data, &ent) assert.NoError(t, err) - assert.Equal(t, ent.EntityName.String(), "acme") + assert.Equal(t, ent.Name.String(), "acme") address, err := ent.Get("address") require.NoError(t, err) diff --git a/corim/unsignedcorim.go b/corim/unsignedcorim.go index dbe56b69..bca43b1f 100644 --- a/corim/unsignedcorim.go +++ b/corim/unsignedcorim.go @@ -207,7 +207,7 @@ func (o *UnsignedCorim) SetRimValidity(notAfter time.Time, notBefore *time.Time) func (o *UnsignedCorim) AddEntity(name string, regID *string, roles ...Role) *UnsignedCorim { if o != nil { e := NewEntity(). - SetEntityName(name). + SetName(name). SetRoles(roles...) if regID != nil { diff --git a/corim/unsignedcorim_test.go b/corim/unsignedcorim_test.go index ff3ca173..7e338b77 100644 --- a/corim/unsignedcorim_test.go +++ b/corim/unsignedcorim_test.go @@ -260,9 +260,9 @@ func TestUnsignedCorim_AddEntity_full(t *testing.T) { Entities: &Entities{ Values: []Entity{ { - EntityName: MustNewStringEntityName(name), - Roles: Roles{role}, - RegID: &taggedRegID, + Name: MustNewStringEntityName(name), + Roles: Roles{role}, + RegID: &taggedRegID, }, }, },