grade.go 815 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package fp
  2. import "fmt"
  3. // Grade represents a TLS client security grade
  4. type Grade uint8
  5. // String returns a string representation of the grade
  6. func (a Grade) String() string {
  7. switch a {
  8. case GradeEmpty:
  9. return "empty"
  10. case GradeA:
  11. return "A"
  12. case GradeB:
  13. return "B"
  14. case GradeC:
  15. return "C"
  16. case GradeF:
  17. return "F"
  18. default:
  19. return fmt.Sprintf("Grade(%d)", uint8(a))
  20. }
  21. }
  22. // Merge returns the weakest of two security grades
  23. func (a Grade) Merge(b Grade) Grade {
  24. if a > b {
  25. return a
  26. }
  27. return b
  28. }
  29. // Sources:
  30. // - https://jhalderm.com/pub/papers/interception-ndss17.pdf
  31. const (
  32. GradeEmpty Grade = iota // no grade assigned
  33. GradeA // optimal
  34. GradeB // suboptimal
  35. GradeC // known attack
  36. GradeF // trivially broken
  37. )