1
0
Fork 0

Add constants

This commit is contained in:
Alex Kotov 2019-09-14 04:22:45 +05:00
parent 85830aa66a
commit df8c5dc7ea
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
4 changed files with 8 additions and 4 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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