Module: NewRelic::Agent::CrossAppMonitor::EncodingFunctions

Included in:
NewRelic::Agent::CrossAppMonitor, NewRelic::Agent::CrossAppTracing
Defined in:
lib/new_relic/agent/cross_app_monitor.rb

Overview

Functions for obfuscating and unobfuscating header values

Class Method Summary collapse

Class Method Details

.decode_with_key(key, text) ⇒ Object



41
42
43
# File 'lib/new_relic/agent/cross_app_monitor.rb', line 41

def decode_with_key(key, text)
  encode_with_key( key, text.unpack('m').first )
end

.encode_with_key(key, text) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/new_relic/agent/cross_app_monitor.rb', line 45

def encode_with_key(key, text)
  return text unless key
  key = key.bytes.to_a if key.respond_to?( :bytes )

  encoded = ""
  encoded.force_encoding('binary') if encoded.respond_to?( :force_encoding )
  index = 0
  text.each_byte do |byte|
    encoded.concat((byte ^ key[index % key.length].to_i))
    index+=1
  end
  encoded
end

.obfuscate_with_key(key, text) ⇒ Object



37
38
39
# File 'lib/new_relic/agent/cross_app_monitor.rb', line 37

def obfuscate_with_key(key, text)
  [ encode_with_key(key, text) ].pack('m').chomp.gsub(/\n/, '')
end