You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fixture.rb 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. require 'openssl'
  2. class String
  3. alias :colorize_old :colorize
  4. COLORS = {
  5. critical: { color: :white, background: :red },
  6. error: :red,
  7. warning: :light_red,
  8. good: :green,
  9. perfect: :blue,
  10. best: :magenta,
  11. unknown: { background: :black }
  12. }
  13. def colorize(state)
  14. self.colorize_old COLORS[state]
  15. end
  16. end
  17. class Integer
  18. def humanize
  19. secs = self
  20. [[60, :second], [60, :minute], [24, :hour], [30, :day], [12, :month]].map { |count, name|
  21. if secs > 0
  22. secs, n = secs.divmod count
  23. n = n.to_i
  24. n > 0 ? "#{n} #{name}#{n > 1 ? 's' : ''}" : nil
  25. end
  26. }.compact.reverse.join(' ')
  27. end
  28. end
  29. class ::OpenSSL::PKey::EC
  30. def type
  31. :ecc
  32. end
  33. def size
  34. self.group.degree
  35. end
  36. def to_s
  37. "ECC #{self.size} bits"
  38. end
  39. def status
  40. case self.size
  41. when 0...160 then :critical
  42. when 160...192 then :error
  43. when 192...256 then :warning
  44. when 384...::Float::INFINITY then :good
  45. end
  46. end
  47. end
  48. class ::OpenSSL::PKey::RSA
  49. def type
  50. :rsa
  51. end
  52. def size
  53. self.n.num_bits
  54. end
  55. def to_s
  56. "RSA #{self.size} bits"
  57. end
  58. def status
  59. case self.size
  60. when 0...1024 then :critical
  61. when 1024...2048 then :error
  62. when 4096...::Float::INFINITY then :good
  63. end
  64. end
  65. end
  66. class ::OpenSSL::PKey::DSA
  67. def type
  68. :dsa
  69. end
  70. def size
  71. self.p.num_bits
  72. end
  73. def to_s
  74. "DSA #{self.size} bits"
  75. end
  76. def status
  77. return :critical
  78. end
  79. end
  80. class ::OpenSSL::PKey::DH
  81. def type
  82. :dh
  83. end
  84. def size
  85. self.p.num_bits
  86. end
  87. def to_s
  88. "DH #{self.size} bits"
  89. end
  90. def status
  91. case self.size
  92. when 0...1024 then :critical
  93. when 1024...2048 then :error
  94. when 4096...::Float::INFINITY then :good
  95. end
  96. end
  97. end