-
Notifications
You must be signed in to change notification settings - Fork 4
feat: add Valid() methods for TagID and Evidence #45
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
Changes from 3 commits
8afdc02
011f777
dd45316
3e76bd6
54797d7
9edaa4b
dc7d4b5
c54309d
c89d821
cbbe7b8
ceef354
67d21e8
53be192
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,11 @@ | |
|
|
||
| package swid | ||
|
|
||
| import "time" | ||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "time" | ||
| ) | ||
|
|
||
| // Evidence models a evidence-entry | ||
| type Evidence struct { | ||
|
|
@@ -53,3 +57,34 @@ func (e *Evidence) AddProcess(p Process) error { | |
|
|
||
| return nil | ||
| } | ||
|
|
||
| // Valid validates the Evidence receiver to ensure it has valid required fields | ||
| func (e Evidence) Valid() error { | ||
| if e.DeviceID == "" { | ||
| return errors.New("evidence device-id is empty") | ||
| } | ||
|
|
||
| if e.Date.IsZero() { | ||
| return errors.New("evidence date is zero") | ||
| } | ||
|
|
||
| // Validate Files if present | ||
| if e.Files != nil { | ||
| for i, file := range *e.Files { | ||
| if err := file.Valid(); err != nil { | ||
| return fmt.Errorf("evidence file[%d] invalid: %w", i, err) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Validate Processes if present | ||
| if e.Processes != nil { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for process, may be we are ok to check here as there is not much to check for validity of the process elements. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh ok sir |
||
| for i, process := range *e.Processes { | ||
| if process.ProcessName == "" { | ||
| return fmt.Errorf("evidence process[%d] process-name is empty", i) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,83 @@ | ||||||
| // Copyright 2020 Contributors to the Veraison project. | ||||||
|
||||||
| // Copyright 2020 Contributors to the Veraison project. | |
| // Copyright 2020-2025 Contributors to the Veraison project. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,8 @@ | |
|
|
||
| package swid | ||
|
|
||
| import "errors" | ||
|
|
||
| // File models CoSWID file-entry | ||
| type File struct { | ||
| GlobalAttributes | ||
|
|
@@ -23,3 +25,25 @@ type File struct { | |
| // match, the the file has not been modified in any fashion. | ||
| Hash *HashEntry `cbor:"7,keyasint,omitempty" json:"hash,omitempty" xml:"hash,attr,omitempty"` | ||
| } | ||
|
|
||
| // Valid validates the File receiver to ensure it has valid required and optional fields | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks very good to me! Thanks for incorporating feedback! |
||
| func (f File) Valid() error { | ||
| // Check mandatory fields | ||
| if f.FsName == "" { | ||
| return errors.New("file fs-name is empty") | ||
| } | ||
|
|
||
| // Validate optional elements if present | ||
| if f.Hash != nil { | ||
| if err := ValidHashEntry(f.Hash.HashAlgID, f.Hash.HashValue); err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| // Size validation - if present, should be non-negative | ||
| if f.Size != nil && *f.Size < 0 { | ||
| return errors.New("file size cannot be negative") | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
The correct implementation is to invoke Method Valid() on the File Object and let File Object, in the file
file.goto implement the Valid Method that can be invoked from line 71. In the Valid for file, check for validity of Mandatory (like FsName) and check for presence of optional elements in the file object. If Optional Elements are present, then please check their validity!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.
Sure sir checking it @yogeshbdeshpande