forked from veraison/corim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcryptokeys.go
More file actions
37 lines (30 loc) · 818 Bytes
/
Copy pathcryptokeys.go
File metadata and controls
37 lines (30 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright 2023 Contributors to the Veraison project.
// SPDX-License-Identifier: Apache-2.0
package comid
import "fmt"
// CryptoKeys is an array of *CryptoKey
type CryptoKeys []*CryptoKey
// NewCryptoKeys instantiates an empty CryptoKeys
func NewCryptoKeys() *CryptoKeys {
return new(CryptoKeys)
}
// Add the supplied *CryptoKey to the CryptoKeys
func (o *CryptoKeys) Add(v *CryptoKey) *CryptoKeys {
if o != nil && v != nil {
*o = append(*o, v)
}
return o
}
// Valid returns an error if any of the contained keys fail to validate, or if
// CryptoKeys is empty
func (o CryptoKeys) Valid() error {
if len(o) == 0 {
return fmt.Errorf("no keys to validate")
}
for i, vk := range o {
if err := vk.Valid(); err != nil {
return fmt.Errorf("invalid key at index %d: %w", i, err)
}
}
return nil
}