Sha256: 5ea532c3491c11aa4be03a8ceeff65c773af394aaf7d7bdcb48cca7917df2d54

Contents?: true

Size: 1015 Bytes

Versions: 3

Compression:

Stored size: 1015 Bytes

Contents

module Cryptor
  class SymmetricEncryption
    # Base class of all Cryptor::SymmetricEncryption ciphers
    class Cipher
      REGISTRY = {}

      attr_reader :algorithm, :key_bytes

      def self.register(algorithm, options = {})
        REGISTRY[algorithm.to_s] ||= new(algorithm, options)
      end

      def self.[](algorithm)
        REGISTRY[algorithm.to_s] || fail(ArgumentError, "no such cipher: #{algorithm}")
      end

      def initialize(algorithm, options = {})
        @algorithm = algorithm
        @key_bytes = options[:key_bytes] || fail(ArgumentError, 'key_bytes not specified')
      end

      def random_key
        SecretKey.random_key(self)
      end

      def encrypt(_key, _plaintext)
        #:nocov:
        fail NotImplementedError, "'encrypt' method has not been implemented"
        #:nocov:
      end

      def decrypt(_key, _ciphertext)
        #:nocov:
        fail NotImplementedError, "'decrypt' method has not been implemented"
        #:nocov:
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cryptor-1.1.1 lib/cryptor/symmetric_encryption/cipher.rb
cryptor-1.1.0 lib/cryptor/symmetric_encryption/cipher.rb
cryptor-1.0.0 lib/cryptor/symmetric_encryption/cipher.rb