Class: Gem::Security::Signer
- Inherits:
-
Object
- Object
- Gem::Security::Signer
- Defined in:
- lib/rubygems/security.rb
Overview
Basic OpenSSL-based package signing class.
Instance Attribute Summary collapse
-
#cert_chain ⇒ Object
Returns the value of attribute cert_chain.
-
#key ⇒ Object
Returns the value of attribute key.
Instance Method Summary collapse
-
#initialize(key, cert_chain) ⇒ Signer
constructor
A new instance of Signer.
-
#sign(data) ⇒ Object
Sign data with given digest algorithm.
Constructor Details
#initialize(key, cert_chain) ⇒ Signer
Returns a new instance of Signer.
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 |
# File 'lib/rubygems/security.rb', line 488 def initialize(key, cert_chain) Gem.ensure_ssl_available @algo = Gem::Security::OPT[:dgst_algo] @key, @cert_chain = key, cert_chain # check key, if it's a file, and if it's key, leave it alone if @key && !@key.kind_of?(OpenSSL::PKey::PKey) @key = OpenSSL::PKey::RSA.new(File.read(@key)) end # check cert chain, if it's a file, load it, if it's cert data, convert # it into a cert object, and if it's a cert object, leave it alone if @cert_chain @cert_chain = @cert_chain.map do |cert| # check cert, if it's a file, load it, if it's cert data, # convert it into a cert object, and if it's a cert object, # leave it alone if cert && !cert.kind_of?(OpenSSL::X509::Certificate) cert = File.read(cert) if File::exist?(cert) cert = OpenSSL::X509::Certificate.new(cert) end cert end end end |
Instance Attribute Details
#cert_chain ⇒ Object
Returns the value of attribute cert_chain.
486 487 488 |
# File 'lib/rubygems/security.rb', line 486 def cert_chain @cert_chain end |
#key ⇒ Object
Returns the value of attribute key.
486 487 488 |
# File 'lib/rubygems/security.rb', line 486 def key @key end |
Instance Method Details
#sign(data) ⇒ Object
Sign data with given digest algorithm
517 518 519 |
# File 'lib/rubygems/security.rb', line 517 def sign(data) @key.sign(@algo.new, data) end |