1
0
Fork 0

Set RSAPublicKey#sha1, #sha256

This commit is contained in:
Alex Kotov 2019-09-12 10:07:25 +05:00
parent abcdea4e43
commit a9484918a5
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
2 changed files with 27 additions and 0 deletions

View file

@ -11,6 +11,9 @@ class CreateRSAKeys
public_key.bits = BITS
public_key.sha1 = Digest::SHA1.hexdigest pkey.public_key.to_der
public_key.sha256 = Digest::SHA256.hexdigest pkey.public_key.to_der
public_key.public_key_pem = pkey.public_key.to_pem.freeze
public_key.private_key_pem = pkey.to_pem.freeze

View file

@ -13,6 +13,14 @@ RSpec.describe CreateRSAKeys do
expect(subject.public_key).to be_instance_of RSAPublicKey
end
specify do
expect(subject.public_key.sha1).not_to be_blank
end
specify do
expect(subject.public_key.sha256).not_to be_blank
end
specify do
expect(subject.public_key.private_key_pem).not_to be_blank
end
@ -32,6 +40,22 @@ RSpec.describe CreateRSAKeys do
raise_error
end
specify do
expect(subject.public_key.sha1).to eq(
Digest::SHA1.hexdigest(
OpenSSL::PKey::RSA.new(subject.public_key.public_key_pem).to_der,
),
)
end
specify do
expect(subject.public_key.sha256).to eq(
Digest::SHA256.hexdigest(
OpenSSL::PKey::RSA.new(subject.public_key.public_key_pem).to_der,
),
)
end
specify do
expect(subject.public_key.public_key_pem).to eq(
OpenSSL::PKey::RSA.new(subject.public_key.private_key_pem)