Sha256: adaf5186724b3d18a471af48239bf8faedbe72b6616b82e0c473d7a0362930af

Contents?: true

Size: 951 Bytes

Versions: 1

Compression:

Stored size: 951 Bytes

Contents

require 'singleton'

module Ccrypto
  module Java
    
    class JCEProviderException < StandardError; end

    class JCEProvider
      include Singleton

      BCProv = org.bouncycastle.jce.provider.BouncyCastleProvider.new
      DEFProv = BCProv

      def add_provider(prov = nil)
        case prov
        when java.security.Provider
          java.security.Security.add_provider(prov) if not is_provider_registered?(prov)
        else
          java.security.Security.add_provider(DEFProv) if not is_provider_registered?(DEFProv)	
        end
      end

      def is_provider_registered?(prov)
        case prov
        when String
          java.security.Security.providers.to_a.map { |v| v.name }.include?(prov)
        when java.security.Provider
          java.security.Security.get_providers.to_a.include?(prov)
        else
          false
        end
      end

      def add_bc_provider
        add_provider
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ccrypto-java-0.2.0 lib/ccrypto/java/jce_provider.rb