class OneApm::Agent::Obfuscator
Constants
- OA_EMPTY_KEY_BYTES
- OA_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/one_apm/support/obfuscator.rb, line 15 def initialize(key, length=nil) if key.nil? || key.empty? @key_bytes = OA_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/one_apm/support/obfuscator.rb, line 28 def deobfuscate(text) encode(text.unpack(OA_PACK_FORMAT).first ) end
encode(text)
click to toggle source
# File lib/one_apm/support/obfuscator.rb, line 32 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/one_apm/support/obfuscator.rb, line 24 def obfuscate(text) [ encode(text) ].pack(OA_PACK_FORMAT).gsub(/\n/, '') end