Class: Origami::Adobe::PPKLite

Inherits:
Object
  • Object
show all
Defined in:
lib/origami/extensions/ppklite.rb,
lib/origami/parsers/ppklite.rb

Overview

Class representing an Adobe Reader certificate store.

Defined Under Namespace

Modules: Descriptor Classes: AddressList, Catalog, Certificate, Header, PPK, Parser, Revision, User, UserList

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePPKLite

:nodoc:



116
117
118
119
120
# File 'lib/origami/extensions/ppklite.rb', line 116

def initialize #:nodoc:
  @header = PPKLite::Header.new
  @revisions = [ Revision.new(self) ]
  @revisions.first.trailer = Trailer.new
end

Instance Attribute Details

#headerObject

Returns the value of attribute header.



114
115
116
# File 'lib/origami/extensions/ppklite.rb', line 114

def header
  @header
end

#revisionsObject

Returns the value of attribute revisions.



114
115
116
# File 'lib/origami/extensions/ppklite.rb', line 114

def revisions
  @revisions
end

Instance Method Details

#<<(object) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/origami/extensions/ppklite.rb', line 142

def <<(object)
  
  object.set_indirect(true)
  
  if object.no.zero?
  maxno = 1
    while get_object(maxno) do maxno = maxno.succ end
    
    object.generation = 0
    object.no = maxno
  end
  
  @revisions.first.body[object.reference] = object
  
  object.reference
end

#add_certificate(certfile, attributes, viewable = false, editable = false) ⇒ Object

Add a certificate into the address book



272
273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'lib/origami/extensions/ppklite.rb', line 272

def add_certificate(certfile, attributes, viewable = false, editable = false)
  
  cert = Certificate.new
  cert.Cert = OpenSSL::X509::Certificate.new(certfile).to_der
  cert.ID = self.Catalog.PPK.AddressBook.NextID
  self.Catalog.PPK.AddressBook.NextID += 1
  cert.Trust = attributes
  cert.Viewable = viewable
  cert.Editable = editable
  
  self.Catalog.PPK.AddressBook.Entries.push(self << cert)
  
  show_certs
end

#append_subobj(root, objset) ⇒ Object



123
124
125
126
127
128
129
130
# File 'lib/origami/extensions/ppklite.rb', line 123

def append_subobj(root, objset)
  if objset.find{ |o| o.object_id == root.object_id }.nil?
    objset << root
    if root.is_a?(Array) or root.is_a?(Dictionary)
      root.each { |subobj| append_subobj(subobj, objset) unless subobj.is_a?(Reference) }
    end
  end
end

#CatalogObject



159
160
161
# File 'lib/origami/extensions/ppklite.rb', line 159

def Catalog
  get_object(@trailer.Root)
end

#get_cert(id) ⇒ Object

Returns a Certificate dictionary corresponding to the specified id



246
247
248
# File 'lib/origami/extensions/ppklite.rb', line 246

def get_cert(id)
  @revisions.first.body.values.find { |obj| obj.is_a?(Certificate) and obj.ID == id }
end

#get_object(no, generation = 0) ⇒ Object

:nodoc:



412
413
414
415
416
417
418
419
420
421
422
423
424
# File 'lib/origami/extensions/ppklite.rb', line 412

def get_object(no, generation = 0) #:nodoc:
   
  case no
  when Reference
    target = no
  when ::Integer
    target = Reference.new(no, generation)
  when Origami::Object
    return no
  end
 
  @revisions.first.body[target]
end

#objectsObject



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/origami/extensions/ppklite.rb', line 122

def objects
  def append_subobj(root, objset)
    if objset.find{ |o| o.object_id == root.object_id }.nil?
      objset << root
      if root.is_a?(Array) or root.is_a?(Dictionary)
        root.each { |subobj| append_subobj(subobj, objset) unless subobj.is_a?(Reference) }
      end
    end
  end
  
  objset = []
  @revisions.first.body.values.each do |object|
    unless object.is_a?(Reference)
      append_subobj(object, objset)
    end
  end
  
  objset
end

#save(filename) ⇒ Object Also known as: saveas



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/origami/extensions/ppklite.rb', line 163

def save(filename)
  
  bin = ""
  bin << @header.to_s

  lastno, brange = 0, 0
    
  xrefs = [ XRef.new(0, XRef::LASTFREE, 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

    bin << obj.to_s
  }
  
  xrefsection << XRef::Subsection.new(brange, xrefs)
  
  @xreftable = xrefsection
  @trailer ||= Trailer.new
  @trailer.Size = rev.body.size + 1
  @trailer.startxref = bin.size

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

  fd = File.open(filename, "w").binmode
    fd << bin 
  fd.close
  
  show_entries
end

#show_cert(id) ⇒ Object

Prints certificate with the specified id



234
235
236
237
238
239
240
241
# File 'lib/origami/extensions/ppklite.rb', line 234

def show_cert(id)
  @revisions.first.body.values.find_all { |obj| obj.is_a?(Certificate) and obj.ID == id }.each do |cert|
    cert.show
    puts
  end
  
  nil
end

#show_certsObject

Prints registered certificates in the addressbook



221
222
223
224
225
226
227
228
229
# File 'lib/origami/extensions/ppklite.rb', line 221

def show_certs
  puts "-----------------"
  puts "Certificates list"
  puts "-----------------"
  
  @revisions.first.body.values.each { |obj| if obj.is_a?(Certificate) then obj.show; puts end }
  
  nil
end

#show_entriesObject Also known as: to_s, to_str

Prints users and certificates registered in the address book



262
263
264
265
266
267
# File 'lib/origami/extensions/ppklite.rb', line 262

def show_entries
  show_users
  show_certs
  
  puts "End of address book."
end

#show_user(id) ⇒ Object



250
251
252
253
254
255
256
257
# File 'lib/origami/extensions/ppklite.rb', line 250

def show_user(id)
  users = @revisions.first.body.values.find_all { |obj| obj.is_a?(User) and obj.ID == id }.each do |user|
    user.show
    puts
  end
  
  nil
end

#show_usersObject

Prints registered users in the address book



207
208
209
210
211
212
213
214
215
216
# File 'lib/origami/extensions/ppklite.rb', line 207

def show_users
  
  puts "----------"
  puts "Users list"
  puts "----------"
  
  @revisions.first.body.values.each { |obj| if obj.is_a?(User) then obj.show; puts end }
  
  nil
end