This repository has been archived by the owner on Nov 18, 2021. It is now read-only.
forked from edwinfrc/voucher
-
Notifications
You must be signed in to change notification settings - Fork 2
/
attestation.go
56 lines (49 loc) · 1.58 KB
/
attestation.go
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package voucher
import (
"github.com/grafeas/voucher/signer"
)
// Attestation is a structure that contains the Attestation data that we want
// to create an MetadataItem from.
type Attestation struct {
CheckName string
Body string
}
// NewAttestation creates a new Attestation for the check with the passed name,
// with the payload as the body. The payload will then be signed by the key associated
// with the check (referenced by the checkName).
func NewAttestation(checkName string, payload string) Attestation {
return Attestation{
CheckName: checkName,
Body: payload,
}
}
// SignedAttestation is a structure that contains the Attestation data as well
// as the signature and signing key ID.
type SignedAttestation struct {
Attestation
Signature string
KeyID string
}
// SignAttestation takes a keyring and attestation and signs the body of the
// payload with it, updating the Attestation's Signature field.
func SignAttestation(s signer.AttestationSigner, attestation Attestation) (SignedAttestation, error) {
signature, keyID, err := s.Sign(attestation.CheckName, attestation.Body)
if nil != err {
return SignedAttestation{}, err
}
return SignedAttestation{
Attestation: attestation,
Signature: signature,
KeyID: keyID,
}, nil
}
// SignedAttestationToResult returns a CheckResults from the SignedAttestation
// passed to it. Check names is set as appropriate.
func SignedAttestationToResult(attestation SignedAttestation) CheckResult {
return CheckResult{
Name: attestation.CheckName,
Success: true,
Attested: true,
Details: attestation,
}
}