Class: Origami::Signature::DigitalSignature

Inherits:
Dictionary
  • Object
show all
Includes:
Origami::StandardObject
Defined in:
lib/origami/signature.rb

Overview

Class representing a digital signature.

Constant Summary

Constants included from Origami::StandardObject

Origami::StandardObject::DEFAULT_ATTRIBUTES

Constants inherited from Dictionary

Dictionary::TOKENS

Constants included from Object

Object::TOKENS

Instance Attribute Summary

Attributes inherited from Dictionary

#names_cache, #strings_cache, #xref_cache

Attributes included from Object

#file_offset, #generation, #no, #objstm_offset, #parent

Instance Method Summary collapse

Methods included from Origami::StandardObject

included, #version_required

Methods inherited from Dictionary

#[], #[]=, add_type_signature, #cast_to, #copy, #delete, guess_type, hint_type, #initialize, #key?, #map!, #merge, parse, #to_h, #to_obfuscated_str

Methods included from FieldAccessor

#method_missing, #respond_to_missing?

Methods included from Object

#<=>, #cast_to, #copy, #document, #export, included, #indirect?, #indirect_parent, #initialize, #logicalize, #logicalize!, #native_type, parse, #post_build, #reference, #set_document, #set_indirect, skip_until_next_obj, #solve, #to_o, #type, typeof, #version_required, #xrefs

Constructor Details

This class inherits a constructor from Origami::Dictionary

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Origami::FieldAccessor

Instance Method Details

#pre_buildObject

:nodoc:



482
483
484
485
486
487
# File 'lib/origami/signature.rb', line 482

def pre_build #:nodoc:
    self.M = Origami::Date.now
    self.Prop_Build ||= BuildProperties.new.pre_build

    super
end

#rangesObject



506
507
508
509
510
511
512
513
514
515
516
# File 'lib/origami/signature.rb', line 506

def ranges
    byte_range = self.ByteRange

    unless byte_range.is_a?(Array) and byte_range.length == 4 and byte_range.all? {|i| i.is_a?(Integer) }
        raise SignatureError, "Invalid ByteRange field value"
    end

    byte_range.map(&:to_i).each_slice(2).map do |start, length|
        (start...start + length)
    end
end

#signature_offsetObject

:nodoc:



518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
# File 'lib/origami/signature.rb', line 518

def signature_offset #:nodoc:
    indent, tab = 1, "\t"
    content = "#{no} #{generation} obj" + EOL + TOKENS.first + EOL

    self.to_a.sort_by{ |key, _| key }.reverse.each do |key, value|
        if key == :Contents
            content << tab * indent + key.to_s + " "

            return content.size
        else
            content << tab * indent + key.to_s << " "
            content << (value.is_a?(Dictionary) ? value.to_s(indent: indent + 1) : value.to_s) << EOL
        end
    end

    nil
end

#to_s(indent: 1, tab: "\t") ⇒ Object

:nodoc:



489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
# File 'lib/origami/signature.rb', line 489

def to_s(indent: 1, tab: "\t") #:nodoc:

    # Must be deterministic.
    indent, tab = 1, "\t"

    content = TOKENS.first + EOL

    self.to_a.sort_by{ |key, _| key }.reverse.each do |key, value|
        content << tab * indent << key.to_s << " "
        content << (value.is_a?(Dictionary) ? value.to_s(indent: indent + 1) : value.to_s) << EOL
    end

    content << tab * (indent - 1) << TOKENS.last

    output(content)
end