Class: Cryptor::Cipher
- Inherits:
-
Object
- Object
- Cryptor::Cipher
- Defined in:
- lib/cryptor/cipher.rb
Overview
Base class of all Cryptor ciphers
Direct Known Subclasses
Cryptor::Ciphers::MessageEncryptor, Cryptor::Ciphers::XSalsa20Poly1305
Constant Summary collapse
- REGISTRY =
{}
Instance Attribute Summary collapse
-
#algorithm ⇒ Object
readonly
Returns the value of attribute algorithm.
-
#key_bytes ⇒ Object
readonly
Returns the value of attribute key_bytes.
Class Method Summary collapse
Instance Method Summary collapse
- #decrypt(_key, _ciphertext) ⇒ Object
- #encrypt(_key, _plaintext) ⇒ Object
-
#initialize(algorithm, options = {}) ⇒ Cipher
constructor
A new instance of Cipher.
- #random_key ⇒ Object
Constructor Details
#initialize(algorithm, options = {}) ⇒ Cipher
Returns a new instance of Cipher.
16 17 18 19 |
# File 'lib/cryptor/cipher.rb', line 16 def initialize(algorithm, = {}) @algorithm = algorithm @key_bytes = [:key_bytes] || fail(ArgumentError, 'key_bytes not specified') end |
Instance Attribute Details
#algorithm ⇒ Object (readonly)
Returns the value of attribute algorithm.
6 7 8 |
# File 'lib/cryptor/cipher.rb', line 6 def algorithm @algorithm end |
#key_bytes ⇒ Object (readonly)
Returns the value of attribute key_bytes.
6 7 8 |
# File 'lib/cryptor/cipher.rb', line 6 def key_bytes @key_bytes end |
Class Method Details
.[](algorithm) ⇒ Object
12 13 14 |
# File 'lib/cryptor/cipher.rb', line 12 def self.[](algorithm) REGISTRY[algorithm.to_s] || fail(ArgumentError, "no such cipher: #{algorithm}") end |
.register(algorithm, options = {}) ⇒ Object
8 9 10 |
# File 'lib/cryptor/cipher.rb', line 8 def self.register(algorithm, = {}) REGISTRY[algorithm.to_s] ||= new(algorithm, ) end |
Instance Method Details
#decrypt(_key, _ciphertext) ⇒ Object
31 32 33 34 35 |
# File 'lib/cryptor/cipher.rb', line 31 def decrypt(_key, _ciphertext) #:nocov: fail NotImplementedError, "'decrypt' method has not been implemented" #:nocov: end |
#encrypt(_key, _plaintext) ⇒ Object
25 26 27 28 29 |
# File 'lib/cryptor/cipher.rb', line 25 def encrypt(_key, _plaintext) #:nocov: fail NotImplementedError, "'encrypt' method has not been implemented" #:nocov: end |
#random_key ⇒ Object
21 22 23 |
# File 'lib/cryptor/cipher.rb', line 21 def random_key SecretKey.random_key(self) end |