From a9484918a5e5e94db0fd3308f5f3f1cb537cd9ab Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Thu, 12 Sep 2019 10:07:25 +0500 Subject: [PATCH] Set RSAPublicKey#sha1, #sha256 --- app/interactors/create_rsa_keys.rb | 3 +++ spec/interactors/create_rsa_keys_spec.rb | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/app/interactors/create_rsa_keys.rb b/app/interactors/create_rsa_keys.rb index 64f816c..27e1961 100644 --- a/app/interactors/create_rsa_keys.rb +++ b/app/interactors/create_rsa_keys.rb @@ -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 diff --git a/spec/interactors/create_rsa_keys_spec.rb b/spec/interactors/create_rsa_keys_spec.rb index 9f68442..b1a51dc 100644 --- a/spec/interactors/create_rsa_keys_spec.rb +++ b/spec/interactors/create_rsa_keys_spec.rb @@ -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)