File tree Expand file tree Collapse file tree 3 files changed +24
-3
lines changed
cmd/govulncheck/testdata/common/testfiles Expand file tree Collapse file tree 3 files changed +24
-3
lines changed Original file line number Diff line number Diff line change 3
3
$ govulncheck -format openvex -mode binary ${common_vuln_binary}
4
4
{
5
5
"@context": "https://openvex.dev/ns/v0.2.0",
6
- "@id": "govulncheckVEX ",
6
+ "@id": "govulncheck/vex:b2e8274f24820051d79285827c4fe6e1912c99143a4693804b9a5c366ec5fb8d ",
7
7
"author": "Unknown Author",
8
8
"timestamp": "2024-01-01T00:00:00",
9
9
"version": 1,
Original file line number Diff line number Diff line change 3
3
$ govulncheck -C ${moddir}/vuln -format openvex ./...
4
4
{
5
5
"@context": "https://openvex.dev/ns/v0.2.0",
6
- "@id": "govulncheckVEX ",
6
+ "@id": "govulncheck/vex:b2e8274f24820051d79285827c4fe6e1912c99143a4693804b9a5c366ec5fb8d ",
7
7
"author": "Unknown Author",
8
8
"timestamp": "2024-01-01T00:00:00",
9
9
"version": 1,
Original file line number Diff line number Diff line change 5
5
package openvex
6
6
7
7
import (
8
+ "crypto/sha256"
8
9
"encoding/json"
9
10
"fmt"
10
11
"io"
@@ -88,14 +89,16 @@ func (h *handler) Flush() error {
88
89
89
90
func toVex (h * handler ) Document {
90
91
doc := Document {
91
- ID : "govulncheckVEX" , // TODO: create hash from document for ID
92
92
Context : ContextURI ,
93
93
Author : DefaultAuthor ,
94
94
Timestamp : time .Now ().UTC (),
95
95
Version : 1 ,
96
96
Tooling : Tooling ,
97
97
Statements : statements (h ),
98
98
}
99
+
100
+ id := hashVex (doc )
101
+ doc .ID = "govulncheck/vex:" + id
99
102
return doc
100
103
}
101
104
@@ -160,3 +163,21 @@ func statements(h *handler) []Statement {
160
163
})
161
164
return statements
162
165
}
166
+
167
+ func hashVex (doc Document ) string {
168
+ // json.Marshal should never error here (because of the structure of Document).
169
+ // If an error does occur, it won't be a jsonerror, but instead a panic
170
+ d := Document {
171
+ Context : doc .Context ,
172
+ ID : doc .ID ,
173
+ Author : doc .Author ,
174
+ Version : doc .Version ,
175
+ Tooling : doc .Tooling ,
176
+ Statements : doc .Statements ,
177
+ }
178
+ out , err := json .Marshal (d )
179
+ if err != nil {
180
+ panic (err )
181
+ }
182
+ return fmt .Sprintf ("%x" , sha256 .Sum256 (out ))
183
+ }
You can’t perform that action at this time.
0 commit comments