class Origami::PPKLite

Class representing an Adobe Reader certificate store.

Constants

Cert
Editable
ID
Root
Size
Trust
Viewable

Attributes

header[RW]
revisions[RW]

Public Class Methods

read(path, options = {}) click to toggle source
# File lib/origami/extensions/ppklite.rb, line 45
def self.read(path, options = {})
    path = File.expand_path(path) if path.is_a?(::String)

    PPKLite::Parser.new(options).parse(path)
end

Public Instance Methods

<<(object) click to toggle source
# File lib/origami/extensions/ppklite.rb, line 242
def <<(object)
    object.set_indirect(true)
    object.set_document(self)

    if object.no.zero?
        maxno = 1
        maxno = maxno.succ while get_object(maxno)

        object.generation = 0
        object.no = maxno
    end

    @revisions.first.body[object.reference] = object

    object.reference
end
Also aliased as: insert
Catalog() click to toggle source
# File lib/origami/extensions/ppklite.rb, line 260
def Catalog
    get_object(@revisions.first.trailer.Root)
end
add_certificate(certfile, attributes, viewable: false, editable: false) click to toggle source

Add a certificate into the address book

# File lib/origami/extensions/ppklite.rb, line 344
def add_certificate(certfile, attributes, viewable: false, editable: false)
    if certfile.is_a?(OpenSSL::X509::Certificate)
        x509 = certfile
    else
        x509 = OpenSSL::X509::Certificate.new(certfile)
    end

    address_book = get_address_book

    cert = Certificate.new
    cert.Cert = x509.to_der
    cert.ID = address_book.NextID
    address_book.NextID += 1

    cert.Trust = attributes
    cert.Viewable = viewable
    cert.Editable = editable

    address_book.Entries.push(self << cert)
end
certificates() click to toggle source
# File lib/origami/extensions/ppklite.rb, line 337
def certificates
    self.each_certificate.to_a
end
each_certificate(&b) click to toggle source
# File lib/origami/extensions/ppklite.rb, line 329
def each_certificate(&b)
    each_entry(Descriptor::CERTIFICATE, &b)
end
each_user(&b) click to toggle source
# File lib/origami/extensions/ppklite.rb, line 317
def each_user(&b)
    each_entry(Descriptor::USER, &b)
end
get_certificate(id) click to toggle source
# File lib/origami/extensions/ppklite.rb, line 333
def get_certificate(id)
    self.each_certificate.find {|cert| cert.ID == id }
end
get_user(id) click to toggle source
# File lib/origami/extensions/ppklite.rb, line 321
def get_user(id)
    self.each_user.find {|user| user.ID == id }
end
indirect_objects() click to toggle source
# File lib/origami/extensions/ppklite.rb, line 212
def indirect_objects
    @revisions.inject([]) do |set, rev| set.concat(rev.objects) end
end
Also aliased as: root_objects
insert(object)
Alias for: <<
root_objects()
Alias for: indirect_objects
save(path) click to toggle source
# File lib/origami/extensions/ppklite.rb, line 264
def save(path)
    bin = "".b
    bin << @header.to_s

    lastno, brange = 0, 0

    xrefs = [ XRef.new(0, XRef::FIRSTFREE, XRef::FREE) ]
    xrefsection = XRef::Section.new

    @revisions.first.body.values.sort.each { |obj|
        if (obj.no - lastno).abs > 1
            xrefsection << XRef::Subsection.new(brange, xrefs)
            brange = obj.no
            xrefs.clear
        end

        xrefs << XRef.new(bin.size, obj.generation, XRef::USED)
        lastno = obj.no

        obj.pre_build

        bin << obj.to_s

        obj.post_build
    }

    xrefsection << XRef::Subsection.new(brange, xrefs)

    @xreftable = xrefsection
    @trailer ||= Trailer.new
    @trailer.Size = @revisions.first.body.size + 1
    @trailer.startxref = bin.size

    bin << @xreftable.to_s
    bin << @trailer.to_s

    if path.respond_to?(:write)
        io = path
    else
        path = File.expand_path(path)
        io = File.open(path, "wb", encoding: 'binary')
        close = true
    end

    begin
        io.write(bin)
    ensure
        io.close if close
    end

    self
end
users() click to toggle source
# File lib/origami/extensions/ppklite.rb, line 325
def users
    self.each_user.to_a
end

Private Instance Methods

each_entry(type) { |entry| ... } click to toggle source
# File lib/origami/extensions/ppklite.rb, line 381
def each_entry(type)
    return enum_for(__method__, type) unless block_given?

    address_book = get_address_book 

    address_book.Entries.each do |entry|
        entry = entry.solve

        yield(entry) if entry.is_a?(Dictionary) and entry.ABEType == type
    end
end
get_address_book() click to toggle source
# File lib/origami/extensions/ppklite.rb, line 393
def get_address_book
    raise Error, "Broken catalog" unless self.Catalog.is_a?(Dictionary) and self.Catalog.PPK.is_a?(Dictionary)

    ppk = self.Catalog.PPK
    raise Error, "Broken PPK" unless ppk.AddressBook.is_a?(Dictionary)

    address_book = ppk.AddressBook
    raise Error, "Broken address book" unless address_book.Entries.is_a?(Array)

    address_book
end
init() click to toggle source
# File lib/origami/extensions/ppklite.rb, line 367
def init
    catalog = Catalog.new(
        PPK: PPK.new(
            User: UserList.new,
            AddressBook: AddressList.new(
                Entries: [],
                NextID: 1
            )
        )
    )

    @revisions.first.trailer.Root = self.insert(catalog)
end