class RubeePass::AttachmentDecoder

Public Class Methods

new(binaries) click to toggle source
# File lib/rubeepass/attachment_decoder.rb, line 21
def initialize(binaries)
    @binaries = binaries
end

Public Instance Methods

get_attachment(ref) click to toggle source
# File lib/rubeepass/attachment_decoder.rb, line 6
def get_attachment(ref)
    @binaries.elements.each("Binary") do |elem|
        if (elem.attributes["ID"] == ref)
            if (elem.attributes["Compressed"].nil?)
                begin
                    return Base64.decode64(elem.text)
                rescue
                    return elem.text
                end
            end
            return parse_gzip(elem.text)
        end
    end
end

Private Instance Methods

parse_gzip(attachment) click to toggle source
# File lib/rubeepass/attachment_decoder.rb, line 25
def parse_gzip(attachment)
    begin
        attachment = Base64.decode64(attachment)
    rescue
        # Do nothing
    end
    return Zlib::GzipReader.new(StringIO.new(attachment)).read
end