| 30 | } |
| 31 | |
| 32 | func FilterAttestations(predicateType string, attestations []*Attestation) ([]*Attestation, error) { |
| 33 | filteredAttestations := []*Attestation{} |
| 34 | |
| 35 | for _, each := range attestations { |
| 36 | dsseEnvelope := each.Bundle.GetDsseEnvelope() |
| 37 | if dsseEnvelope != nil { |
| 38 | if dsseEnvelope.PayloadType != "application/vnd.in-toto+json" { |
| 39 | // Don't fail just because an entry isn't intoto |
| 40 | continue |
| 41 | } |
| 42 | var intotoStatement IntotoStatement |
| 43 | if err := json.Unmarshal([]byte(dsseEnvelope.Payload), &intotoStatement); err != nil { |
| 44 | // Don't fail just because a single entry can't be unmarshalled |
| 45 | continue |
| 46 | } |
| 47 | if intotoStatement.PredicateType == predicateType { |
| 48 | filteredAttestations = append(filteredAttestations, each) |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | if len(filteredAttestations) == 0 { |
| 54 | return nil, fmt.Errorf("no attestations found with predicate type: %s", predicateType) |
| 55 | } |
| 56 | |
| 57 | return filteredAttestations, nil |
| 58 | } |