main
1# frozen_string_literal: true
2
3require 'xml/kit/crypto/oaep_cipher'
4require 'xml/kit/crypto/rsa_cipher'
5require 'xml/kit/crypto/symmetric_cipher'
6require 'xml/kit/crypto/unknown_cipher'
7
8module Xml
9 module Kit
10 module Crypto
11 CIPHERS = [SymmetricCipher, RsaCipher, OaepCipher, UnknownCipher].freeze
12
13 # @!visibility private
14 def self.cipher_for(algorithm, key)
15 CIPHERS.find { |x| x.matches?(algorithm) }.new(algorithm, key)
16 end
17
18 def self.cipher_registry(&block)
19 BlockRegistry.new(&block)
20 end
21
22 class BlockRegistry
23 def initialize(&factory)
24 @factory = factory
25 end
26
27 def cipher_for(algorithm, key)
28 @factory.call(algorithm, key)
29 end
30 end
31 end
32 end
33end