class Cryptor::SymmetricEncryption::Cipher

Base class of all Cryptor::SymmetricEncryption ciphers

Constants

REGISTRY

Attributes

algorithm[R]
key_bytes[R]

Public Class Methods

[](algorithm) click to toggle source
# File lib/cryptor/symmetric_encryption/cipher.rb, line 13
def self.[](algorithm)
  REGISTRY[algorithm.to_s] || fail(ArgumentError, "no such cipher: #{algorithm}")
end
new(algorithm, options = {}) click to toggle source
# File lib/cryptor/symmetric_encryption/cipher.rb, line 17
def initialize(algorithm, options = {})
  @algorithm = algorithm
  @key_bytes = options[:key_bytes] || fail(ArgumentError, 'key_bytes not specified')
end
register(algorithm, options = {}) click to toggle source
# File lib/cryptor/symmetric_encryption/cipher.rb, line 9
def self.register(algorithm, options = {})
  REGISTRY[algorithm.to_s] ||= new(algorithm, options)
end

Public Instance Methods

decrypt(_key, _ciphertext) click to toggle source
# File lib/cryptor/symmetric_encryption/cipher.rb, line 32
def decrypt(_key, _ciphertext)
  #:nocov:
  fail NotImplementedError, "'decrypt' method has not been implemented"
  #:nocov:
end
encrypt(_key, _plaintext) click to toggle source
# File lib/cryptor/symmetric_encryption/cipher.rb, line 26
def encrypt(_key, _plaintext)
  #:nocov:
  fail NotImplementedError, "'encrypt' method has not been implemented"
  #:nocov:
end
random_key() click to toggle source
# File lib/cryptor/symmetric_encryption/cipher.rb, line 22
def random_key
  SecretKey.random_key(self)
end