-
Notifications
You must be signed in to change notification settings - Fork 32
feat(comid): implement MembershipTriple functionality #231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
7908837174
wants to merge
4
commits into
veraison:main
Choose a base branch
from
7908837174:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,404
−0
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ae29852
feat(comid): implement MembershipTriple functionality for PR #218
7908837174 65b7234
fix: resolve linting errors for job 52170299881
7908837174 4dd92d3
fix: resolve gocritic hugeParam error for SetValue method (job 521709…
7908837174 f09ac89
Merge branch 'veraison:main' into main
7908837174 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,5 @@ | ||
| { | ||
| "githubPullRequests.ignoredPullRequestBranches": [ | ||
| "main" | ||
| ] | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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,130 @@ | ||
| // Copyright 2025 Contributors to the Veraison project. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package comid | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/veraison/corim/extensions" | ||
| ) | ||
|
|
||
| // Membership represents a membership record that associates an identifier with membership information. | ||
| // It contains a key identifying the membership target and a value containing the membership details. | ||
| type Membership struct { | ||
| Key *Mkey `cbor:"0,keyasint,omitempty" json:"key,omitempty"` | ||
| Val MemberVal `cbor:"1,keyasint" json:"value"` | ||
| } | ||
|
|
||
| // NewMembership creates a new Membership with the specified key type and value. | ||
| func NewMembership(val any, typ string) (*Membership, error) { | ||
| keyFactory, ok := mkeyValueRegister[typ] | ||
| if !ok { | ||
| return nil, fmt.Errorf("unknown Mkey type: %s", typ) | ||
| } | ||
|
|
||
| key, err := keyFactory(val) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("invalid key: %w", err) | ||
| } | ||
|
|
||
| if err = key.Valid(); err != nil { | ||
| return nil, fmt.Errorf("invalid key: %w", err) | ||
| } | ||
|
|
||
| var ret Membership | ||
| ret.Key = key | ||
|
|
||
| return &ret, nil | ||
| } | ||
|
|
||
| // MustNewMembership is like NewMembership but panics on error. | ||
| func MustNewMembership(val any, typ string) *Membership { | ||
| ret, err := NewMembership(val, typ) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| return ret | ||
| } | ||
|
|
||
| // MustNewUUIDMembership creates a new Membership with a UUID key. | ||
| func MustNewUUIDMembership(uuid UUID) *Membership { | ||
| return MustNewMembership(uuid, "uuid") | ||
| } | ||
|
|
||
| // MustNewUintMembership creates a new Membership with a uint key. | ||
| func MustNewUintMembership(u uint64) *Membership { | ||
| return MustNewMembership(u, UintType) | ||
| } | ||
|
|
||
| // SetValue sets the membership value. | ||
| func (o *Membership) SetValue(val *MemberVal) *Membership { | ||
| if o != nil { | ||
| o.Val = *val | ||
| } | ||
| return o | ||
| } | ||
|
|
||
| func (o *Membership) RegisterExtensions(exts extensions.Map) error { | ||
| return o.Val.RegisterExtensions(exts) | ||
| } | ||
|
|
||
| func (o *Membership) GetExtensions() extensions.IMapValue { | ||
| return o.Val.GetExtensions() | ||
| } | ||
|
|
||
| // Valid validates the Membership. | ||
| func (o *Membership) Valid() error { | ||
| if o.Key != nil { | ||
| if err := o.Key.Valid(); err != nil { | ||
| return fmt.Errorf("invalid measurement key: %w", err) | ||
| } | ||
| } | ||
|
|
||
| return o.Val.Valid() | ||
| } | ||
|
|
||
| // Memberships is a container for Membership instances and their extensions. | ||
| // It is a thin wrapper around extensions.Collection. | ||
| type Memberships extensions.Collection[Membership, *Membership] | ||
|
|
||
| func NewMemberships() *Memberships { | ||
| return (*Memberships)(extensions.NewCollection[Membership]()) | ||
| } | ||
|
|
||
| func (o *Memberships) RegisterExtensions(exts extensions.Map) error { | ||
| return (*extensions.Collection[Membership, *Membership])(o).RegisterExtensions(exts) | ||
| } | ||
|
|
||
| func (o *Memberships) GetExtensions() extensions.IMapValue { | ||
| return (*extensions.Collection[Membership, *Membership])(o).GetExtensions() | ||
| } | ||
|
|
||
| func (o *Memberships) Valid() error { | ||
| return (*extensions.Collection[Membership, *Membership])(o).Valid() | ||
| } | ||
|
|
||
| func (o *Memberships) IsEmpty() bool { | ||
| return (*extensions.Collection[Membership, *Membership])(o).IsEmpty() | ||
| } | ||
|
|
||
| func (o *Memberships) Add(val *Membership) *Memberships { | ||
| ret := (*extensions.Collection[Membership, *Membership])(o).Add(val) | ||
| return (*Memberships)(ret) | ||
| } | ||
|
|
||
| func (o *Memberships) MarshalCBOR() ([]byte, error) { | ||
| return (*extensions.Collection[Membership, *Membership])(o).MarshalCBOR() | ||
| } | ||
|
|
||
| func (o *Memberships) UnmarshalCBOR(data []byte) error { | ||
| return (*extensions.Collection[Membership, *Membership])(o).UnmarshalCBOR(data) | ||
| } | ||
|
|
||
| func (o *Memberships) MarshalJSON() ([]byte, error) { | ||
| return (*extensions.Collection[Membership, *Membership])(o).MarshalJSON() | ||
| } | ||
|
|
||
| func (o *Memberships) UnmarshalJSON(data []byte) error { | ||
| return (*extensions.Collection[Membership, *Membership])(o).UnmarshalJSON(data) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is completely wrong..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FIX