lib/ccrypto/provider.rb in ccrypto-ruby-0.1.0 vs lib/ccrypto/provider.rb in ccrypto-ruby-0.1.1

- old
+ new

@@ -1,10 +1,14 @@ require_relative 'ruby/engines/ecc_engine' require_relative 'ruby/engines/digest_engine' require_relative 'ruby/engines/x509_engine' +require_relative 'ruby/engines/x509_csr_engine' +require_relative 'ruby/engines/ed25519_engine' +require_relative 'ruby/engines/x25519_engine' + require_relative 'ruby/engines/scrypt_engine' require_relative 'ruby/engines/hkdf_engine' require_relative 'ruby/engines/pbkdf2_engine' require_relative 'ruby/engines/secure_random_engine' @@ -29,16 +33,54 @@ require_relative 'ruby/engines/rsa_engine' module Ccrypto module Ruby + + class KSPemStore + include TR::CondUtils + include PEMStore + end + + class KSP12Store + include TR::CondUtils + include DataConversion + include PKCS12Store + end + class Provider def self.provider_name "ruby" end + def self.supported_keypair_config(purpose = :signing, &block) + case purpose + when :signing, :sign, :identity + [Ccrypto::ECCConfig, Ccrypto::RSAConfig, Ccrypto::ED25519Config] + when :cipher, :encryption, :enc + [Ccrypto::ECCConfig, Ccrypto::RSAConfig, Ccrypto::X25519Config] + when :sign_and_encrypt, :sign_and_enc, :sign_and_cipher + [Ccrypto::ECCConfig, Ccrypto::RSAConfig] + else + raise KeypairEngineException, "Unknown key purpose '#{purpose}'. Supported including :signing, :cipher or :both" + end + end + + def self.supported_secret_key_config(&block) + CipherEngine.supported_cipher_list + end + + def self.keybundle_from_storage(*args, &block) + input = args.first + if KSPemStore.is_pem?(input) + KSPemStore.from_pem(input, &block) + else + KSP12Store.from_pkcs12(input, &block) + end + end + def self.algo_instance(*args, &block) config = args.first if config.is_a?(Class) or config.is_a?(Module) if config == Ccrypto::ECCConfig @@ -59,10 +101,14 @@ Ccrypto::Ruby::ECCPublicKey elsif config == Ccrypto::KeyConfig Ccrypto::Ruby::SecretKeyEngine elsif config == Ccrypto::SecretSharingConfig SecretSharingEngine + elsif config == Ccrypto::X509::CSRProfile + X509CSREngine + elsif config == Ccrypto::ED25519Config + ED25519Engine else raise CcryptoProviderException, "Config class '#{config}' is not supported for provider '#{self.provider_name}'" end else case config @@ -72,10 +118,12 @@ RSAEngine.new(*args, &block) when Ccrypto::DigestConfig DigestEngine.instance(*args, &block) when Ccrypto::X509::CertProfile X509Engine.new(*args,&block) + when Ccrypto::X509::CSRProfile + X509CSREngine.new(*args,&block) when Ccrypto::ScryptConfig ScryptEngine.new(*args,&block) when Ccrypto::HKDFConfig HKDFEngine.new(*args, &block) when Ccrypto::PBKDF2Config @@ -86,57 +134,17 @@ HMACEngine.new(*args, &block) when Ccrypto::SecretSharingConfig SecretSharingEngine.new(*args,&block) when Ccrypto::PKCS7Config PKCS7Engine.new(*args, &block) + when Ccrypto::ED25519Config + ED25519Engine.new(*args, &block) + when Ccrypto::X25519Config + X25519Engine.new(*args, &block) else raise CcryptoProviderException, "Config instance '#{config}' is not supported for provider '#{self.provider_name}'" end end - - #case config - #when Ccrypto::ECCConfig.class - # puts "ecc config class" - # ECCEngine - #when Ccrypto::ECCConfig - # puts "ecc config" - # ECCEngine.new(*args, &block) - #when Ccrypto::DigestConfig.class - # puts "digest config class" - # DigestEngine - #when Ccrypto::DigestConfig - # puts "digest config" - # DigestEngine.instance(*args,&block) - #else - # raise CcryptoProviderException, "Config '#{config}' is not supported for provider '#{self.provider_name}'" - #end - - #case algo - #when :ecc - # ECCEngine - #when :x509 - # if args.length > 1 - # X509Engine.new(*args[1..-1]) - # else - # X509Engine - # end - #when :scrypt - # ScryptEngine.new - #when :secure_random - # SecureRandomEngine - #else - # if DigestEngine.is_supported?(algo) - # DigestEngine.instance(algo) - # elsif CipherEngine.is_supported_cipher?(algo.to_s) - # if args.length > 1 or args[0].is_a?(String) - # CipherEngine.new(*args) - # else - # CipherEngine - # end - # else - # raise CcryptoProviderException, "Algo '#{algo}' is not supported for provider '#{self.provider_name}'" - # end - #end end def self.asn1_engine(*args, &block) ASN1Engine