Class: R509::Spki
Overview
class for handling SPKAC/SPKI requests (typically generated by the <keygen> tag
Instance Attribute Summary (collapse)
-
- (Object) san_names
readonly
Returns the value of attribute san_names.
-
- (Object) spki
readonly
Returns the value of attribute spki.
-
- (Object) subject
readonly
Returns the value of attribute subject.
Instance Method Summary (collapse)
-
- (Integer) bit_strength
Returns the bit strength of the key used to create the SPKI.
-
- (Boolean) dsa?
Returns whether the public key is DSA.
-
- (Spki) initialize(opts = {})
constructor
you can also pass OIDs (see tests).
-
- (String) key_algorithm
Returns key algorithm (RSA/DSA).
-
- (OpenSSL::PKey::RSA) public_key
Public key.
-
- (Boolean) rsa?
Returns whether the public key is RSA.
-
- (String) to_der
Converts the SPKI into the DER format.
-
- (Hash) to_hash
Returns a hash structure you can pass to the Ca You will want to call this method if you intend to alter the values and then pass them to the Ca class.
-
- (String) to_pem
(also: #to_s)
Converts the SPKI into the PEM format.
-
- (Object) write_der(filename_or_io)
Writes the SPKI into the DER format.
-
- (Object) write_pem(filename_or_io)
Writes the SPKI into the PEM format.
Methods included from IOHelpers
#read_data, read_data, #write_data, write_data
Constructor Details
- (Spki) initialize(opts = {})
you can also pass OIDs (see tests)
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/r509/spki.rb', line 16 def initialize(opts={}) if not opts.kind_of?(Hash) raise ArgumentError, 'Must provide a hash of options' end if opts.has_key?(:spki) and not opts.has_key?(:subject) raise ArgumentError, "Must provide both spki and subject" end if opts.has_key?(:san_names) and not opts[:san_names].kind_of?(Array) raise ArgumentError, "if san_names are provided they must be in an Array" end @spki = OpenSSL::Netscape::SPKI.new(opts[:spki].sub("SPKAC=","")) @subject = R509::Subject.new(opts[:subject]) @san_names = opts[:san_names] || [] end |
Instance Attribute Details
- (Object) san_names (readonly)
Returns the value of attribute san_names
10 11 12 |
# File 'lib/r509/spki.rb', line 10 def san_names @san_names end |
- (Object) spki (readonly)
Returns the value of attribute spki
10 11 12 |
# File 'lib/r509/spki.rb', line 10 def spki @spki end |
- (Object) subject (readonly)
Returns the value of attribute subject
10 11 12 |
# File 'lib/r509/spki.rb', line 10 def subject @subject end |
Instance Method Details
- (Integer) bit_strength
Returns the bit strength of the key used to create the SPKI
84 85 86 87 88 89 90 |
# File 'lib/r509/spki.rb', line 84 def bit_strength if self.rsa? return @spki.public_key.n.num_bits elsif self.dsa? return @spki.public_key.p.num_bits end end |
- (Boolean) dsa?
Returns whether the public key is DSA
78 79 80 |
# File 'lib/r509/spki.rb', line 78 def dsa? @spki.public_key.kind_of?(OpenSSL::PKey::DSA) end |
- (String) key_algorithm
Returns key algorithm (RSA/DSA)
95 96 97 98 99 100 101 |
# File 'lib/r509/spki.rb', line 95 def key_algorithm if @spki.public_key.kind_of? OpenSSL::PKey::RSA then 'RSA' elsif @spki.public_key.kind_of? OpenSSL::PKey::DSA then 'DSA' end end |
- (OpenSSL::PKey::RSA) public_key
Public key
32 33 34 |
# File 'lib/r509/spki.rb', line 32 def public_key @spki.public_key end |
- (Boolean) rsa?
Returns whether the public key is RSA
71 72 73 |
# File 'lib/r509/spki.rb', line 71 def rsa? @spki.public_key.kind_of?(OpenSSL::PKey::RSA) end |
- (String) to_der
Converts the SPKI into the DER format
48 49 50 |
# File 'lib/r509/spki.rb', line 48 def to_der @spki.to_der end |
- (Hash) to_hash
Returns a hash structure you can pass to the Ca You will want to call this method if you intend to alter the values and then pass them to the Ca class.
108 109 110 |
# File 'lib/r509/spki.rb', line 108 def to_hash { :subject => @subject.dup , :san_names => @san_names.dup } end |
- (String) to_pem Also known as: to_s
Converts the SPKI into the PEM format
39 40 41 |
# File 'lib/r509/spki.rb', line 39 def to_pem @spki.to_pem end |
- (Object) write_der(filename_or_io)
Writes the SPKI into the DER format
64 65 66 |
# File 'lib/r509/spki.rb', line 64 def write_der(filename_or_io) write_data(filename_or_io, @spki.to_der) end |
- (Object) write_pem(filename_or_io)
Writes the SPKI into the PEM format
56 57 58 |
# File 'lib/r509/spki.rb', line 56 def write_pem(filename_or_io) write_data(filename_or_io, @spki.to_pem) end |