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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. require 'openssl'
  2. class Integer
  3. def humanize
  4. secs = self
  5. [[60, :second], [60, :minute], [24, :hour], [30, :day], [12, :month]].map { |count, name|
  6. if secs > 0
  7. secs, n = self.divmod count
  8. n = n.to_i
  9. "#{n} #{name}#{n > 1 ? 's' : ''}"
  10. end
  11. }.compact.reverse.join(' ')
  12. end
  13. end
  14. class ::OpenSSL::PKey::EC
  15. def type
  16. :ecc
  17. end
  18. def size
  19. self.group.degree
  20. end
  21. def rsa_equivalent_size
  22. case self.size
  23. when 160 then 1024
  24. when 224 then 2048
  25. when 256 then 3072
  26. when 384 then 7680
  27. when 521 then 15360
  28. when 571 then 21000
  29. end
  30. end
  31. def to_s
  32. "ECC #{self.size} bits"
  33. end
  34. end
  35. class ::OpenSSL::PKey::RSA
  36. def type
  37. :rsa
  38. end
  39. def size
  40. self.n.num_bits
  41. end
  42. def rsa_equivalent_size
  43. self.size
  44. end
  45. def to_s
  46. "RSA #{self.size} bits"
  47. end
  48. end
  49. class ::OpenSSL::PKey::DSA
  50. def type
  51. :dsa
  52. end
  53. def size
  54. self.p.num_bits
  55. end
  56. def rsa_equivalent_size
  57. self.size
  58. end
  59. def to_s
  60. "DSA #{self.size} bits"
  61. end
  62. end
  63. class ::OpenSSL::PKey::DH
  64. def type
  65. :dh
  66. end
  67. def size
  68. self.p.num_bits
  69. end
  70. def rsa_equivalent_size
  71. self.size
  72. end
  73. def to_s
  74. "DH #{self.size} bits"
  75. end
  76. end