Class: MrSmime::Certificate
- Inherits:
-
Object
- Object
- MrSmime::Certificate
- Includes:
- OpenSSL
- Defined in:
- lib/mr_smime/certificate.rb
Class Method Summary collapse
Instance Method Summary collapse
- #ca_bundles ⇒ Object
- #certificate ⇒ Object
- #certificate_path ⇒ Object
- #filename(extension) ⇒ Object
-
#initialize(email) ⇒ Certificate
constructor
A new instance of Certificate.
- #present? ⇒ Boolean
- #private_key ⇒ Object
- #private_key_path ⇒ Object
Constructor Details
#initialize(email) ⇒ Certificate
25 26 27 |
# File 'lib/mr_smime/certificate.rb', line 25 def initialize(email) @email = email end |
Class Method Details
.exist?(email) ⇒ Boolean
13 14 15 |
# File 'lib/mr_smime/certificate.rb', line 13 def self.exist?(email) new(email).present? end |
.filename(email, extension) ⇒ Object
21 22 23 |
# File 'lib/mr_smime/certificate.rb', line 21 def self.filename(email, extension) email.tr('@', '.') + '.' + extension.to_s end |
.find(email) ⇒ Object
7 8 9 10 11 |
# File 'lib/mr_smime/certificate.rb', line 7 def self.find(email) return unless exist?(email) new(email) end |
.root ⇒ Object
17 18 19 |
# File 'lib/mr_smime/certificate.rb', line 17 def self.root MrSmime.configuration.certificate_path end |
Instance Method Details
#ca_bundles ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/mr_smime/certificate.rb', line 37 def ca_bundles pem_header = '-----BEGIN CERTIFICATE-----' # drop(2): blank item, original certificate File.read(certificate_path).split(pem_header).drop(2).map { |cert| X509::Certificate.new(pem_header + cert) } end |
#certificate ⇒ Object
33 34 35 |
# File 'lib/mr_smime/certificate.rb', line 33 def certificate X509::Certificate.new(File.read(certificate_path)) end |
#certificate_path ⇒ Object
45 46 47 |
# File 'lib/mr_smime/certificate.rb', line 45 def certificate_path filename(:pem) end |
#filename(extension) ⇒ Object
57 58 59 |
# File 'lib/mr_smime/certificate.rb', line 57 def filename(extension) File.join Certificate.root, Certificate.filename(@email, extension) end |
#present? ⇒ Boolean
29 30 31 |
# File 'lib/mr_smime/certificate.rb', line 29 def present? File.exist? certificate_path end |
#private_key ⇒ Object
49 50 51 |
# File 'lib/mr_smime/certificate.rb', line 49 def private_key PKey::RSA.new(File.read(private_key_path)) end |
#private_key_path ⇒ Object
53 54 55 |
# File 'lib/mr_smime/certificate.rb', line 53 def private_key_path filename(:key) end |