Class: Ingenico::Connect::SDK::Logging::ValueObfuscator

Inherits:
Object
  • Object
show all
Defined in:
lib/ingenico/connect/sdk/logging/logging_util.rb

Overview

Class responsible for obfuscating sensitive data in a message body.

Constant Summary collapse

@@ALL =
ValueObfuscator.new(0, 0, 0)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.ALLObject



27
28
29
# File 'lib/ingenico/connect/sdk/logging/logging_util.rb', line 27

def self.ALL
  @@ALL
end

.fixed_length(fixed_length) ⇒ Object

Creates a new ValueObfuscator that replaces any sensitive data with a fixed_length line of asterisks.



32
33
34
# File 'lib/ingenico/connect/sdk/logging/logging_util.rb', line 32

def self.fixed_length(fixed_length)
  ValueObfuscator.new(fixed_length, 0, 0)
end

.keep_end_count(count) ⇒ Object

Creates a new ValueObfuscator that retains only the last count characters of any value to obfuscate and replaces the rest with asterisks.



44
45
46
# File 'lib/ingenico/connect/sdk/logging/logging_util.rb', line 44

def self.keep_end_count(count)
  ValueObfuscator.new(0, 0, count)
end

.keep_start_count(count) ⇒ Object

Creates a new ValueObfuscator that retains only the first count characters of any value to obfuscate and replaces the rest with asterisks.



38
39
40
# File 'lib/ingenico/connect/sdk/logging/logging_util.rb', line 38

def self.keep_start_count(count)
  ValueObfuscator.new(0, count, 0)
end

Instance Method Details

#obfuscate_value(value) ⇒ Object

Obfuscates the parameter value.



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ingenico/connect/sdk/logging/logging_util.rb', line 49

def obfuscate_value(value)
  return value if value.nil? or value.empty?
  return repeat_mask(@fixed_length) if @fixed_length > 0
  return repeat_mask(value.length) if @keep_start_count == 0 and @keep_end_count == 0
  return value if value.length < (@keep_start_count + @keep_end_count)

  # range describes the range of characters to replace with asterisks
  range = @keep_start_count...(value.length - @keep_end_count)
  value[range] = @mask_character * range.size
  value
end