Class: Cryptor::SymmetricEncryption::Cipher
- Inherits:
-
Object
- Object
- Cryptor::SymmetricEncryption::Cipher
- Defined in:
- lib/cryptor/symmetric_encryption/cipher.rb
Overview
Base class of all Cryptor::SymmetricEncryption ciphers
Direct Known Subclasses
Cryptor::SymmetricEncryption::Ciphers::MessageEncryptor, Cryptor::SymmetricEncryption::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.
17 18 19 20 |
# File 'lib/cryptor/symmetric_encryption/cipher.rb', line 17 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.
7 8 9 |
# File 'lib/cryptor/symmetric_encryption/cipher.rb', line 7 def algorithm @algorithm end |
#key_bytes ⇒ Object (readonly)
Returns the value of attribute key_bytes.
7 8 9 |
# File 'lib/cryptor/symmetric_encryption/cipher.rb', line 7 def key_bytes @key_bytes end |
Class Method Details
.[](algorithm) ⇒ Object
13 14 15 |
# File 'lib/cryptor/symmetric_encryption/cipher.rb', line 13 def self.[](algorithm) REGISTRY[algorithm.to_s] || fail(ArgumentError, "no such cipher: #{algorithm}") end |
.register(algorithm, options = {}) ⇒ Object
9 10 11 |
# File 'lib/cryptor/symmetric_encryption/cipher.rb', line 9 def self.register(algorithm, = {}) REGISTRY[algorithm.to_s] ||= new(algorithm, ) end |
Instance Method Details
#decrypt(_key, _ciphertext) ⇒ Object
32 33 34 35 36 |
# 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) ⇒ Object
26 27 28 29 30 |
# 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 ⇒ Object
22 23 24 |
# File 'lib/cryptor/symmetric_encryption/cipher.rb', line 22 def random_key SecretKey.random_key(self) end |