Sha256: 87d1c44bb239bbf791bdc00030361bf80c3a3c6aa6da1d05ff275cd1113112ca

Contents?: true

Size: 1.51 KB

Versions: 2

Compression:

Stored size: 1.51 KB

Contents


Dir.glob(File.join(File.dirname(__FILE__),'../../jars/*.jar')).each do |f|
  require_relative File.expand_path(f)
end

require_relative 'global'

module GcryptoJce
  module Provider
    
    DefProvider = org.bouncycastle.jce.provider.BouncyCastleProvider.new

    def Provider::add_default
      add_provider(DefProvider)
      DefProvider
    end
    # 
    # end add_default
    #

    def Provider::add_provider(prov)
			if prov != nil
				if prov.is_a?(String) and not prov.empty?
          GcryptoJce::GConf.instance.glog.error "Unknown provider by string '#{prov}'. Please use provider object."
          raise Exception, "Unknown provider by string '#{prov}'. Please use provider object."
				elsif prov.is_a?(java.security.Provider)
					if prov != nil
						if not java.security.Security.get_providers.to_a.include?(prov)
              GcryptoJce::GConf.instance.glog.debug "Adding security provider '#{prov.name}'" 
							java.security.Security.add_provider(prov)
						end
						prov
					else
						raise Exception, "Unknown provider object #{prov.inspect}"
					end

				end
			end
      
    end
    # 
    # end add_provider
    #

    def Provider::handle_options(opts = { }, def_if_nil = DefProvider)
      if opts.nil? or opts.empty?
      else
        prov = opts[:provider]
        if prov.nil?
          if def_if_nil != nil
            Provider::add_provider(def_if_nil)
          end
        else
          Provider::add_provider(prov)
        end
      end
    end
    # 
    # add handle_options
    #

  end
end


Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gcrypto_jce-0.2 lib/gcrypto_jce/provider.rb
gcrypto_jce-0.1 lib/gcrypto_jce/provider.rb