class RubeePass::ProtectedDecryptor

Public Class Methods

new(key, iv) click to toggle source
# File lib/rubeepass/protected_decryptor.rb, line 25
def initialize(key, iv)
    @ciphertext = Array.new
    @iv = iv
    @key = key
end

Public Instance Methods

add_to_stream(str) click to toggle source
# File lib/rubeepass/protected_decryptor.rb, line 4
def add_to_stream(str)
    @ciphertext.push(str)
    return (@ciphertext.length - 1)
end
decrypt(index) click to toggle source
# 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