From a8d666a5f10937d03cc64b1a7d20081deb5fc82c Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Fri, 13 Sep 2019 23:58:30 +0500 Subject: [PATCH] Rename primitive PublicKeyPrivateKey to PrivateKey --- .../private_keys_controller.rb | 3 +-- app/primitives/private_key.rb | 18 ++++++++++++++++++ app/primitives/public_key_private_key.rb | 18 ------------------ .../staffs/x509_certificates/show.html.erb | 2 +- ...private_key_spec.rb => private_key_spec.rb} | 2 +- 5 files changed, 21 insertions(+), 22 deletions(-) create mode 100644 app/primitives/private_key.rb delete mode 100644 app/primitives/public_key_private_key.rb rename spec/primitives/{public_key_private_key_spec.rb => private_key_spec.rb} (69%) diff --git a/app/controllers/staffs/x509_certificates/private_keys_controller.rb b/app/controllers/staffs/x509_certificates/private_keys_controller.rb index 69fa685..12823ee 100644 --- a/app/controllers/staffs/x509_certificates/private_keys_controller.rb +++ b/app/controllers/staffs/x509_certificates/private_keys_controller.rb @@ -7,8 +7,7 @@ class Staffs::X509Certificates::PrivateKeysController < ApplicationController # GET /staff/x509_certificates/:x509_certificate_id/private_key def show - authorize [:staff, X509Certificate, - PublicKeyPrivateKey.new(@asymmetric_key)] + authorize [:staff, X509Certificate, PrivateKey.new(@asymmetric_key)] @asymmetric_key.decrypt_private_key_pem diff --git a/app/primitives/private_key.rb b/app/primitives/private_key.rb new file mode 100644 index 0000000..74e1d47 --- /dev/null +++ b/app/primitives/private_key.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class PrivateKey + attr_reader :asymmetric_key + + def self.policy_class + 'PrivateKeyPolicy' + end + + def initialize(asymmetric_key) + @asymmetric_key = asymmetric_key or raise + end + + def exist? + asymmetric_key.private_key_pem_iv.present? && + asymmetric_key.private_key_pem_ciphertext.present? + end +end diff --git a/app/primitives/public_key_private_key.rb b/app/primitives/public_key_private_key.rb deleted file mode 100644 index a406204..0000000 --- a/app/primitives/public_key_private_key.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -class PublicKeyPrivateKey - attr_reader :public_key - - def self.policy_class - 'PrivateKeyPolicy' - end - - def initialize(public_key) - @public_key = public_key or raise - end - - def exist? - public_key.private_key_pem_iv.present? && - public_key.private_key_pem_ciphertext.present? - end -end diff --git a/app/views/staffs/x509_certificates/show.html.erb b/app/views/staffs/x509_certificates/show.html.erb index 095d891..4469d44 100644 --- a/app/views/staffs/x509_certificates/show.html.erb +++ b/app/views/staffs/x509_certificates/show.html.erb @@ -69,7 +69,7 @@ <% if policy([ :staff, X509Certificate, - PublicKeyPrivateKey.new(@x509_certificate.asymmetric_key), + PrivateKey.new(@x509_certificate.asymmetric_key), ]).show? %>