Sha256: f853f98a550db937b12e05722feb0ddf8f966316eb30aa0d3b1718de7a196942

Contents?: true

Size: 1.67 KB

Versions: 1

Compression:

Stored size: 1.67 KB

Contents


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

module PkernelJce
  module Provider
    
    BCProvider = org.bouncycastle.jce.provider.BouncyCastleProvider.new
    DefProvider = BCProvider

    def Provider::add_default
      add_provider(DefProvider)
      DefProvider
    end

    def Provider::add_provider(prov)
			if prov != nil
				if prov.is_a?(String) and not prov.empty?
          case prov
          when BCProvider.name
            provInst = BCProvider
						if not java.security.Security.get_providers.to_a.include?(provInst)
              PkernelJce::GConf.instance.glog.debug "Adding security provider '#{provInst.name}'" 
							java.security.Security.add_provider(provInst)
						end
						prov
          else
            PkernelJce::GConf.instance.glog.error "Unknown provider by string '#{prov}'. Please use provider object."
            raise Exception, "Unknown provider by string '#{prov}'. Please use provider object."
          end
				elsif prov.is_a?(java.security.Provider)
					if prov != nil
						if not java.security.Security.get_providers.to_a.include?(prov)
              PkernelJce::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 # add_provider

    def Provider::supported_algo(&block)
      prov = DefProvider
      prov.services.each do |ser|
        if block
          block.call(ser)
        else
          STDOUT.puts "Algorithm : #{ser.algorithm}"
        end
      end
    end # supported_algo

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pkernel_jce-0.7.0 lib/pkernel_jce/provider.rb