Skip to content

Commit

Permalink
Set MKey as uint
Browse files Browse the repository at this point in the history
  • Loading branch information
yogeshbdeshpande committed Nov 24, 2021
1 parent 640b00b commit 09fcc2c
Show file tree
Hide file tree
Showing 4 changed files with 329 additions and 0 deletions.
280 changes: 280 additions & 0 deletions comid/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,113 @@ func Example_encode() {
// {"lang":"en-GB","tag-identity":{"id":"my-ns:acme-roadrunner-supplement"},"entities":[{"name":"ACME Ltd.","regid":"https://acme.example","roles":["creator","tagCreator"]},{"name":"EMCA Ltd.","roles":["maintainer"]}],"linked-tags":[{"target":"my-ns:acme-roadrunner-base","rel":"supplements"},{"target":"my-ns:acme-roadrunner-old","rel":"replaces"}],"triples":{"reference-values":[{"environment":{"class":{"id":{"type":"oid","value":"2.5.2.8192"},"vendor":"ACME Ltd.","model":"RoadRunner","layer":0,"index":1},"instance":{"type":"ueid","value":"At6tvu/erQ=="},"group":{"type":"ueid","value":"31fb5abf-023e-4992-aa4e-95f9c1503bfa"}},"measurements":[{"key":{"type":"uuid","value":"31fb5abf-023e-4992-aa4e-95f9c1503bfa"},"value":{"svn":{"type":"exact-value","value":2},"digests":["sha-256-32:q83vAA==","sha-256-32://///w=="],"op-flags":["notSecure","debug"],"raw-value":"AQIDBA==","raw-value-mask":"/////w==","mac-addr":"02:00:5e:10:00:00:00:01","ip-addr":"2001:db8::68","serial-number":"C02X70VHJHD5","ueid":"At6tvu/erQ==","uuid":"31fb5abf-023e-4992-aa4e-95f9c1503bfa"}}]}],"endorsed-values":[{"environment":{"class":{"id":{"type":"uuid","value":"31fb5abf-023e-4992-aa4e-95f9c1503bfa"},"vendor":"ACME Ltd.","model":"RoadRunner","layer":0,"index":1},"instance":{"type":"ueid","value":"At6tvu/erQ=="},"group":{"type":"ueid","value":"31fb5abf-023e-4992-aa4e-95f9c1503bfa"}},"measurements":[{"key":{"type":"uuid","value":"31fb5abf-023e-4992-aa4e-95f9c1503bfa"},"value":{"svn":{"type":"min-value","value":2},"digests":["sha-256-32:q83vAA==","sha-256-32://///w=="],"op-flags":["notConfigured","notSecure","debug"],"raw-value":"AQIDBA==","raw-value-mask":"/////w==","mac-addr":"02:00:5e:10:00:00:00:01","ip-addr":"2001:db8::68","serial-number":"C02X70VHJHD5","ueid":"At6tvu/erQ==","uuid":"31fb5abf-023e-4992-aa4e-95f9c1503bfa"}}]}],"attester-verification-keys":[{"environment":{"instance":{"type":"uuid","value":"31fb5abf-023e-4992-aa4e-95f9c1503bfa"}},"verification-keys":[{"key":"FGHIjkisldnASDxvWY...","chain":["MENGsdhfugjQWEtyX...","MIIEnjCCA4agAwIBA..."]}]}],"dev-identity-keys":[{"environment":{"instance":{"type":"ueid","value":"At6tvu/erQ=="}},"verification-keys":[{"key":"MIGkAgEBBDCk5QboB...","chain":["MIIDkjCCAxigAwIBA...","MIIEnjCCA4agAwIBA..."]}]}]}}
}

func Example_encode_int_mkey() {
comid := NewComid().
SetLanguage("en-GB").
SetTagIdentity("my-ns:acme-roadrunner-supplement", 0).
AddEntity("ACME Ltd.", &TestRegID, RoleCreator, RoleTagCreator).
AddEntity("EMCA Ltd.", nil, RoleMaintainer).
AddLinkedTag("my-ns:acme-roadrunner-base", RelSupplements).
AddLinkedTag("my-ns:acme-roadrunner-old", RelReplaces).
AddReferenceValue(
ReferenceValue{
Environment: Environment{
Class: NewClassOID(TestOID).
SetVendor("ACME Ltd.").
SetModel("RoadRunner").
SetLayer(0).
SetIndex(1),
Instance: NewInstanceUEID(TestUEID),
Group: NewGroupUUID(TestUUID),
},
Measurements: *NewMeasurements().
AddMeasurement(
NewMeasurement().
SetKeyUint(TestUInt).
SetRawValueBytes([]byte{0x01, 0x02, 0x03, 0x04}, []byte{0xff, 0xff, 0xff, 0xff}).
SetSVN(2).
AddDigest(swid.Sha256_32, []byte{0xab, 0xcd, 0xef, 0x00}).
AddDigest(swid.Sha256_32, []byte{0xff, 0xff, 0xff, 0xff}).
SetOpFlags(OpFlagNotSecure, OpFlagDebug).
SetSerialNumber("C02X70VHJHD5").
SetUEID(TestUEID).
SetUUID(TestUUID).
SetMACaddr(MACaddr(TestMACaddr)).
SetIPaddr(TestIPaddr),
),
},
).
AddEndorsedValue(
EndorsedValue{
Environment: Environment{
Class: NewClassUUID(TestUUID).
SetVendor("ACME Ltd.").
SetModel("RoadRunner").
SetLayer(0).
SetIndex(1),
Instance: NewInstanceUEID(TestUEID),
Group: NewGroupUUID(TestUUID),
},
Measurements: *NewMeasurements().
AddMeasurement(
NewMeasurement().
SetKeyUint(TestUInt+1).
SetRawValueBytes([]byte{0x01, 0x02, 0x03, 0x04}, []byte{0xff, 0xff, 0xff, 0xff}).
SetMinSVN(2).
AddDigest(swid.Sha256_32, []byte{0xab, 0xcd, 0xef, 0x00}).
AddDigest(swid.Sha256_32, []byte{0xff, 0xff, 0xff, 0xff}).
SetOpFlags(OpFlagNotSecure, OpFlagDebug, OpFlagNotConfigured).
SetSerialNumber("C02X70VHJHD5").
SetUEID(TestUEID).
SetUUID(TestUUID).
SetMACaddr(MACaddr(TestMACaddr)).
SetIPaddr(TestIPaddr),
),
},
).
AddAttestVerifKey(
AttestVerifKey{
Environment: Environment{
Instance: NewInstanceUUID(uuid.UUID(TestUUID)),
},
VerifKeys: *NewVerifKeys().
AddVerifKey(
NewVerifKey().
SetKey("FGHIjkisldnASDxvWY...").
AddCert("MENGsdhfugjQWEtyX...").
AddCert("MIIEnjCCA4agAwIBA..."),
),
},
).AddDevIdentityKey(
DevIdentityKey{
Environment: Environment{
Instance: NewInstanceUEID(TestUEID),
},
VerifKeys: *NewVerifKeys().
AddVerifKey(
NewVerifKey().
SetKey("MIGkAgEBBDCk5QboB...").
AddCert("MIIDkjCCAxigAwIBA...").
AddCert("MIIEnjCCA4agAwIBA..."),
),
},
)

cbor, err := comid.ToCBOR()
if err == nil {
fmt.Printf("%x\n", cbor)
}

json, err := comid.ToJSON()
if err == nil {
fmt.Printf("%s\n", string(json))
}

// Output:
// a50065656e2d474201a10078206d792d6e733a61636d652d726f616472756e6e65722d737570706c656d656e740282a3006941434d45204c74642e01d8207468747470733a2f2f61636d652e6578616d706c6502820100a20069454d4341204c74642e0281020382a200781a6d792d6e733a61636d652d726f616472756e6e65722d626173650100a20078196d792d6e733a61636d652d726f616472756e6e65722d6f6c64010104a4008182a300a500d86f445502c000016941434d45204c74642e026a526f616452756e6e65720300040101d902264702deadbeefdead02d8255031fb5abf023e4992aa4e95f9c1503bfa81a200182d01aa01d90228020282820644abcdef00820644ffffffff030a04d9023044010203040544ffffffff064802005e1000000001075020010db8000000000000000000000068086c43303258373056484a484435094702deadbeefdead0a5031fb5abf023e4992aa4e95f9c1503bfa018182a300a500d8255031fb5abf023e4992aa4e95f9c1503bfa016941434d45204c74642e026a526f616452756e6e65720300040101d902264702deadbeefdead02d8255031fb5abf023e4992aa4e95f9c1503bfa81a200182e01aa01d90229020282820644abcdef00820644ffffffff030b04d9023044010203040544ffffffff064802005e1000000001075020010db8000000000000000000000068086c43303258373056484a484435094702deadbeefdead0a5031fb5abf023e4992aa4e95f9c1503bfa028182a101d8255031fb5abf023e4992aa4e95f9c1503bfa81a20075464748496a6b69736c646e415344787657592e2e2e0182744d454e477364686675676a5157457479582e2e2e744d4949456e6a43434134616741774942412e2e2e038182a101d902264702deadbeefdead81a200744d49476b416745424244436b3551626f422e2e2e0182744d4949446b6a43434178696741774942412e2e2e744d4949456e6a43434134616741774942412e2e2e
// {"lang":"en-GB","tag-identity":{"id":"my-ns:acme-roadrunner-supplement"},"entities":[{"name":"ACME Ltd.","regid":"https://acme.example","roles":["creator","tagCreator"]},{"name":"EMCA Ltd.","roles":["maintainer"]}],"linked-tags":[{"target":"my-ns:acme-roadrunner-base","rel":"supplements"},{"target":"my-ns:acme-roadrunner-old","rel":"replaces"}],"triples":{"reference-values":[{"environment":{"class":{"id":{"type":"oid","value":"2.5.2.8192"},"vendor":"ACME Ltd.","model":"RoadRunner","layer":0,"index":1},"instance":{"type":"ueid","value":"At6tvu/erQ=="},"group":{"type":"ueid","value":"31fb5abf-023e-4992-aa4e-95f9c1503bfa"}},"measurements":[{"key":{"type":"uint","value":45},"value":{"svn":{"type":"exact-value","value":2},"digests":["sha-256-32:q83vAA==","sha-256-32://///w=="],"op-flags":["notSecure","debug"],"raw-value":"AQIDBA==","raw-value-mask":"/////w==","mac-addr":"02:00:5e:10:00:00:00:01","ip-addr":"2001:db8::68","serial-number":"C02X70VHJHD5","ueid":"At6tvu/erQ==","uuid":"31fb5abf-023e-4992-aa4e-95f9c1503bfa"}}]}],"endorsed-values":[{"environment":{"class":{"id":{"type":"uuid","value":"31fb5abf-023e-4992-aa4e-95f9c1503bfa"},"vendor":"ACME Ltd.","model":"RoadRunner","layer":0,"index":1},"instance":{"type":"ueid","value":"At6tvu/erQ=="},"group":{"type":"ueid","value":"31fb5abf-023e-4992-aa4e-95f9c1503bfa"}},"measurements":[{"key":{"type":"uint","value":46},"value":{"svn":{"type":"min-value","value":2},"digests":["sha-256-32:q83vAA==","sha-256-32://///w=="],"op-flags":["notConfigured","notSecure","debug"],"raw-value":"AQIDBA==","raw-value-mask":"/////w==","mac-addr":"02:00:5e:10:00:00:00:01","ip-addr":"2001:db8::68","serial-number":"C02X70VHJHD5","ueid":"At6tvu/erQ==","uuid":"31fb5abf-023e-4992-aa4e-95f9c1503bfa"}}]}],"attester-verification-keys":[{"environment":{"instance":{"type":"uuid","value":"31fb5abf-023e-4992-aa4e-95f9c1503bfa"}},"verification-keys":[{"key":"FGHIjkisldnASDxvWY...","chain":["MENGsdhfugjQWEtyX...","MIIEnjCCA4agAwIBA..."]}]}],"dev-identity-keys":[{"environment":{"instance":{"type":"ueid","value":"At6tvu/erQ=="}},"verification-keys":[{"key":"MIGkAgEBBDCk5QboB...","chain":["MIIDkjCCAxigAwIBA...","MIIEnjCCA4agAwIBA..."]}]}]}}
}

func Example_encode_PSA() {
comid := NewComid().
SetTagIdentity("my-ns:acme-roadrunner-supplement", 0).
Expand Down Expand Up @@ -392,6 +499,134 @@ func Example_decode_JSON() {
// Output: OK
}

func Example_decode_JSON_Mkey_asUint() {
j := `
{
"lang": "en-GB",
"tag-identity": {
"id": "43BBE37F-2E61-4B33-AED3-53CFF1428B16",
"version": 1
},
"entities": [
{
"name": "ACME Ltd.",
"regid": "https://acme.example",
"roles": [ "tagCreator" ]
},
{
"name": "EMCA Ltd.",
"regid": "https://emca.example",
"roles": [ "maintainer", "creator" ]
}
],
"linked-tags": [
{
"target": "6F7D8D2F-EAEC-4A15-BB46-1E4DCB85DDFF",
"rel": "replaces"
}
],
"triples": {
"endorsed-values": [
{
"environment": {
"class": {
"id": {
"type": "oid",
"value": "2.16.840.1.101.3.4.2.1"
}
},
"instance": {
"type": "uuid",
"value": "9090B8D3-3B17-474C-A0B9-6F54731CAB72"
}
},
"measurements": [
{
"key" : {
"type": "uint",
"value":100
},
"value": {
"mac-addr": "00:00:5e:00:53:01",
"ip-addr": "2001:4860:0:2001::68",
"serial-number": "C02X70VHJHD5",
"ueid": "Ad6tvu/erb7v3q2+796tvu8=",
"uuid": "9090B8D3-3B17-474C-A0B9-6F54731CAB72",
"raw-value": {
"type": "bytes",
"value": "cmF3dmFsdWUKcmF3dmFsdWUK"
},
"raw-value-mask": "qg==",
"op-flags": [ "notSecure" ],
"digests": [
"sha-256:5Fty9cDAtXLbTY06t+l/No/3TmI0eoJN7LZ6hOUiTXU=",
"sha-384:S1bPoH+usqtX3pIeSpfWVRRLVGRw66qrb3HA21GN31tKX7KPsq0bSTQmRCTrHlqG"
],
"version": {
"scheme": "semaver",
"value": "1.2.3beta4"
},
"svn": {
"type": "min-value",
"value": 10
}
}
}
]
}
],
"attester-verification-keys": [
{
"environment": {
"group": {
"type": "uuid",
"value": "83294297-97EB-42EF-8A72-AE9FEA002750"
}
},
"verification-keys": [
{
"key": "MFkwEwYHKoZI...",
"chain": [
"MIIDkjCCAxigAwIBA...",
"MIIEnjCCA4agAwIBA..."
]
}
]
}
],
"dev-identity-keys": [
{
"environment": {
"instance": {
"type": "uuid",
"value": "4ECCE47C-85F2-4FD9-9EC6-00DEB72DA707"
}
},
"verification-keys": [
{
"key": "MIIDUDCCAvWgAw..."
},
{
"key": "MIIEnjCCA4agAw..."
}
]
}
]
}
}
`
comid := Comid{}
err := comid.FromJSON([]byte(j))

if err != nil {
fmt.Printf("FAIL: %v", err)
} else {
fmt.Println("OK")
}

// Output: OK
}

func Example_decode_CBOR_1() {
// https://github.com/ietf-rats/ietf-corim-cddl/blob/main/examples/comid-1.diag
in := []byte{
Expand Down Expand Up @@ -588,3 +823,48 @@ func Example_decode_CBOR_4() {

// Output: OK
}

func Example_decode_CBOR_5() {
in := []byte{
0xa5, 0x00, 0x65, 0x65, 0x6e, 0x2d, 0x47, 0x42, 0x01, 0xa1, 0x00, 0x78, 0x20, 0x6d, 0x79, 0x2d, 0x6e, 0x73, 0x3a, 0x61, 0x63, 0x6d, 0x65, 0x2d,
0x72, 0x6f, 0x61, 0x64, 0x72, 0x75, 0x6e, 0x6e, 0x65, 0x72, 0x2d, 0x73, 0x75, 0x70, 0x70, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x02, 0x82, 0xa3,
0x00, 0x69, 0x41, 0x43, 0x4d, 0x45, 0x20, 0x4c, 0x74, 0x64, 0x2e, 0x01, 0xd8, 0x20, 0x74, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x61,
0x63, 0x6d, 0x65, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x02, 0x82, 0x01, 0x00, 0xa2, 0x00, 0x69, 0x45, 0x4d, 0x43, 0x41, 0x20, 0x4c,
0x74, 0x64, 0x2e, 0x02, 0x81, 0x02, 0x03, 0x82, 0xa2, 0x00, 0x78, 0x1a, 0x6d, 0x79, 0x2d, 0x6e, 0x73, 0x3a, 0x61, 0x63, 0x6d, 0x65, 0x2d, 0x72,
0x6f, 0x61, 0x64, 0x72, 0x75, 0x6e, 0x6e, 0x65, 0x72, 0x2d, 0x62, 0x61, 0x73, 0x65, 0x01, 0x00, 0xa2, 0x00, 0x78, 0x19, 0x6d, 0x79, 0x2d, 0x6e,
0x73, 0x3a, 0x61, 0x63, 0x6d, 0x65, 0x2d, 0x72, 0x6f, 0x61, 0x64, 0x72, 0x75, 0x6e, 0x6e, 0x65, 0x72, 0x2d, 0x6f, 0x6c, 0x64, 0x01, 0x01, 0x04,
0xa4, 0x00, 0x81, 0x82, 0xa3, 0x00, 0xa5, 0x00, 0xd8, 0x6f, 0x44, 0x55, 0x02, 0xc0, 0x00, 0x01, 0x69, 0x41, 0x43, 0x4d, 0x45, 0x20, 0x4c, 0x74,
0x64, 0x2e, 0x02, 0x6a, 0x52, 0x6f, 0x61, 0x64, 0x52, 0x75, 0x6e, 0x6e, 0x65, 0x72, 0x03, 0x00, 0x04, 0x01, 0x01, 0xd9, 0x02, 0x26, 0x47, 0x02,
0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0x02, 0xd8, 0x25, 0x50, 0x31, 0xfb, 0x5a, 0xbf, 0x02, 0x3e, 0x49, 0x92, 0xaa, 0x4e, 0x95, 0xf9, 0xc1, 0x50,
0x3b, 0xfa, 0x81, 0xa2, 0x00, 0x18, 0x2d, 0x01, 0xaa, 0x01, 0xd9, 0x02, 0x28, 0x02, 0x02, 0x82, 0x82, 0x06, 0x44, 0xab, 0xcd, 0xef, 0x00, 0x82,
0x06, 0x44, 0xff, 0xff, 0xff, 0xff, 0x03, 0x0a, 0x04, 0xd9, 0x02, 0x30, 0x44, 0x01, 0x02, 0x03, 0x04, 0x05, 0x44, 0xff, 0xff, 0xff, 0xff, 0x06,
0x48, 0x02, 0x00, 0x5e, 0x10, 0x00, 0x00, 0x00, 0x01, 0x07, 0x50, 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x68, 0x08, 0x6c, 0x43, 0x30, 0x32, 0x58, 0x37, 0x30, 0x56, 0x48, 0x4a, 0x48, 0x44, 0x35, 0x09, 0x47, 0x02, 0xde, 0xad, 0xbe, 0xef,
0xde, 0xad, 0x0a, 0x50, 0x31, 0xfb, 0x5a, 0xbf, 0x02, 0x3e, 0x49, 0x92, 0xaa, 0x4e, 0x95, 0xf9, 0xc1, 0x50, 0x3b, 0xfa, 0x01, 0x81, 0x82, 0xa3,
0x00, 0xa5, 0x00, 0xd8, 0x25, 0x50, 0x31, 0xfb, 0x5a, 0xbf, 0x02, 0x3e, 0x49, 0x92, 0xaa, 0x4e, 0x95, 0xf9, 0xc1, 0x50, 0x3b, 0xfa, 0x01, 0x69,
0x41, 0x43, 0x4d, 0x45, 0x20, 0x4c, 0x74, 0x64, 0x2e, 0x02, 0x6a, 0x52, 0x6f, 0x61, 0x64, 0x52, 0x75, 0x6e, 0x6e, 0x65, 0x72, 0x03, 0x00, 0x04,
0x01, 0x01, 0xd9, 0x02, 0x26, 0x47, 0x02, 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0x02, 0xd8, 0x25, 0x50, 0x31, 0xfb, 0x5a, 0xbf, 0x02, 0x3e, 0x49,
0x92, 0xaa, 0x4e, 0x95, 0xf9, 0xc1, 0x50, 0x3b, 0xfa, 0x81, 0xa2, 0x00, 0x18, 0x2e, 0x01, 0xaa, 0x01, 0xd9, 0x02, 0x29, 0x02, 0x02, 0x82, 0x82,
0x06, 0x44, 0xab, 0xcd, 0xef, 0x00, 0x82, 0x06, 0x44, 0xff, 0xff, 0xff, 0xff, 0x03, 0x0b, 0x04, 0xd9, 0x02, 0x30, 0x44, 0x01, 0x02, 0x03, 0x04,
0x05, 0x44, 0xff, 0xff, 0xff, 0xff, 0x06, 0x48, 0x02, 0x00, 0x5e, 0x10, 0x00, 0x00, 0x00, 0x01, 0x07, 0x50, 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x68, 0x08, 0x6c, 0x43, 0x30, 0x32, 0x58, 0x37, 0x30, 0x56, 0x48, 0x4a, 0x48, 0x44, 0x35,
0x09, 0x47, 0x02, 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0x0a, 0x50, 0x31, 0xfb, 0x5a, 0xbf, 0x02, 0x3e, 0x49, 0x92, 0xaa, 0x4e, 0x95, 0xf9, 0xc1,
0x50, 0x3b, 0xfa, 0x02, 0x81, 0x82, 0xa1, 0x01, 0xd8, 0x25, 0x50, 0x31, 0xfb, 0x5a, 0xbf, 0x02, 0x3e, 0x49, 0x92, 0xaa, 0x4e, 0x95, 0xf9, 0xc1,
0x50, 0x3b, 0xfa, 0x81, 0xa2, 0x00, 0x75, 0x46, 0x47, 0x48, 0x49, 0x6a, 0x6b, 0x69, 0x73, 0x6c, 0x64, 0x6e, 0x41, 0x53, 0x44, 0x78, 0x76, 0x57,
0x59, 0x2e, 0x2e, 0x2e, 0x01, 0x82, 0x74, 0x4d, 0x45, 0x4e, 0x47, 0x73, 0x64, 0x68, 0x66, 0x75, 0x67, 0x6a, 0x51, 0x57, 0x45, 0x74, 0x79, 0x58,
0x2e, 0x2e, 0x2e, 0x74, 0x4d, 0x49, 0x49, 0x45, 0x6e, 0x6a, 0x43, 0x43, 0x41, 0x34, 0x61, 0x67, 0x41, 0x77, 0x49, 0x42, 0x41, 0x2e, 0x2e, 0x2e,
0x03, 0x81, 0x82, 0xa1, 0x01, 0xd9, 0x02, 0x26, 0x47, 0x02, 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0x81, 0xa2, 0x00, 0x74, 0x4d, 0x49, 0x47, 0x6b,
0x41, 0x67, 0x45, 0x42, 0x42, 0x44, 0x43, 0x6b, 0x35, 0x51, 0x62, 0x6f, 0x42, 0x2e, 0x2e, 0x2e, 0x01, 0x82, 0x74, 0x4d, 0x49, 0x49, 0x44, 0x6b,
0x6a, 0x43, 0x43, 0x41, 0x78, 0x69, 0x67, 0x41, 0x77, 0x49, 0x42, 0x41, 0x2e, 0x2e, 0x2e, 0x74, 0x4d, 0x49, 0x49, 0x45, 0x6e, 0x6a, 0x43, 0x43,
0x41, 0x34, 0x61, 0x67, 0x41, 0x77, 0x49, 0x42, 0x41, 0x2e, 0x2e, 0x2e,
}
comid := Comid{}
err := comid.FromCBOR(in)
if err != nil {
fmt.Printf("FAIL: %v", err)
} else {
fmt.Println("OK")
}

// Output: OK
}
39 changes: 39 additions & 0 deletions comid/measurement.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ func (o Mkey) Valid() error {
return nil
case TaggedPSARefValID:
return PSARefValID(t).Valid()
case uint:
if o.val == nil {
return fmt.Errorf("empty uint Mkey")
}
return nil
default:
return fmt.Errorf("unknown measurement key type %T", t)
}
Expand Down Expand Up @@ -84,6 +89,15 @@ func (o *Mkey) UnmarshalJSON(data []byte) error {
)
}
o.val = TaggedPSARefValID(x)
case "uint":
var x uint
if err := json.Unmarshal(v.Value, &x); err != nil {
return fmt.Errorf(
"cannot unmarshal $measured-element-type-choice of type uint: %w",
err,
)
}
o.val = x
default:
return fmt.Errorf("unknown type %s for $measured-element-type-choice", v.Type)
}
Expand Down Expand Up @@ -114,6 +128,13 @@ func (o Mkey) MarshalJSON() ([]byte, error) {
return nil, err
}
v = tnv{Type: "psa.refval-id", Value: b}
case uint:
b, err = json.Marshal(t)
if err != nil {
return nil, err
}
v = tnv{Type: "uint", Value: b}

default:
return nil, fmt.Errorf("unknown type %T for mkey", t)
}
Expand Down Expand Up @@ -255,6 +276,17 @@ func (o *Measurement) SetKeyUUID(u UUID) *Measurement {
return o
}

// SetKeyUint sets the key of the target measurement-map to the supplied
// uint
func (o *Measurement) SetKeyUint(u uint) *Measurement {
if o != nil {
o.Key = &Mkey{
val: u,
}
}
return o
}

// NewPSAMeasurement instantiates a new measurement-map with the key set to the
// supplied PSA refval-id
func NewPSAMeasurement(psaRefValID PSARefValID) *Measurement {
Expand All @@ -269,6 +301,13 @@ func NewUUIDMeasurement(uuid UUID) *Measurement {
return m.SetKeyUUID(uuid)
}

// NewUintMeasurement instantiates a new measurement-map with the key set to the
// supplied Uint
func NewUintMeasurement(mkey uint) *Measurement {
m := &Measurement{}
return m.SetKeyUint(mkey)
}

func (o *Measurement) SetVersion(ver string, scheme uint64) *Measurement {
if o != nil {
v := NewVersion().SetVersion(ver).SetScheme(scheme)
Expand Down
8 changes: 8 additions & 0 deletions comid/measurement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ func TestMeasurement_NewUUIDMeasurement_empty_uuid(t *testing.T) {
assert.Nil(t, tv)
}

func TestMeasurement_NewUIntMeasurement_good_uint(t *testing.T) {
var TestUint uint = 35

tv := NewUintMeasurement(TestUint)

assert.NotNil(t, tv)
}

func TestMeasurement_NewPSAMeasurement_empty(t *testing.T) {
emptyPSARefValID := PSARefValID{}

Expand Down
2 changes: 2 additions & 0 deletions comid/test_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"github.com/veraison/eat"
)

var TestUInt uint = 45

var (
TestUUIDString = "31fb5abf-023e-4992-aa4e-95f9c1503bfa"
TestUUID = UUID(uuid.Must(uuid.Parse(TestUUIDString)))
Expand Down

0 comments on commit 09fcc2c

Please sign in to comment.