Class: Ccrypto::Ruby::Provider

Inherits:
Object
  • Object
show all
Defined in:
lib/ccrypto/provider.rb

Class Method Summary collapse

Class Method Details

.algo_instance(*args, &block) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/ccrypto/provider.rb', line 82

def self.algo_instance(*args, &block)
  config = args.first

  if config.is_a?(Class) or config.is_a?(Module)
    if config == Ccrypto::ECCConfig
      ECCEngine
    elsif config == Ccrypto::RSAConfig
      RSAEngine
    elsif config == Ccrypto::ECCKeyBundle
      ECCKeyBundle
    elsif config == Ccrypto::RSAKeyBundle
      RSAKeyBundle
    elsif config == Ccrypto::DigestConfig
      DigestEngine
    elsif config == Ccrypto::SecureRandomConfig
      SecureRandomEngine
    elsif config == Ccrypto::CipherConfig
      CipherEngine
    elsif config == Ccrypto::ECCPublicKey
      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
    when Ccrypto::ECCConfig
      ECCEngine.new(*args, &block)
    when Ccrypto::RSAConfig
      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
      PBKDF2Engine.new(*args, &block)
    when Ccrypto::CipherConfig
      CipherEngine.new(*args, &block)
    when Ccrypto::HMACConfig
      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

end

.asn1_engine(*args, &block) ⇒ Object



150
151
152
# File 'lib/ccrypto/provider.rb', line 150

def self.asn1_engine(*args, &block)
  ASN1Engine
end

.keybundle_from_storage(*args, &block) ⇒ Object



73
74
75
76
77
78
79
80
# File 'lib/ccrypto/provider.rb', line 73

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

.provider_nameObject



52
53
54
# File 'lib/ccrypto/provider.rb', line 52

def self.provider_name
  "ruby"
end

.supported_keypair_config(purpose = :signing, &block) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/ccrypto/provider.rb', line 56

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

.supported_secret_key_config(&block) ⇒ Object



69
70
71
# File 'lib/ccrypto/provider.rb', line 69

def self.supported_secret_key_config(&block)
  CipherEngine.supported_cipher_list 
end

.util_instance(*args, &block) ⇒ Object



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/ccrypto/provider.rb', line 154

def self.util_instance(*args, &block)
  type = args.first
  case type
  when :comparator, :compare
    ComparatorUtil
  when :data_conversion, :converter, :data_converter
    DataConversionEngine

  when :memory_buffer, :membuf, :buffer, :mem
    MemoryBuffer

  when :compression, :compressor
    Compression.new(*(args[1..-1]), &block)

  when :decompression
    Decompression.new(*(args[1..-1]), &block)

  when :native_helper
    NativeHelper

  else
    raise CcryptoProviderException, "Util type #{type} is not supported by provider #{self.provider_name}"
  end
end