class NewRelic::Agent::Obfuscator
Constants
- EMPTY_KEY_BYTES
- PACK_FORMAT
Attributes
key_bytes[R]
Public Class Methods
new(key, length = nil)
click to toggle source
RUM uses a shortened key, so just trim it up front
# File lib/new_relic/agent/obfuscator.rb, line 14 def initialize(key, length = nil) if key.nil? || key.empty? @key_bytes = EMPTY_KEY_BYTES else @key_bytes = key.bytes.to_a @key_bytes = @key_bytes.first(length) if length end end
Public Instance Methods
deobfuscate(text)
click to toggle source
# File lib/new_relic/agent/obfuscator.rb, line 27 def deobfuscate(text) encode(text.unpack(PACK_FORMAT).first) end
encode(text)
click to toggle source
# File lib/new_relic/agent/obfuscator.rb, line 31 def encode(text) return text unless key_bytes encoded = +'' encoded.force_encoding('binary') if encoded.respond_to?(:force_encoding) index = 0 text.each_byte do |byte| encoded.concat((byte ^ key_bytes[index % key_bytes.length])) index += 1 end encoded end
obfuscate(text)
click to toggle source
# File lib/new_relic/agent/obfuscator.rb, line 23 def obfuscate(text) [encode(text)].pack(PACK_FORMAT).delete("\n") end