resultset.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * ZLint Copyright 2021 Regents of the University of Michigan
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy
  6. * of the License at http://www.apache.org/licenses/LICENSE-2.0
  7. *
  8. * Unless required by applicable law or agreed to in writing, software
  9. * distributed under the License is distributed on an "AS IS" BASIS,
  10. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  11. * implied. See the License for the specific language governing
  12. * permissions and limitations under the License.
  13. */
  14. package zlint
  15. import (
  16. "github.com/zmap/zcrypto/x509"
  17. "github.com/zmap/zlint/v3/lint"
  18. )
  19. // ResultSet contains the output of running all lints in a registry against
  20. // a single certificate.
  21. type ResultSet struct {
  22. Version int64 `json:"version"`
  23. Timestamp int64 `json:"timestamp"`
  24. Results map[string]*lint.LintResult `json:"lints"`
  25. NoticesPresent bool `json:"notices_present"`
  26. WarningsPresent bool `json:"warnings_present"`
  27. ErrorsPresent bool `json:"errors_present"`
  28. FatalsPresent bool `json:"fatals_present"`
  29. }
  30. // Execute lints the given certificate with all of the lints in the provided
  31. // registry. The ResultSet is mutated to trace the lint results obtained from
  32. // linting the certificate.
  33. func (z *ResultSet) execute(cert *x509.Certificate, registry lint.Registry) {
  34. z.Results = make(map[string]*lint.LintResult, len(registry.Names()))
  35. // Run each lints from the registry.
  36. for _, name := range registry.Names() {
  37. res := registry.ByName(name).Execute(cert)
  38. z.Results[name] = res
  39. z.updateErrorStatePresent(res)
  40. }
  41. }
  42. func (z *ResultSet) updateErrorStatePresent(result *lint.LintResult) {
  43. switch result.Status {
  44. case lint.Notice:
  45. z.NoticesPresent = true
  46. case lint.Warn:
  47. z.WarningsPresent = true
  48. case lint.Error:
  49. z.ErrorsPresent = true
  50. case lint.Fatal:
  51. z.FatalsPresent = true
  52. }
  53. }