Module: Origami::Encryption::EncryptedDocument

Defined in:
lib/origami/encryption.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#encryption_dict=(value) ⇒ Object (writeonly)

Sets the attribute encryption_dict

Parameters:

  • value

    the value to set the attribute encryption_dict to.



323
324
325
# File 'lib/origami/encryption.rb', line 323

def encryption_dict=(value)
  @encryption_dict = value
end

#encryption_key=(value) ⇒ Object (writeonly)

Sets the attribute encryption_key

Parameters:

  • value

    the value to set the attribute encryption_key to.



322
323
324
# File 'lib/origami/encryption.rb', line 322

def encryption_key=(value)
  @encryption_key = value
end

#stm_algo=(value) ⇒ Object (writeonly)

Sets the attribute stm_algo

Parameters:

  • value

    the value to set the attribute stm_algo to.



324
325
326
# File 'lib/origami/encryption.rb', line 324

def stm_algo=(value)
  @stm_algo = value
end

#str_algo=(value) ⇒ Object (writeonly)

Sets the attribute str_algo

Parameters:

  • value

    the value to set the attribute str_algo to.



325
326
327
# File 'lib/origami/encryption.rb', line 325

def str_algo=(value)
  @str_algo = value
end

Instance Method Details

#build(obj, revision, options) ⇒ Object

:nodoc:



331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
# File 'lib/origami/encryption.rb', line 331

def build(obj, revision, options) #:nodoc:
  if obj.is_a?(EncryptedObject) # already built
    if options[:decrypt] == true
      obj.pre_build
      obj.decrypt!
      obj.decrypted = false # makes it believe no encryption pass is required
      obj.post_build
    end

    return
  end
     
  if obj.is_a?(ObjectStream)
    obj.each do |subobj|
      build(subobj, revision, options)
    end
  end

  obj.pre_build

  case obj
  when String
    if not obj.equal?(@encryption_dict[:U]) and 
       not obj.equal?(@encryption_dict[:O]) and 
       not obj.equal?(@encryption_dict[:UE]) and 
       not obj.equal?(@encryption_dict[:OE]) and 
       not obj.equal?(@encryption_dict[:Perms]) and 
       not (obj.parent.is_a?(Signature::DigitalSignature) and obj.equal?(obj.parent[:Contents])) and
       not obj.indirect_parent.parent.is_a?(ObjectStream)
      
      obj.extend(EncryptedString)
      obj.decrypted = true
      obj.encryption_handler = @encryption_dict
      obj.encryption_key = @encryption_key
      obj.algorithm = @str_algo
    end

  when Stream
    return if obj.is_a?(XRefStream)
    return if obj.equal?(self.Catalog.Metadata) and not @encryption_dict.EncryptMetadata
    obj.extend(EncryptedStream)
    obj.decrypted = true
    obj.encryption_handler = @encryption_dict
    obj.encryption_key = @encryption_key
    obj.algorithm = @stm_algo

  when Dictionary, Array
    obj.map! do |subobj|
      if subobj.is_indirect?
        if get_object(subobj.reference)
          subobj.reference
        else
          ref = add_to_revision(subobj, revision)
          build(subobj, revision, options)
          ref
        end
      else
        subobj
      end
    end
    
    obj.each do |subobj|
      build(subobj, revision, options)
    end
  end

  obj.post_build
end