lib/app_info/certificate.rb in app-info-3.0.0.beta1 vs lib/app_info/certificate.rb in app-info-3.0.0.beta2

- old
+ new

@@ -52,22 +52,26 @@ # @return [Array, String, OpenSSL::X509::Name] the object converted into the expected format. def subject(format: :raw) convert_cert_name(raw.subject, format: format) end + # @return [Time] def created_at raw.not_before end + # @return [Time] def expired_at raw.not_after end + # @return [Boolean] def expired? expired_at < Time.now.utc end + # @return [String] format always be :x509. def format :x509 end # return algorithm digest @@ -112,10 +116,11 @@ when OpenSSL::PKey::EC then :ec end end # return size of public key + # @return [Integer] def size case public_key when OpenSSL::PKey::RSA public_key.n.num_bits when OpenSSL::PKey::DSA, OpenSSL::PKey::DH @@ -124,36 +129,23 @@ raise NotImplementedError, "key size for #{public_key.inspect} not implemented" end end # return fingerprint of certificate + # @return [String] def fingerprint(name = :sha256, transform: :lower, delimiter: nil) digest = OpenSSL::Digest.new(name.to_s.upcase) - # digest = case name.to_sym - # when :sha1 - # OpenSSL::Digest::SHA1.new - # when :sha224 - # OpenSSL::Digest::SHA224.new - # when :sha384 - # OpenSSL::Digest::SHA384.new - # when :sha512 - # OpenSSL::Digest::SHA512.new - # when :md5 - # OpenSSL::Digest::MD5.new - # else - # OpenSSL::Digest::SHA256.new - # end - digest.update(raw.to_der) fingerprint = digest.to_s fingerprint = fingerprint.upcase if transform.to_sym == :upper return fingerprint unless delimiter fingerprint.scan(/../).join(delimiter) end # Orginal OpenSSL X509 certificate + # @return [OpenSSL::X509::Certificate] def raw @cert end private @@ -172,10 +164,12 @@ def method_missing(method, *args, &block) @cert.send(method.to_sym, *args, &block) || super end - def respond_to_missing?(method, *args) - @cert.include?(method.to_sym) || super + def respond_to_missing?(method_name, *args) + @cert.key?(method_name.to_sym) || + @cert.respond_to?(method_name) || + super end end end