Skip to content

Commit

Permalink
golang: update api
Browse files Browse the repository at this point in the history
align golang api with python one

Signed-off-by: Ruoyu Ying <[email protected]>
  • Loading branch information
Ruoyu-y authored and dongx1x committed Oct 16, 2024
1 parent df05311 commit 954b05b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion sdk/golang/cima/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func GetContainerId() string {
return ""
}

func (cc *Client) GetCCReportFromServer(userData string, nonce string) (pb.GetCcReportResponse, error) {
func (cc *Client) GetCCReportFromServer(userData, nonce string) (pb.GetCcReportResponse, error) {
var ContainerId = GetContainerId()
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
Expand Down
8 changes: 6 additions & 2 deletions sdk/golang/cima/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package cima

import (
b64 "encoding/base64"
"errors"
"log"

Expand All @@ -19,14 +20,17 @@ type SDK struct {
}

// GetCCReport implements EvidenceAPI
func (s *SDK) GetCCReport(nonce, userData string, extraArgs map[string]any) (evidence_api.Report, error) {
func (s *SDK) GetCCReport(nonce, userData []byte, extraArgs map[string]any) (evidence_api.Report, error) {
client, err := NewClient()
if err != nil {
log.Fatalf("[GetCCReport] failed to connect to client with error %v", err)
return nil, err
}

result, err := client.GetCCReportFromServer(userData, nonce)
nonceStr := b64.StdEncoding.EncodeToString(nonce)
userDataStr := b64.StdEncoding.EncodeToString(userData)

result, err := client.GetCCReportFromServer(userDataStr, nonceStr)
if err != nil {
return nil, err
}
Expand Down
9 changes: 3 additions & 6 deletions sdk/golang/example/go-sdk-example.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
b64 "encoding/base64"
"encoding/binary"
"log"
"math"
Expand All @@ -17,12 +16,10 @@ func testGetCCReport(sdk cima.SDK, logger *log.Logger) {
logger.Println("Call [GetCCReport] to fetch attestation report...")

num := uint64(rand.Int63n(math.MaxInt64))
b := make([]byte, 8)
binary.LittleEndian.PutUint64(b, num)
nonce := b64.StdEncoding.EncodeToString(b)
nonce := make([]byte, 8)
binary.LittleEndian.PutUint64(nonce, num)

rawBytes := []byte("demo user data")
userData := b64.StdEncoding.EncodeToString(rawBytes)
userData := []byte("demo user data")
report, err := sdk.GetCCReport(nonce, userData, nil)
if err != nil {
logger.Println("Error in fetching cc report.")
Expand Down

0 comments on commit 954b05b

Please sign in to comment.