Class: CryptoToolchain::BlackBoxes::AesCtrEditor
- Defined in:
- lib/crypto_toolchain/black_boxes/aes_ctr_editor.rb
Instance Attribute Summary collapse
-
#ciphertext ⇒ Object
readonly
Returns the value of attribute ciphertext.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#nonce ⇒ Object
readonly
Returns the value of attribute nonce.
-
#plaintext ⇒ Object
readonly
Returns the value of attribute plaintext.
Instance Method Summary collapse
-
#edit(offset:, with:) ⇒ Object
Offset is in bytes Does not mutate @ciphetext or @plaintext.
-
#initialize(plaintext, key: Random.new.bytes(16), nonce: rand(0..0x0000FF)) ⇒ AesCtrEditor
constructor
A new instance of AesCtrEditor.
Constructor Details
#initialize(plaintext, key: Random.new.bytes(16), nonce: rand(0..0x0000FF)) ⇒ AesCtrEditor
Returns a new instance of AesCtrEditor.
4 5 6 7 8 9 |
# File 'lib/crypto_toolchain/black_boxes/aes_ctr_editor.rb', line 4 def initialize(plaintext, key: Random.new.bytes(16), nonce: rand(0..0x0000FF)) @plaintext = plaintext @key = key @nonce = nonce @ciphertext = plaintext.encrypt_ctr(key: key, nonce: nonce) end |
Instance Attribute Details
#ciphertext ⇒ Object (readonly)
Returns the value of attribute ciphertext.
22 23 24 |
# File 'lib/crypto_toolchain/black_boxes/aes_ctr_editor.rb', line 22 def ciphertext @ciphertext end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
22 23 24 |
# File 'lib/crypto_toolchain/black_boxes/aes_ctr_editor.rb', line 22 def key @key end |
#nonce ⇒ Object (readonly)
Returns the value of attribute nonce.
22 23 24 |
# File 'lib/crypto_toolchain/black_boxes/aes_ctr_editor.rb', line 22 def nonce @nonce end |
#plaintext ⇒ Object (readonly)
Returns the value of attribute plaintext.
22 23 24 |
# File 'lib/crypto_toolchain/black_boxes/aes_ctr_editor.rb', line 22 def plaintext @plaintext end |
Instance Method Details
#edit(offset:, with:) ⇒ Object
Offset is in bytes Does not mutate @ciphetext or @plaintext
13 14 15 16 17 18 19 20 |
# File 'lib/crypto_toolchain/black_boxes/aes_ctr_editor.rb', line 13 def edit(offset: ,with: ) previous = ciphertext[0...offset] after = ciphertext[(offset + with.bytesize)..-1] edited = with.encrypt_ctr(nonce: nonce, key: key, start_counter: offset) previous + edited + after end |