-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add methods to directly add Reference Values and Endorsed Values #142
base: main
Are you sure you want to change the base?
Add methods to directly add Reference Values and Endorsed Values #142
Conversation
Signed-off-by: Priyanshu Thapliyal <[email protected]>
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.
In addition to other comments -- please fix the indentation be consistent with existing code -- use tabs rather spaces for inent in Go files.
|
||
return o.Extensions.validComid(&o) | ||
if err := o.TagIdentity.Valid(); err != nil { | ||
return fmt.Errorf("tag-identity validation failed: %v", err) // Changed %w to %v |
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.
Why this change?
(also, remove the comments -- they don't make sense without historical context)
@@ -321,3 +321,103 @@ func (o Comid) ToJSONPretty(indent string) ([]byte, error) { | |||
|
|||
return json.MarshalIndent(&o, "", indent) | |||
} | |||
|
|||
// AddSimpleReferenceValue adds a reference value with a single measurement | |||
func (o *Comid) AddSimpleReferenceValue(env Environment, measurement *Measurement) error { |
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.
I don't think "simple" is the right term for this. Perhaps something like AddReferenceValueFromMeasurement
.
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 does not address #136, as this does not handle extensions, which is the intent of adding the helper methods.
Note that the issue says "without creating instances of measurements" -- where as this still requres a measurement instance. The reason is that extensions are registred with the collection, and are not propagated to the reference values (and then, through measurement, down to the Mval and the Flags) until the values are added to the collection, so its not possible to specify values for the extension fields until the reference value is in the collection.
The goal of #136 is to address that by adding a method that adds a reference/endorsement value from all raw inputs in asingle operation.
Another issue that, as of the latest CoRIM spec update, a reference value can contain multiple measurements, so the mothod would need to accomodate that as well....
Files Added/Modified:
comid/comid.go
comid/comid_test.go
comid/digests.go
comid/hashalg.go
comid/hashalg_test.go
comid/valuetriple.go
Issue Addressed:
This pull request closes #136 which highlights the difficulty in introducing Extensions for Reference Value Measurements using the current Extensions Interface.
###** Solution:**
New methods have been introduced to the CoMID struct to facilitate the addition of Reference Values without requiring the creation of instances for Measurement and ValueTriples. These methods include:
AddSimpleReferenceValue
AddDigestReferenceValue
AddRawReferenceValue
AddReferenceValueDirect
AddEndorsedValueDirect
These enhancements streamline the process, making it easier to add Reference Values and ensuring better usability of the Extensions Interface.
Before:
Users had to manually create instances for Measurement and ValueTriples to add Reference Values, which was cumbersome and error-prone.
Example:
measurement := &Measurement{ /* initialize measurement */ }
valueTriple := ValueTriple{
Environment: env,
Measurements: *NewMeasurements().Add(measurement),
}
comid.Triples.ReferenceValues.Add(valueTriple)
### After:
With the new methods, users can directly add Reference Values without creating these instances, significantly simplifying the process and reducing the likelihood of errors.
Example:
err := comid.AddSimpleReferenceValue(env, measurement)
if err != nil {
log.Fatalf("failed to add reference value: %v", err)
}