Module: NmDatafile::FileEncoding

Included in:
NmDatafile, NmDatafile
Defined in:
lib/nm_datafile/file_encoding.rb

Instance Method Summary collapse

Instance Method Details

#deobfuscate_file_formatObject



69
70
71
# File 'lib/nm_datafile/file_encoding.rb', line 69

def deobfuscate_file_format
  
end

#encode_datafiles_as_zip(hash_of_entries) ⇒ Object

hash consists of string_data output is a binary string representing a zip file of the entries specified



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/nm_datafile/file_encoding.rb', line 11

def encode_datafiles_as_zip(hash_of_entries)
  temp_file = Tempfile.new(file_type.to_s, get_temp_directory)
  FileUtils.rm temp_file.path
  
  stream = ::Zip::OutputStream.write_buffer do |zos|
    hash_of_entries.each do |entry_name, data|
      zos.put_next_entry entry_name
      zos.write data
    end
  end
  
  stream.rewind
  stream.read
end

#encode_string_as_password_protected(encryptable_portion, pass = nil) ⇒ Object

TODu: rename to encode_password_protected_string



55
56
57
58
59
60
61
62
63
# File 'lib/nm_datafile/file_encoding.rb', line 55

def encode_string_as_password_protected(encryptable_portion, pass = nil)
  pish = @password
  pish = pass unless pass.nil?
  raise "error, password given was too long, must be 56 or less chars" if pish.length > 56
  
  encrypted = Blowfish.encrypt(pish, encryptable_portion)
  
  encrypted
end

#encode_string_as_password_protected_old_zip_based(encryptable_portion, pass = nil) ⇒ Object

Play: Below will write to stdout as long as stdout isn’t the terminal (so works in irb and ruby) zip -P ‘fp5!IZbVxgx2hWh8m*UQyc@d5nCGCrbiqPx73hh&’ - file_to_add

Below is attempt to read file from stdin: out = ‘echo ’hi’ | zip -P ‘fp5!IZbVxgx2hWh8m*UQyc@d5nCGCrbiqPx73hh&’ - -‘

Zip commandline is zip -P ‘fp5!IZbVxgx2hWh8m*UQyc@d5nCGCrbiqPx73hh&’ zip_to_make.zip file_to_add maybe password has invalid chars



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/nm_datafile/file_encoding.rb', line 37

def encode_string_as_password_protected_old_zip_based(encryptable_portion, pass = nil)
  pish = @password 
  pish = pass unless pass.nil?
  
  supress_errors = "2>/dev/null"
  # this will read that file... let's try passing it in from stdin pipes though
  # alt = "zip -P '#{pish}' - #{@@clear_text_path}"
  
  # TODu:  escape single quotes or this command breaks...  
  raise "tried to encrypt an encryptable_portion which contained illegal character ' which would break the command being piped to zip" if encryptable_portion =~ /\'/ 
  # passing in clear_text through pipes
  alt = "echo '#{encryptable_portion}'| zip -P '#{pish}' - - #{supress_errors}"
  #alt = "echo '#{encryptable_portion.gsub("\\n", "")}'| zip -P '#{pish}' - -"

  binary_output = `#{alt}`
end

#obfuscate_file_formatObject



65
66
67
# File 'lib/nm_datafile/file_encoding.rb', line 65

def obfuscate_file_format
  # TODu: implement me
end