From 2a3be5adc71b33fd0ee87dcf4c3152469bf9f8d8 Mon Sep 17 00:00:00 2001 From: Matthias Glastra Date: Wed, 25 Sep 2024 22:49:03 +0200 Subject: [PATCH] chore: Make the gitbinhash ouput a DigestSet. Signed-off-by: Matthias Glastra --- attestation/git/git.go | 2 +- attestation/git/git_bin.go | 12 +++++------- schemagen/git.json | 2 +- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/attestation/git/git.go b/attestation/git/git.go index 1ddb0155..e61a0af6 100644 --- a/attestation/git/git.go +++ b/attestation/git/git.go @@ -81,7 +81,7 @@ type Tag struct { type Attestor struct { GitTool string `json:"gittool"` GitBinPath string `json:"gitbinpath,omitempty"` - GitBinHash string `json:"gitbinhash,omitempty"` + GitBinHash cryptoutil.DigestSet `json:"gitbinhash,omitempty"` CommitHash string `json:"commithash"` Author string `json:"author"` AuthorEmail string `json:"authoremail"` diff --git a/attestation/git/git_bin.go b/attestation/git/git_bin.go index e2078347..964dbf6e 100644 --- a/attestation/git/git_bin.go +++ b/attestation/git/git_bin.go @@ -48,24 +48,22 @@ func GitGetBinPath() (string, error) { // GitGetBinHash retrieves a sha256 hash of the git binary that is located on the system. // The path is determined based on exec.LookPath(). -func GitGetBinHash(ctx *attestation.AttestationContext) (string, error) { +func GitGetBinHash(ctx *attestation.AttestationContext) (cryptoutil.DigestSet, error) { path, err := exec.LookPath("git") if err != nil { - return "", err + return cryptoutil.DigestSet{}, err } gitBinDigest, err := cryptoutil.CalculateDigestSetFromFile(path, ctx.Hashes()) - fmt.Printf("%s", gitBinDigest) if err != nil { - return "", err + return cryptoutil.DigestSet{}, err } - digestMap, err := gitBinDigest.ToNameMap() if err != nil { - return "", err + return cryptoutil.DigestSet{}, err } - return fmt.Sprintf("sha256:%s", digestMap["sha256"]), nil + return gitBinDigest, nil } // GitGetStatus retrieves the status of staging and worktree diff --git a/schemagen/git.json b/schemagen/git.json index 54270a72..06f68704 100644 --- a/schemagen/git.json +++ b/schemagen/git.json @@ -11,7 +11,7 @@ "type": "string" }, "gitbinhash": { - "type": "string" + "$ref": "#/$defs/DigestSet" }, "commithash": { "type": "string"