Class: Origami::HexaString

Inherits:
String
  • Object
show all
Includes:
String
Defined in:
lib/origami/string.rb,
lib/origami/obfuscation.rb

Overview

Class representing an hexadecimal-writen String Object.

Constant Summary collapse

TOKENS =

:nodoc:

%w{ < > }
@@regexp_open =
Regexp.new(WHITESPACES + TOKENS.first)
@@regexp_close =
Regexp.new(TOKENS.last)

Instance Attribute Summary

Attributes included from String

#encoding

Attributes included from Object

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from String

#infer_encoding, #real_type, #to_pdfdoc, #to_utf16be, #to_utf8

Methods included from Object

#<=>, #copy, #indirect_parent, #is_indirect?, #pdf, #pdf_version_required, #post_build, #pre_build, #reference, #set_indirect, #set_pdf, #size, skip_until_next_obj, #solve, #to_o, #type, typeof, #xrefs

Methods inherited from String

#is_binary_data?, #to_o

Constructor Details

#initialize(str = "") ⇒ HexaString

Creates a new PDF hexadecimal String.

str

The string value.



182
183
184
185
186
187
188
189
# File 'lib/origami/string.rb', line 182

def initialize(str = "")
  
  unless str.is_a?(::String)
    raise TypeError, "Expected type String, received #{str.class}."
  end
  
  super(str)
end

Class Method Details

.parse(stream) ⇒ Object

:nodoc:



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/origami/string.rb', line 191

def self.parse(stream) #:nodoc:

  offset = stream.pos
    
  if stream.skip(@@regexp_open).nil?
    raise InvalidHexaStringObjectError, "Hexadecimal string shall start with a '#{TOKENS.first}' token"
  end
    
  hexa = stream.scan_until(@@regexp_close)
  if hexa.nil?
    raise InvalidHexaStringObjectError, "Hexadecimal string shall end with a '#{TOKENS.last}' token"
  end

  decoded = Filter::ASCIIHex.decode(hexa.chomp!(TOKENS.last))
    
  hexastr = HexaString.new(decoded)
  hexastr.file_offset = offset

  hexastr
end

Instance Method Details

#to_obfuscated_strObject



179
180
181
# File 'lib/origami/obfuscation.rb', line 179

def to_obfuscated_str
  to_s
end

#to_rawObject

Converts self to ByteString



219
220
221
# File 'lib/origami/string.rb', line 219

def to_raw
  ByteString.new(self.value)
end

#to_sObject

:nodoc:



212
213
214
# File 'lib/origami/string.rb', line 212

def to_s #:nodoc:
  super(TOKENS.first + Filter::ASCIIHex.encode(to_str) + TOKENS.last)
end

#valueObject



223
224
225
226
227
# File 'lib/origami/string.rb', line 223

def value
  self.decrypt! if self.is_a?(Encryption::EncryptedString) and not @decrypted

  to_str
end