Add attribute AsymmetricKey#has_password
This commit is contained in:
parent
78c2df4cce
commit
f354cdbe27
5 changed files with 13 additions and 3 deletions
|
@ -21,6 +21,8 @@ class RSAKey < AsymmetricKey
|
|||
presence: true,
|
||||
uniqueness: true
|
||||
|
||||
validates :has_password, exclusion: { in: [nil] }
|
||||
|
||||
validates :bits, inclusion: { in: [2048, 4096] }
|
||||
|
||||
validates :sha1,
|
||||
|
|
|
@ -17,9 +17,10 @@ class CreateX509Tables < ActiveRecord::Migration[6.0]
|
|||
t.binary :private_key_pem_iv
|
||||
t.binary :private_key_pem_ciphertext
|
||||
|
||||
t.integer :bits, null: false
|
||||
t.string :sha1, null: false
|
||||
t.string :sha256, null: false
|
||||
t.boolean :has_password, null: false
|
||||
t.integer :bits, null: false
|
||||
t.string :sha1, null: false
|
||||
t.string :sha256, null: false
|
||||
|
||||
t.index :public_key_pem, unique: true
|
||||
t.index :public_key_der, unique: true
|
||||
|
|
|
@ -378,6 +378,7 @@ CREATE TABLE public.asymmetric_keys (
|
|||
public_key_der bytea NOT NULL,
|
||||
private_key_pem_iv bytea,
|
||||
private_key_pem_ciphertext bytea,
|
||||
has_password boolean NOT NULL,
|
||||
bits integer NOT NULL,
|
||||
sha1 character varying NOT NULL,
|
||||
sha256 character varying NOT NULL,
|
||||
|
|
|
@ -6,6 +6,8 @@ FactoryBot.define do
|
|||
|
||||
public_key_pem { OpenSSL::PKey::RSA.new(bits).public_key.to_pem }
|
||||
public_key_der { OpenSSL::PKey::RSA.new(bits).public_key.to_der }
|
||||
|
||||
has_password { [false, true].sample }
|
||||
bits { [2048, 4096].sample }
|
||||
sha1 { Digest::SHA1.hexdigest SecureRandom.hex }
|
||||
sha256 { Digest::SHA256.hexdigest SecureRandom.hex }
|
||||
|
|
|
@ -22,6 +22,10 @@ RSpec.describe RSAKey do
|
|||
it { is_expected.to validate_uniqueness_of :public_key_der }
|
||||
end
|
||||
|
||||
describe '#has_password' do
|
||||
it { is_expected.to validate_exclusion_of(:has_password).in_array([nil]) }
|
||||
end
|
||||
|
||||
describe '#bits' do
|
||||
it { is_expected.to validate_inclusion_of(:bits).in_array([2048, 4096]) }
|
||||
end
|
||||
|
|
Reference in a new issue