move artifact package over

Signed-off-by: Meredith Lancaster <malancas@github.com>
This commit is contained in:
Meredith Lancaster 2024-03-01 16:16:20 -07:00
parent 3a08c03cc7
commit 97c10f4c04
10 changed files with 525 additions and 1 deletions

View file

@ -0,0 +1,25 @@
package artifact
import (
"fmt"
"os"
"github.com/github/gh-attestation/pkg/artifact/digest"
)
func digestLocalFileArtifact(filename, digestAlg string) (*DigestedArtifact, error) {
data, err := os.Open(filename)
if err != nil {
return nil, fmt.Errorf("failed to get open local artifact: %w", err)
}
defer data.Close()
digest, err := digest.CalculateDigestWithAlgorithm(data, digestAlg)
if err != nil {
return nil, fmt.Errorf("failed to calculate local artifact digest: %w", err)
}
return &DigestedArtifact{
URL: fmt.Sprintf("file://%s", filename),
digest: digest,
digestAlg: digestAlg,
}, nil
}