(raw []byte, ref string, digest string, dest proto.Message)
| 241 | } |
| 242 | |
| 243 | func unmarshallResource(raw []byte, ref string, digest string, dest proto.Message) (*PolicyDescriptor, error) { |
| 244 | jsonContent, err := unmarshal.LoadJSONBytes(raw, filepath.Ext(ref)) |
| 245 | if err != nil { |
| 246 | return nil, fmt.Errorf("loading resource spec: %w", err) |
| 247 | } |
| 248 | |
| 249 | if err := protojson.Unmarshal(jsonContent, dest); err != nil { |
| 250 | return nil, fmt.Errorf("unmarshalling policy spec: %w", err) |
| 251 | } |
| 252 | |
| 253 | // calculate hash of the raw data |
| 254 | h, _, err := crv1.SHA256(bytes.NewBuffer(raw)) |
| 255 | if err != nil { |
| 256 | return nil, fmt.Errorf("calculating hash: %w", err) |
| 257 | } |
| 258 | |
| 259 | // compare it with the wanted digest if needed |
| 260 | if digest != "" && h.String() != digest { |
| 261 | return nil, fmt.Errorf("digest mismatch: got %s, want %s", h.String(), digest) |
| 262 | } |
| 263 | |
| 264 | return policyReferenceResourceDescriptor("", ref, "", h), nil |
| 265 | } |
| 266 | |
| 267 | // IsProviderScheme takes a policy reference and returns whether it's referencing to an external provider or not |
| 268 | func IsProviderScheme(ref string) bool { |
no test coverage detected