Skip to content

Commit 53373c8

Browse files
Fix #38 (#39)
* Fix #38 Signed-off-by: Thomas Fossati <[email protected]> * increase coverage threshold Signed-off-by: Thomas Fossati <[email protected]>
1 parent 86aeefe commit 53373c8

File tree

6 files changed

+164
-257
lines changed

6 files changed

+164
-257
lines changed

.github/workflows/ci-go-cover.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# 1. Change workflow name from "cover 100%" to "cover ≥92.5%". Script will automatically use 92.5%.
1515
# 2. Update README.md to use the new path to badge.svg because the path includes the workflow name.
1616

17-
name: cover ≥78.8%
17+
name: cover ≥80.4%
1818
on: [push, pull_request]
1919
jobs:
2020

doc.go

+1-13
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,7 @@ Or a CoSWID/JSON tag:
113113
if err := tag.FromJSON(data); err != nil { ... }
114114
115115
Note that all nested fields are accessible from outside the swid package, so
116-
(for now) no special getters are provided by the API and you will need to
117-
create your own, e.g.:
118-
119-
// CheckResType return true if the a resource exists at the expected location and
120-
// is of type "arm.com-PSAMeasuredSoftwareComponent"
121-
func CheckResType(tag swid.SoftwareIdentity) bool {
122-
if payloads := tag.Payloads; payloads != nil {
123-
if resources := (*payloads)[0].Resources; resources != nil {
124-
return (*resources)[0].Type == ResourceTypePSAMeasuredSoftwareComponent
125-
}
126-
}
127-
return false
128-
}
116+
(for now) no special getters are provided by the API.
129117
130118
Enjoy!
131119
*/

example_test.go

+1-105
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"fmt"
99
)
1010

11-
func Example_useAPIToBuildPSAEndorsementSoftwareBundle() {
11+
func Example_links() {
1212
// make new tag
1313
tag, _ := NewTag("example.acme.roadrunner-sw-v1-0-0", "Roadrunner software bundle", "1.0.0")
1414

@@ -43,50 +43,6 @@ func Example_useAPIToBuildPSAEndorsementSoftwareBundle() {
4343
// <SoftwareIdentity xmlns="http://standards.iso.org/iso/19770/-2/2015/schema.xsd" tagId="example.acme.roadrunner-sw-v1-0-0" name="Roadrunner software bundle" version="1.0.0"><Entity name="ACME Ltd" regid="acme.example" role="tagCreator softwareCreator aggregator"></Entity><Link href="example.acme.roadrunner-hw-v1-0-0" rel="psa-rot-compound"></Link><Link href="example.acme.roadrunner-sw-bl-v1-0-0" rel="component"></Link><Link href="example.acme.roadrunner-sw-prot-v1-0-0" rel="component"></Link><Link href="example.acme.roadrunner-sw-arot-v1-0-0" rel="component"></Link></SoftwareIdentity>
4444
}
4545

46-
func Example_useAPIToBuildPSAEndorsementSoftwareComponent() {
47-
// make new tag
48-
tag, _ := NewTag("example.acme.roadrunner-sw-bl-v1-0-0", "Roadrunner boot loader", "1.0.0")
49-
50-
// make entity and add it to the tag
51-
entity, _ := NewEntity("ACME Ltd", RoleTagCreator, RoleAggregator)
52-
_ = entity.SetRegID("acme.example")
53-
_ = tag.AddEntity(*entity)
54-
55-
// make resource and add it to payload
56-
resource, _ := NewPSAMeasuredSoftwareComponentResource(
57-
// measurement
58-
HashEntry{
59-
HashAlgID: 1,
60-
HashValue: []byte("aabb...eeff"),
61-
},
62-
// signer ID
63-
HashEntry{
64-
HashAlgID: 1,
65-
HashValue: []byte("5192...1234"),
66-
},
67-
)
68-
69-
payload := NewPayload()
70-
_ = payload.AddResource(*resource)
71-
tag.Payload = payload
72-
73-
// make link to the HW RoT
74-
link, _ := NewLink("example.acme.roadrunner-hw-v1-0-0", *NewRel("psa-rot-compound"))
75-
_ = tag.AddLink(*link)
76-
77-
// encode tag to JSON
78-
data, _ := tag.ToJSON()
79-
fmt.Println(string(data))
80-
81-
// encode tag to XML
82-
data, _ = tag.ToXML()
83-
fmt.Println(string(data))
84-
85-
// Output:
86-
// {"tag-id":"example.acme.roadrunner-sw-bl-v1-0-0","tag-version":0,"software-name":"Roadrunner boot loader","software-version":"1.0.0","entity":[{"entity-name":"ACME Ltd","reg-id":"acme.example","role":["tagCreator","aggregator"]}],"link":[{"href":"example.acme.roadrunner-hw-v1-0-0","rel":"psa-rot-compound"}],"payload":{"resource":[{"type":"arm.com-PSAMeasuredSoftwareComponent","arm.com-PSAMeasurementValue":"sha-256:YWFiYi4uLmVlZmY=","arm.com-PSASignerId":"sha-256:NTE5Mi4uLjEyMzQ="}]}}
87-
// <SoftwareIdentity xmlns="http://standards.iso.org/iso/19770/-2/2015/schema.xsd" tagId="example.acme.roadrunner-sw-bl-v1-0-0" name="Roadrunner boot loader" version="1.0.0"><Entity name="ACME Ltd" regid="acme.example" role="tagCreator aggregator"></Entity><Link href="example.acme.roadrunner-hw-v1-0-0" rel="psa-rot-compound"></Link><Payload><Resource type="arm.com-PSAMeasuredSoftwareComponent" measurementValue="sha-256:YWFiYi4uLmVlZmY=" signerId="sha-256:NTE5Mi4uLjEyMzQ="></Resource></Payload></SoftwareIdentity>
88-
}
89-
9046
func Example_completePrimaryTag() {
9147
tag, _ := NewTag(
9248
"com.acme.rrd2013-ce-sp1-v4-1-5-0",
@@ -161,63 +117,3 @@ func Example_completePrimaryTag() {
161117
// Output:
162118
// <SoftwareIdentity xmlns="http://standards.iso.org/iso/19770/-2/2015/schema.xsd" tagId="com.acme.rrd2013-ce-sp1-v4-1-5-0" name="ACME Roadrunner Detector 2013 Coyote Edition SP1" version="4.1.5"><Meta activationStatus="trial" colloquialVersion="2013" edition="coyote" product="Roadrunner Detector" revision="sp1"></Meta><Entity name="The ACME Corporation" regid="acme.com" role="tagCreator softwareCreator"></Entity><Entity name="Coyote Services, Inc." regid="mycoyote.com" role="distributor"></Entity><Link href="www.gnu.org/licenses/gpl.txt" rel="license"></Link><Payload><Directory name="rrdetector" root="%programdata%"><File name="rrdetector.exe" size="532712" hash="sha-256:oxT8LcZjrnpra8Z4dZQFc5bms/VpzVD9XdtNG7r9K2o="></File></Directory><File name="test.exe" size="532712" hash="sha-256:oxT8LcZjrnpra8Z4dZQFc5bms/VpzVD9XdtNG7r9K2o="></File></Payload></SoftwareIdentity>
163119
}
164-
165-
func Example_decodePSAEndorsementSoftwareComponent() {
166-
var tag SoftwareIdentity
167-
168-
data := []byte(`{
169-
"tag-id": "example.acme.roadrunner-sw-bl-v1-0-0",
170-
"tag-version": 0,
171-
"software-name": "Roadrunner boot loader",
172-
"software-version": "1.0.0",
173-
"entity": [
174-
{
175-
"entity-name": "ACME Ltd",
176-
"reg-id": "acme.example",
177-
"role": [
178-
"tagCreator",
179-
"aggregator"
180-
]
181-
}
182-
],
183-
"link": [
184-
{
185-
"href": "example.acme.roadrunner-hw-v1-0-0",
186-
"rel": "psa-rot-compound"
187-
}
188-
],
189-
"payload": {
190-
"resource": [
191-
{
192-
"type": "arm.com-PSAMeasuredSoftwareComponent",
193-
"arm.com-PSAMeasurementValue": "sha-256:YWFiYi4uLmVlZmY=",
194-
"arm.com-PSASignerId": "sha-256:NTE5Mi4uLjEyMzQ="
195-
}
196-
]
197-
}
198-
}`)
199-
200-
if err := tag.FromJSON(data); err != nil {
201-
fmt.Println(err)
202-
return
203-
}
204-
205-
if !checkResType(tag) {
206-
fmt.Println("KO")
207-
return
208-
}
209-
210-
fmt.Println("OK")
211-
212-
// Output:
213-
// OK
214-
}
215-
216-
func checkResType(tag SoftwareIdentity) bool {
217-
if payload := tag.Payload; payload != nil {
218-
if resources := payload.Resources; resources != nil {
219-
return (*resources)[0].Type == ResourceTypePSAMeasuredSoftwareComponent
220-
}
221-
}
222-
return false
223-
}

resource.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package swid
55

66
// Resource models a resource-entry
77
type Resource struct {
8+
ResourceExtension
89
GlobalAttributes
910
Type string `cbor:"29,keyasint" json:"type" xml:"type,attr"`
10-
ResourceExtension
1111
}

resource_extension.go

-32
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,6 @@
33

44
package swid
55

6-
var (
7-
// ResourceTypePSAMeasuredSoftwareComponent is the resource type to use for
8-
// a PSA measured software component
9-
ResourceTypePSAMeasuredSoftwareComponent = "arm.com-PSAMeasuredSoftwareComponent"
10-
)
11-
126
// ResourceExtension is a placeholder for $$resource-extension
137
type ResourceExtension struct {
14-
// PSA endorsements extensions
15-
PSAMeasuredSoftwareComponent
16-
}
17-
18-
// PSAMeasuredSoftwareComponent describes a PSA measured software component
19-
// See Section 3.4.1 of draft-tschofenig-rats-psa-token-05
20-
type PSAMeasuredSoftwareComponent struct {
21-
MeasurementValue HashEntry `cbor:"arm.com-PSAMeasurementValue" json:"arm.com-PSAMeasurementValue" xml:"measurementValue,attr"`
22-
SignerID HashEntry `cbor:"arm.com-PSASignerId" json:"arm.com-PSASignerId" xml:"signerId,attr"`
23-
}
24-
25-
// NewPSAMeasuredSoftwareComponentResource returns a Resource of type
26-
// PSAMeasuredSoftwareComponent initialized according to the supplied
27-
// measurement value and signer ID
28-
func NewPSAMeasuredSoftwareComponentResource(
29-
measurementValue HashEntry, signerID HashEntry,
30-
) (*Resource, error) {
31-
return &Resource{
32-
Type: ResourceTypePSAMeasuredSoftwareComponent,
33-
ResourceExtension: ResourceExtension{
34-
PSAMeasuredSoftwareComponent{
35-
MeasurementValue: measurementValue,
36-
SignerID: signerID,
37-
},
38-
},
39-
}, nil
408
}

0 commit comments

Comments
 (0)