Module: Twofish::Mode

Defined in:
lib/twofish/mode.rb

Overview

Encryption modes.

The only currently implemented modes are ECB (Electronic Code Book) and CBC (Cipher Block Chaining).

Constant Summary collapse

ECB =

Electronic code book mode.

:ecb
CBC =

Cipher block chaining mode.

:cbc
ALL =

Array of all known modes.

[CBC, ECB]
DEFAULT =

Default mode (ECB).

ECB

Class Method Summary collapse

Class Method Details

.validate(mode) ⇒ Object

Takes a string or symbol and returns the lowercased symbol representation if this is a recognized mode. Otherwise, throws ArgumentError.

Raises:

  • (ArgumentError)


24
25
26
27
28
# File 'lib/twofish/mode.rb', line 24

def self.validate(mode)
  mode_sym = mode.nil? ? DEFAULT : mode.to_s.downcase.to_sym
  raise ArgumentError, "unknown cipher mode #{mode.inspect}" unless ALL.include? mode_sym
  mode_sym
end