Class: R509::SPKI
- Inherits:
-
Object
- Object
- R509::SPKI
- Defined in:
- lib/r509/spki.rb
Overview
class for loading/generating SPKAC/SPKI requests (typically generated by the <keygen> tag
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#spki ⇒ Object
(also: #internal_obj)
readonly
Returns the value of attribute spki.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ SPKI
constructor
A new instance of SPKI.
-
#public_key ⇒ OpenSSL::PKey::RSA
Public key.
-
#signature_algorithm ⇒ String
Returns the signature algorithm (e.g., RSA-SHA1, ecdsa-with-SHA256).
-
#verify_signature ⇒ Boolean
Verifies the integrity of the signature on the SPKI.
Methods included from Helpers
#bit_length, #curve_name, #dsa?, #ec?, #key_algorithm, #load_private_key, #rsa?, #to_der, #to_pem, #write_der, #write_pem
Methods included from IOHelpers
#read_data, read_data, write_data, #write_data
Constructor Details
#initialize(opts = {}) ⇒ SPKI
Returns a new instance of SPKI.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/r509/spki.rb', line 16 def initialize(opts = {}) if !opts.is_a?(Hash) raise ArgumentError, 'Must provide a hash of options' elsif !opts.key?(:spki) && !opts.key?(:key) raise ArgumentError, 'Must provide either :spki or :key' end @key = load_private_key(opts) if opts.key?(:spki) @spki = parse_spki(opts[:spki]) else # create the SPKI from the private key if it wasn't passed in @spki = build_spki(opts[:message_digest]) end end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
12 13 14 |
# File 'lib/r509/spki.rb', line 12 def key @key end |
#spki ⇒ Object (readonly) Also known as: internal_obj
Returns the value of attribute spki.
12 13 14 |
# File 'lib/r509/spki.rb', line 12 def spki @spki end |
Instance Method Details
#public_key ⇒ OpenSSL::PKey::RSA
Returns public key.
34 35 36 |
# File 'lib/r509/spki.rb', line 34 def public_key @spki.public_key end |
#signature_algorithm ⇒ String
Returns the signature algorithm (e.g., RSA-SHA1, ecdsa-with-SHA256)
49 50 51 52 |
# File 'lib/r509/spki.rb', line 49 def signature_algorithm data = OpenSSL::ASN1.decode(self.to_der) data.entries[1].value.entries[0].value end |
#verify_signature ⇒ Boolean
Verifies the integrity of the signature on the SPKI
40 41 42 |
# File 'lib/r509/spki.rb', line 40 def verify_signature @spki.verify(public_key) end |