lib/ronin/network/ssl.rb in ronin-support-0.2.0 vs lib/ronin/network/ssl.rb in ronin-support-0.3.0
- old
+ new
@@ -17,34 +17,40 @@
# along with Ronin Support. If not, see <http://www.gnu.org/licenses/>.
#
require 'ronin/network/extensions/ssl'
+begin
+ require 'openssl'
+rescue ::LoadError
+end
+
module Ronin
module Network
#
# SSL helper methods.
#
module SSL
+ # Maps SSL verify modes to `OpenSSL::SSL::VERIFY_*` constants.
#
- # Returns the OpenSSL verify mode.
+ # @return [Hash{Symbol => Integer}]
#
- # @param [Symbol, String] mode
- # The name of the verify mode.
+ # @since 1.3.0
#
- # @return [Integer]
- # The verify mode number used by OpenSSL.
- #
# @api private
#
- def SSL.verify(mode=nil)
- verify_mode = 'VERIFY_' + (mode || :none).to_s.upcase
+ VERIFY = Hash.new do |hash,key|
+ verify_const = if key
+ "VERIFY_#{key.to_s.upcase}"
+ else
+ 'VERIFY_NONE'
+ end
- unless OpenSSL::SSL.const_defined?(verify_mode)
- raise(RuntimeError,"unknown verify mode #{mode}")
+ unless OpenSSL::SSL.const_defined?(verify_const)
+ raise(RuntimeError,"unknown verify mode #{key}")
end
- return OpenSSL::SSL.const_get(verify_mode)
+ hash[key] = OpenSSL::SSL.const_get(verify_const)
end
end
end
end