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 collapse

PKCS1_RSA_SHA1 =
:"adbe.x509.rsa_sha1"
PKCS7_SHA1 =
:"adbe.pkcs7.sha1"
PKCS7_DETACHED =
:"adbe.pkcs7.detached"

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:



532
533
534
535
536
537
# File 'lib/origami/signature.rb', line 532

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

    super
end

#rangesObject



556
557
558
559
560
561
562
563
564
565
566
# File 'lib/origami/signature.rb', line 556

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:



568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
# File 'lib/origami/signature.rb', line 568

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:



539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
# File 'lib/origami/signature.rb', line 539

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