1
0
Fork 0

Add attribute AsymmetricKey#has_password

This commit is contained in:
Alex Kotov 2019-09-14 01:48:33 +05:00
parent 78c2df4cce
commit f354cdbe27
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
5 changed files with 13 additions and 3 deletions

View file

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

View file

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

View file

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

View file

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

View file

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