Skip to content

Commit

Permalink
chore: Make the gitbinhash ouput a DigestSet.
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Glastra <[email protected]>
  • Loading branch information
matglas committed Sep 25, 2024
1 parent fb9790a commit aa3f65f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion attestation/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
11 changes: 5 additions & 6 deletions attestation/git/git_bin.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,23 @@ 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
Expand Down

0 comments on commit aa3f65f

Please sign in to comment.