Module: R509::Helpers
Overview
Various helper methods to reduce duplication across classes. These methods are used in the Cert, CSR, SPKI, and PrivateKey classes.
Instance Method Summary (collapse)
-
- (Integer) bit_length
(also: #bit_strength)
Returns the bit length of the key.
-
- (String) curve_name
Returns the short name of the elliptic curve used to generate the public key if the key is EC.
-
- (Boolean) dsa?
Returns whether the public key is DSA.
-
- (Boolean) ec?
Returns whether the public key is EC.
-
- (String) key_algorithm
Returns key algorithm (RSA/DSA/EC).
-
- (Boolean) rsa?
Returns whether the public key is RSA.
-
- (String) to_der
Converts the object into DER format.
-
- (String) to_pem
Converts the object into PEM format.
-
- (Object) write_der(filename_or_io)
Writes the object into DER format.
-
- (Object) write_pem(filename_or_io)
Writes the object into PEM format.
Instance Method Details
- (Integer) bit_length Also known as: bit_strength
Returns the bit length of the key
54 55 56 57 58 59 60 61 62 |
# File 'lib/r509/helpers.rb', line 54 def bit_length if self.rsa? return internal_obj.public_key.n.num_bits elsif self.dsa? return internal_obj.public_key.p.num_bits elsif self.ec? raise R509::R509Error, 'Bit length is not available for EC at this time.' end end |
- (String) curve_name
Returns the short name of the elliptic curve used to generate the public key if the key is EC. If not, raises an error.
44 45 46 47 48 49 50 |
# File 'lib/r509/helpers.rb', line 44 def curve_name if self.ec? internal_obj.public_key.group.curve_name else raise R509::R509Error, 'Curve name is only available with EC' end end |
- (Boolean) dsa?
Returns whether the public key is DSA
16 17 18 |
# File 'lib/r509/helpers.rb', line 16 def dsa? internal_obj.public_key.kind_of?(OpenSSL::PKey::DSA) end |
- (Boolean) ec?
Returns whether the public key is EC
23 24 25 |
# File 'lib/r509/helpers.rb', line 23 def ec? internal_obj.public_key.kind_of?(OpenSSL::PKey::EC) end |
- (String) key_algorithm
Returns key algorithm (RSA/DSA/EC)
30 31 32 33 34 35 36 37 38 |
# File 'lib/r509/helpers.rb', line 30 def key_algorithm if self.rsa? "RSA" elsif self.dsa? "DSA" elsif self.ec? "EC" end end |
- (Boolean) rsa?
Returns whether the public key is RSA
9 10 11 |
# File 'lib/r509/helpers.rb', line 9 def rsa? internal_obj.public_key.kind_of?(OpenSSL::PKey::RSA) end |
- (String) to_der
Converts the object into DER format
89 90 91 |
# File 'lib/r509/helpers.rb', line 89 def to_der internal_obj.to_der end |
- (String) to_pem
Converts the object into PEM format
82 83 84 |
# File 'lib/r509/helpers.rb', line 82 def to_pem internal_obj.to_pem end |
- (Object) write_der(filename_or_io)
Writes the object into DER format
75 76 77 |
# File 'lib/r509/helpers.rb', line 75 def write_der(filename_or_io) write_data(filename_or_io, internal_obj.to_der) end |
- (Object) write_pem(filename_or_io)
Writes the object into PEM format
68 69 70 |
# File 'lib/r509/helpers.rb', line 68 def write_pem(filename_or_io) write_data(filename_or_io, internal_obj.to_pem) end |