lib/r509/helpers.rb in r509-0.10.0 vs lib/r509/helpers.rb in r509-1.0
- old
+ new
@@ -1,29 +1,28 @@
module R509
# Various helper methods to reduce duplication across classes. These methods
# are used in the Cert, CSR, SPKI, and PrivateKey classes.
module Helpers
-
# Returns whether the public key is RSA
#
# @return [Boolean] true if the public key is RSA, false otherwise
def rsa?
- internal_obj.public_key.kind_of?(OpenSSL::PKey::RSA)
+ internal_obj.public_key.is_a?(OpenSSL::PKey::RSA)
end
# Returns whether the public key is DSA
#
# @return [Boolean] true if the public key is DSA, false otherwise
def dsa?
- internal_obj.public_key.kind_of?(OpenSSL::PKey::DSA)
+ internal_obj.public_key.is_a?(OpenSSL::PKey::DSA)
end
# Returns whether the public key is EC
#
# @return [Boolean] true if the public key is EC, false otherwise
def ec?
- internal_obj.public_key.kind_of?(OpenSSL::PKey::EC)
+ internal_obj.public_key.is_a?(OpenSSL::PKey::EC)
end
# Returns key algorithm (RSA/DSA/EC)
#
# @return [String] value of the key algorithm.
@@ -58,11 +57,11 @@
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
- alias :bit_strength :bit_length
+ alias_method :bit_strength, :bit_length
# Writes the object into PEM format
# @param [String, #write] filename_or_io Either a string of the path for
# the file that you'd like to write, or an IO-like object.
def write_pem(filename_or_io)
@@ -78,33 +77,31 @@
# Converts the object into PEM format
#
# @return [String] the object converted into PEM format.
def to_pem
- internal_obj.to_pem
+ internal_obj.to_pem
end
# Converts the object into DER format
#
# @return [String] the object converted into DER format.
def to_der
- internal_obj.to_der
+ internal_obj.to_der
end
# @private
def load_private_key(opts)
- if opts.has_key?(:key)
- if opts[:key].kind_of?(R509::PrivateKey)
- return opts[:key]
- else
- return R509::PrivateKey.new(:key => opts[:key])
- end
+ return unless opts.key?(:key)
+ if opts[:key].is_a?(R509::PrivateKey)
+ return opts[:key]
+ else
+ return R509::PrivateKey.new(:key => opts[:key])
end
end
# @private
def internal_obj
raise R509::R509Error, "Internal object for helpers not implemented"
end
-
end
end