Class: Passifier::Signing
- Inherits:
-
Object
- Object
- Passifier::Signing
- Defined in:
- lib/passifier/signing.rb
Overview
Class for Pass signing functionality
Instance Method Summary collapse
-
#initialize(key_pem, pass_phrase, certificate_pem) ⇒ Signing
constructor
A new instance of Signing.
-
#sha(content) ⇒ String
Generate a digest of the given content.
-
#sign(content) ⇒ String
Sign the given content.
Constructor Details
#initialize(key_pem, pass_phrase, certificate_pem) ⇒ Signing
Returns a new instance of Signing.
11 12 13 14 15 |
# File 'lib/passifier/signing.rb', line 11 def initialize(key_pem, pass_phrase, certificate_pem) @certificate = File.read(certificate_pem) @key = File.read(key_pem) @pass_phrase = pass_phrase end |
Instance Method Details
#sha(content) ⇒ String
Generate a digest of the given content
20 21 22 23 |
# File 'lib/passifier/signing.rb', line 20 def sha(content) signed_contents = sign(content) Digest::SHA1.hexdigest(signed_contents) end |
#sign(content) ⇒ String
Sign the given content
28 29 30 31 32 |
# File 'lib/passifier/signing.rb', line 28 def sign(content) key = OpenSSL::PKey::RSA.new(@key, @pass_phrase) certificate = OpenSSL::X509::Certificate.new(@certificate) OpenSSL::PKCS7.sign(certificate, key, content, nil, OpenSSL::PKCS7::BINARY | OpenSSL::PKCS7::NOATTR | OpenSSL::PKCS7::DETACHED).to_der end |