Class: RubeePass::ProtectedDecryptor
- Inherits:
-
Object
- Object
- RubeePass::ProtectedDecryptor
- Defined in:
- lib/rubeepass/protected_decryptor.rb
Instance Method Summary collapse
- #add_to_stream(str) ⇒ Object
- #decrypt(index) ⇒ Object
-
#initialize(key, iv) ⇒ ProtectedDecryptor
constructor
A new instance of ProtectedDecryptor.
Constructor Details
#initialize(key, iv) ⇒ ProtectedDecryptor
Returns a new instance of ProtectedDecryptor.
25 26 27 28 29 |
# File 'lib/rubeepass/protected_decryptor.rb', line 25 def initialize(key, iv) @ciphertext = Array.new @iv = iv @key = key end |
Instance Method Details
#add_to_stream(str) ⇒ Object
4 5 6 7 |
# File 'lib/rubeepass/protected_decryptor.rb', line 4 def add_to_stream(str) @ciphertext.push(str) return (@ciphertext.length - 1) end |
#decrypt(index) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rubeepass/protected_decryptor.rb', line 9 def decrypt(index) return nil if (@iv.nil? || @key.nil?) return nil if ((index < 0) || (index >= @ciphertext.length)) plaintext = Salsa20.new(@key, @iv).decrypt(@ciphertext.join) start = 0 index.times do |i| start += @ciphertext[i].length end stop = start + @ciphertext[index].length return plaintext[start...stop] end |