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 included from ObjectCache

#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

#[], #[]=, hint_type, #initialize, #merge, parse, #to_h, #to_obfuscated_str, #transform_values, #transform_values!

Methods included from TypeGuessing

#guess_type

Methods included from FieldAccessor

#method_missing, #respond_to_missing?

Methods included from CompoundObject

#copy, #delete, #include?, #update_values, #update_values!

Methods included from ObjectCache

#initialize, #rebuild_caches

Methods included from Object

#cast_to, #copy, #document, #export, included, #indirect?, #indirect_parent, #initialize, #logicalize, #logicalize!, #native_type, #numbered?, 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

#certificate_chainObject



606
607
608
609
610
611
612
613
614
615
# File 'lib/origami/signature.rb', line 606

def certificate_chain
    return [] unless key?(:Cert)

    chain = self.Cert
    unless chain.is_a?(String) or (chain.is_a?(Array) and chain.all?{|cert| cert.is_a?(String)})
        return SignatureError, "Invalid embedded certificate chain"
    end

    [ chain ].flatten.map! {|str| OpenSSL::X509::Certificate.new(str) }
end

#pre_buildObject

:nodoc:



564
565
566
567
568
569
# File 'lib/origami/signature.rb', line 564

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

    super
end

#rangesObject



588
589
590
591
592
593
594
595
596
597
598
# File 'lib/origami/signature.rb', line 588

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_dataObject

Raises:



600
601
602
603
604
# File 'lib/origami/signature.rb', line 600

def signature_data
    raise SignatureError, "Invalid signature data" unless self[:Contents].is_a?(String)

    self[:Contents]
end

#signature_offsetObject

:nodoc:



617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
# File 'lib/origami/signature.rb', line 617

def signature_offset #:nodoc:
    indent, tab, eol = 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", eol: $/) ⇒ Object

:nodoc:



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

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

    # Must be deterministic.
    indent, tab, eol = 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