Class: OneApm::Agent::Obfuscator
- Inherits:
-
Object
- Object
- OneApm::Agent::Obfuscator
- Defined in:
- lib/one_apm/support/obfuscator.rb
Constant Summary collapse
- OA_EMPTY_KEY_BYTES =
[0]
- OA_PACK_FORMAT =
'm'
Instance Attribute Summary collapse
-
#key_bytes ⇒ Object
readonly
Returns the value of attribute key_bytes.
Instance Method Summary collapse
- #deobfuscate(text) ⇒ Object
- #encode(text) ⇒ Object
-
#initialize(key, length = nil) ⇒ Obfuscator
constructor
RUM uses a shortened key, so just trim it up front.
- #obfuscate(text) ⇒ Object
Constructor Details
#initialize(key, length = nil) ⇒ Obfuscator
RUM uses a shortened key, so just trim it up front
15 16 17 18 19 20 21 22 |
# 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 |
Instance Attribute Details
#key_bytes ⇒ Object (readonly)
Returns the value of attribute key_bytes.
9 10 11 |
# File 'lib/one_apm/support/obfuscator.rb', line 9 def key_bytes @key_bytes end |
Instance Method Details
#deobfuscate(text) ⇒ Object
28 29 30 |
# File 'lib/one_apm/support/obfuscator.rb', line 28 def deobfuscate(text) encode(text.unpack(OA_PACK_FORMAT).first ) end |
#encode(text) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# 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) ⇒ Object
24 25 26 |
# File 'lib/one_apm/support/obfuscator.rb', line 24 def obfuscate(text) [ encode(text) ].pack(OA_PACK_FORMAT).gsub(/\n/, '') end |