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



599
600
601
602
603
604
605
606
607
608
# File 'lib/origami/signature.rb', line 599

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

  chain = self.Cert
  if !chain.is_a?(String) && !(chain.is_a?(Array) && 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:



556
557
558
559
560
561
# File 'lib/origami/signature.rb', line 556

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

  super
end

#rangesObject



581
582
583
584
585
586
587
588
589
590
591
# File 'lib/origami/signature.rb', line 581

def ranges
  byte_range = self.ByteRange

  unless byte_range.is_a?(Array) && (byte_range.length == 4) && 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:



593
594
595
596
597
# File 'lib/origami/signature.rb', line 593

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

  self[:Contents]
end

#signature_offsetObject

:nodoc:



610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
# File 'lib/origami/signature.rb', line 610

def signature_offset # :nodoc:
  indent_value = 1
  tab_value = "\t"
  eol_value = $/
  content = "#{no} #{generation} obj" + eol_value + TOKENS.first + eol_value

  to_a.sort_by { |key, _| key }.reverse_each do |key, value|
    if key == :Contents
      content << tab_value * indent_value + key.to_s + " "

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

  nil
end

#to_s(indent: nil, tab: nil, eol: nil) ⇒ Object

:nodoc:



563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
# File 'lib/origami/signature.rb', line 563

def to_s(indent: nil, tab: nil, eol: nil) # :nodoc:
  # Must be deterministic, ignore parameters
  indent_value = 1
  tab_value = "\t"
  eol_value = $/

  content = TOKENS.first + eol_value

  to_a.sort_by { |key, _| key }.reverse_each do |key, value|
    content << tab_value * indent_value << key.to_s << " "
    content << (value.is_a?(Dictionary) ? value.to_s(indent: indent_value + 1) : value.to_s) << eol_value
  end

  content << tab_value * (indent_value - 1) << TOKENS.last

  output(content)
end