Sha256: 4c5241d99f741023e488a2830b5c76ff6eb24867c056f5b5877464abe4398e73

Contents?: true

Size: 1.51 KB

Versions: 2

Compression:

Stored size: 1.51 KB

Contents

# this hack exists to work around a major issue with the OpenSSL::PKey::EC interface
# as it is currently configured in ruby <= 2.0.0-p0
# the signing methods on OpenSSL::X509::Request and OpenSSL::X509::Certificate look for
# a method named #private? on the PKey object. OpenSSL::PKey::RSA and OpenSSL::PKey::DSA
# both define this method, but OpenSSL::PKey::EC defines #private_key? instead. This
# will open up the class and add #private? as an alias to allow successful signing
if defined?(OpenSSL::PKey::EC) && !OpenSSL::PKey::EC.method_defined?('private?')
  # marked as @private so it won't appear in the yard doc
  # @private
  module OpenSSL::PKey
    # marked as @private so it won't appear in the yard doc
    # @private
    class EC
      def private?
        private_key?
      end
    end
  end
elsif !defined?(OpenSSL::PKey::EC)
  # this is a stub implementation for when EC is unavailable. Any method called against
  # it will raise an R509Error
  # marked as @private so it won't appear in the yard doc
  # @private
  module OpenSSL::PKey
    # marked as @private so it won't appear in the yard doc
    # @private
    class EC
      UNSUPPORTED = true
      def initialize(*args)
        raise R509::R509Error, "EC is unavailable. You may need to recompile Ruby with an OpenSSL that has elliptic curve support."
      end

      def method_missing(method, *args, &block)
        raise R509::R509Error, "EC is unavailable. You may need to recompile Ruby with an OpenSSL that has elliptic curve support."
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
r509-1.0.1 lib/r509/ec-hack.rb
r509-1.0 lib/r509/ec-hack.rb