mirror of
https://github.com/slsa-framework/slsa-verifier.git
synced 2026-05-08 17:46:35 +00:00
* update * update * unit tests * update * comments * update * update * update * update * Use interface for builders * update * update * update * update * fix * update * update * update * update * update * update * update * update * update * update * update * update
37 lines
1.1 KiB
Go
37 lines
1.1 KiB
Go
package verifiers
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
serrors "github.com/slsa-framework/slsa-verifier/errors"
|
|
"github.com/slsa-framework/slsa-verifier/options"
|
|
"github.com/slsa-framework/slsa-verifier/register"
|
|
_ "github.com/slsa-framework/slsa-verifier/verifiers/internal/gcb"
|
|
"github.com/slsa-framework/slsa-verifier/verifiers/internal/gha"
|
|
)
|
|
|
|
func Verify(ctx context.Context,
|
|
provenance []byte, artifactHash string,
|
|
provenanceOpts *options.ProvenanceOpts,
|
|
builderOpts *options.BuilderOpts,
|
|
) ([]byte, string, error) {
|
|
// If user provids a builderID, find the right verifier
|
|
// based on its ID.
|
|
if builderOpts.ExpectedID != nil &&
|
|
*builderOpts.ExpectedID != "" {
|
|
for _, v := range register.SLSAVerifiers {
|
|
if v.IsAuthoritativeFor(*builderOpts.ExpectedID) {
|
|
return v.VerifyArtifact(ctx, provenance, artifactHash,
|
|
provenanceOpts, builderOpts)
|
|
}
|
|
}
|
|
// No builder found.
|
|
return nil, "", fmt.Errorf("%w: %s", serrors.ErrorVerifierNotSupported, *builderOpts.ExpectedID)
|
|
}
|
|
|
|
// By default, try the GHA builders.
|
|
return register.SLSAVerifiers[gha.VerifierName].VerifyArtifact(ctx, provenance, artifactHash,
|
|
provenanceOpts, builderOpts)
|
|
}
|