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

included, #infer_encoding, native_type, #to_pdfdoc, #to_utf16be, #to_utf8

Methods included from Object

#<=>, #cast_to, #copy, #export, #indirect_parent, #is_indirect?, #logicalize, #logicalize!, native_type, #native_type, #pdf, #pdf_version_required, #post_build, #pre_build, #reference, #resolve_all_references, #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.



198
199
200
201
202
203
204
205
# File 'lib/origami/string.rb', line 198

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, parser = nil) ⇒ Object

:nodoc:



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/origami/string.rb', line 207

def self.parse(stream, parser = nil) #: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



235
236
237
# File 'lib/origami/string.rb', line 235

def to_raw
  ByteString.new(self.value)
end

#to_sObject

:nodoc:



228
229
230
# File 'lib/origami/string.rb', line 228

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

#valueObject



239
240
241
242
243
# File 'lib/origami/string.rb', line 239

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

  to_str
end