Class: Passifier::Signing

Inherits:
Object
  • Object
show all
Defined in:
lib/passifier/signing.rb

Overview

Class for Pass signing functionality

Instance Method Summary collapse

Constructor Details

#initialize(key_pem, pass_phrase, certificate_pem) ⇒ Signing

Returns a new instance of Signing.

Parameters:

  • key_pem (String)

    The key pem file location

  • pass_phrase (String)

    The key pass phrase

  • certificate_pem (String)

    The certificate pem file location



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

Parameters:

  • content (String)

    The content to generate a digest from

Returns:

  • (String)

    The resulting digest



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

Parameters:

  • content (String)

    The content to generate a signing of

Returns:

  • (String)

    The resulting signing



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