(attestations []*api.Attestation, fileDigest string)
| 74 | } |
| 75 | |
| 76 | func FilterAttestationsByFileDigest(attestations []*api.Attestation, fileDigest string) ([]*api.Attestation, error) { |
| 77 | var filtered []*api.Attestation |
| 78 | for _, att := range attestations { |
| 79 | statement := att.Bundle.Bundle.GetDsseEnvelope().Payload |
| 80 | var statementData v1.Statement |
| 81 | err := protojson.Unmarshal([]byte(statement), &statementData) |
| 82 | |
| 83 | if err != nil { |
| 84 | return nil, fmt.Errorf("failed to unmarshal statement: %w", err) |
| 85 | } |
| 86 | subjects := statementData.Subject |
| 87 | for _, subject := range subjects { |
| 88 | digestMap := subject.GetDigest() |
| 89 | alg := "sha256" |
| 90 | |
| 91 | digest := digestMap[alg] |
| 92 | if digest == fileDigest { |
| 93 | filtered = append(filtered, att) |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | } |
| 98 | return filtered, nil |
| 99 | } |
| 100 | |
| 101 | // buildVerificationPolicy constructs a verification policy for GitHub releases |
| 102 | func buildVerificationPolicy(a artifact.DigestedArtifact, trustDomain string) verify.PolicyBuilder { |
no test coverage detected