Skip to content

Commit

Permalink
[WIP] Further work on the tests
Browse files Browse the repository at this point in the history
Signed-off-by: Yogesh Deshpande <[email protected]>
  • Loading branch information
yogeshbdeshpande committed Feb 21, 2024
1 parent e896c0d commit 9f6e172
Showing 1 changed file with 36 additions and 10 deletions.
46 changes: 36 additions & 10 deletions comid/example_cca_realm_refval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package comid

import (
"fmt"
"strings"
)

func Example_cca_realm_refval() {
Expand Down Expand Up @@ -131,22 +132,26 @@ func extractRealmInstanceID(i *Instance) error {
}

func extractRealmMeasurements(r *IntegrityRegisters) error {

if r == nil {
return fmt.Errorf("no integrity registers")
}

for i, r := range r.m {
switch t := i.(type) {
case string:
fmt.Printf("Index: %s\n", t)
if err := extractRealmDigests(r); err != nil {
return fmt.Errorf("invalid Digests for key: %s, %v", t, err)
}
default:
return fmt.Errorf("unexpected type for index: %T", t)
keys, err := extractRegisterIndex(r)
if err != nil {
return fmt.Errorf("unable to extract register index: %v", err)
}

for _, k := range keys {
d, ok := r.m[k]
if !ok {
return fmt.Errorf("unable to locate register index for: %s", k)
}
fmt.Printf("Index: %s\n", k)
if err := extractRealmDigests(d); err != nil {
return fmt.Errorf("invalid Digests for key: %s, %v", k, err)
}
}

return nil
}

Expand All @@ -162,3 +167,24 @@ func extractRealmDigests(digests Digests) error {

return nil
}

func extractRegisterIndex(r *IntegrityRegisters) ([]string, error) {
var keys [2]string
for k := range r.m {
switch t := k.(type) {
case string:
key := strings.ToLower(t)
switch key {
case "rim":
keys[0] = key
case "rem":
keys[1] = key
default:
return nil, fmt.Errorf("unexpected register index: %s", key)
}
default:
return nil, fmt.Errorf("unexpected type for index: %T", t)
}
}
return keys[:], nil
}

0 comments on commit 9f6e172

Please sign in to comment.