Add constants
This commit is contained in:
parent
85830aa66a
commit
df8c5dc7ea
4 changed files with 8 additions and 4 deletions
|
@ -1,11 +1,13 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class EcurveKey < AsymmetricKey
|
||||
CURVES = %w[prime256v1 secp384r1].freeze
|
||||
|
||||
###############
|
||||
# Validations #
|
||||
###############
|
||||
|
||||
validates :curve, inclusion: { in: %w[prime256v1 secp384r1] }
|
||||
validates :curve, inclusion: { in: CURVES }
|
||||
|
||||
validates :bits, absence: true
|
||||
end
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class RSAKey < AsymmetricKey
|
||||
BITS = [2048, 4096].freeze
|
||||
|
||||
###############
|
||||
# Validations #
|
||||
###############
|
||||
|
||||
validates :bits, inclusion: { in: [2048, 4096] }
|
||||
validates :bits, inclusion: { in: BITS }
|
||||
|
||||
validates :curve, absence: true
|
||||
end
|
||||
|
|
|
@ -22,6 +22,6 @@ FactoryBot.define do
|
|||
sha1 { Digest::SHA1.hexdigest SecureRandom.hex }
|
||||
sha256 { Digest::SHA256.hexdigest SecureRandom.hex }
|
||||
|
||||
curve { %w[prime256v1 secp384r1].sample }
|
||||
curve { EcurveKey::CURVES.sample }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,6 +11,6 @@ FactoryBot.define do
|
|||
sha1 { Digest::SHA1.hexdigest SecureRandom.hex }
|
||||
sha256 { Digest::SHA256.hexdigest SecureRandom.hex }
|
||||
|
||||
bits { [2048, 4096].sample }
|
||||
bits { RSAKey::BITS.sample }
|
||||
end
|
||||
end
|
||||
|
|
Reference in a new issue