| 1 | package signingblock |
| 2 | |
| 3 | import ( |
| 4 | "crypto/x509" |
| 5 | "fmt" |
| 6 | ) |
| 7 | |
| 8 | type VerificationResult struct { |
| 9 | Certs [][]*x509.Certificate |
| 10 | SchemeId int |
| 11 | SigningLineage *V3SigningLineage |
| 12 | |
| 13 | Frosting *FrostingResult |
| 14 | |
| 15 | Warnings []string |
| 16 | Errors []error |
| 17 | } |
| 18 | |
| 19 | type FrostingResult struct { |
| 20 | Error error |
| 21 | KeySha256 string |
| 22 | ProtobufInfo []byte |
| 23 | } |
| 24 | |
| 25 | type certAdder struct { |
| 26 | Certs []*x509.Certificate |
| 27 | |
| 28 | res *VerificationResult |
| 29 | } |
| 30 | |
| 31 | func (r *VerificationResult) addWarning(format string, args ...interface{}) { |
| 32 | r.Warnings = append(r.Warnings, fmt.Sprintf(format, args...)) |
| 33 | } |
| 34 | |
| 35 | func (r *VerificationResult) addError(format string, args ...interface{}) { |
| 36 | r.Errors = append(r.Errors, fmt.Errorf(format, args...)) |
| 37 | } |
| 38 | |
| 39 | func (r *VerificationResult) ContainsErrors() bool { |
| 40 | return len(r.Errors) != 0 |
| 41 | } |
| 42 | |
| 43 | func (r *VerificationResult) GetLastError() error { |
| 44 | if l := len(r.Errors); l != 0 { |
| 45 | return r.Errors[l-1] |
| 46 | } |
| 47 | return nil |
| 48 | } |
| 49 | |
| 50 | func (r *VerificationResult) getCertAdder() certAdder { |
| 51 | return certAdder{ |
| 52 | res: r, |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | func (a *certAdder) append(cert *x509.Certificate) { |
| 57 | a.Certs = append(a.Certs, cert) |
| 58 | if len(a.Certs) == 1 { |
| 59 | a.res.Certs = append(a.res.Certs, a.Certs) |
| 60 | } else { |
| 61 | idx := len(a.res.Certs) - 1 |
| 62 | a.res.Certs[idx] = a.Certs |
| 63 | } |
| 64 | } |