Skip to content

Commit

Permalink
vmsdk: update golang impl and app code
Browse files Browse the repository at this point in the history
* update the golang implementation to align with python
* update application code accordingly

Signed-off-by: Ruoyu Ying <[email protected]>
  • Loading branch information
Ruoyu-y committed Apr 1, 2024
1 parent 924e11f commit 95dc2c7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/golang/cctrusted_vm/cmd/app/eventlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ var eventLogDumpCmd = &cobra.Command{
return err
}

el.Dump(cctrusted_base.QuoteDumpFormat(FlagFormat))
log.Println("Total ", len(el), " of event logs fetched.")
for _, e := range el {
e.Dump()
}
return nil
},
}
Expand All @@ -49,7 +52,7 @@ var eventLogReplayCmd = &cobra.Command{
return err
}

replay := sdk.ReplayCCEventLog(el.EventLog())
replay := sdk.ReplayCCEventLog(el)
// Or direct `replay := el.Replay()`
for idx, elem := range replay {
for alg, v := range elem {
Expand All @@ -62,7 +65,7 @@ var eventLogReplayCmd = &cobra.Command{
},
}

func filterEventLog() (*cctrusted_base.EventLogger, error) {
func filterEventLog() ([]cctrusted_base.FormatedTcgEvent, error) {
sdk, err := GetSDK()
if err != nil {
return nil, err
Expand Down
25 changes: 21 additions & 4 deletions src/golang/cctrusted_vm/sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package vmsdk
import (
"errors"
"fmt"
"log"
"sync"

cctrusted_vm "github.com/cc-api/cc-trusted-vmsdk/src/golang/cctrusted_vm"
Expand Down Expand Up @@ -62,26 +63,42 @@ func (s *SDK) ReplayCCEventLog(formatedEventLogs []cctrusted_base.FormatedTcgEve
}

// GetDefaultAlgorithm implements cctrusted_base.CCTrustedAPI.
func (s *SDK) GetDefaultAlgorithm() cctrusted_base.TCG_ALG {
return s.cvm.DefaultAlgorithm()
func (s *SDK) GetDefaultAlgorithm() (cctrusted_base.TCG_ALG, error) {
return s.cvm.DefaultAlgorithm(), nil
}

// SelectEventlog implements CCTrustedAPI.
func (s *SDK) GetCCEventLog(start int32, count int32) (*cctrusted_base.EventLogger, error) {
func (s *SDK) GetCCEventLog(params ...int32) ([]cctrusted_base.FormatedTcgEvent, error) {
el, err := s.internelEventlog()
if err != nil {
return nil, err
}
el.Parse()

var start int32
var count int32

// Fetch optional params according to user specification
if len(params) > 2 || len(params) == 0 {
log.Fatalf("Invalid params specified. Using default values.")
start = 0
count = int32(len(el.EventLog()))
} else if len(params) == 2 {
start = params[0]
count = params[1]
} else {
start = params[0]
count = int32(len(el.EventLog())) - start
}

if start != 0 || count != 0 {
el, err = el.Select(int(start), int(count))
if err != nil {
return nil, err
}
}

return el, nil
return el.EventLog(), nil
}

func (s *SDK) internelEventlog() (*cctrusted_base.EventLogger, error) {
Expand Down

0 comments on commit 95dc2c7

Please sign in to comment.