class Ingenico::Connect::SDK::Logging::ValueObfuscator

Class responsible for obfuscating sensitive data in a message body.

Public Class Methods

ALL() click to toggle source
# File lib/ingenico/connect/sdk/logging/logging_util.rb, line 34
def self.ALL
  # use lazy instantiation
  @@ALL ||= ValueObfuscator.send(:private_new, 0, 0, 0)
end
fixed_length(fixed_length) click to toggle source

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

# File lib/ingenico/connect/sdk/logging/logging_util.rb, line 40
def self.fixed_length(fixed_length)
  ValueObfuscator.send(:private_new, fixed_length, 0, 0)
end
keep_end_count(count) click to toggle source

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

# File lib/ingenico/connect/sdk/logging/logging_util.rb, line 52
def self.keep_end_count(count)
  ValueObfuscator.send(:private_new, 0, 0, count)
end
keep_start_count(count) click to toggle source

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

# File lib/ingenico/connect/sdk/logging/logging_util.rb, line 46
def self.keep_start_count(count)
  ValueObfuscator.send(:private_new, 0, count, 0)
end
new(fixed_length, keep_start_count, keep_end_count) click to toggle source

Creates a new ValueObfuscator.

@param fixed_length [Integer] if greater than 0, all values that will be obfuscated will be replaced with that number of asterisks. @param keep_start_count [Integer] the number of characters to not obfuscate at the end of any value.

This parameter is only used if _fixed_length_ = 0

@param keep_end_count [Integer] the number of characters to not obfuscate at the start of any value.

This parameter is only used if _fixed_length_ = 0
# File lib/ingenico/connect/sdk/logging/logging_util.rb, line 25
def initialize(fixed_length, keep_start_count, keep_end_count)
  @mask_character = '*'
  @fixed_length = fixed_length
  @keep_start_count = keep_start_count
  @keep_end_count = keep_end_count
end

Private Class Methods

new(*args) click to toggle source
# File lib/ingenico/connect/sdk/logging/logging_util.rb, line 11
def new(*args)
  raise NoMethodError.new('ValueObfuscator should not explicitly instantiated!')
end
Also aliased as: private_new
private_new(*args)
Alias for: new

Public Instance Methods

obfuscate_value(value) click to toggle source

Obfuscates the parameter value.

# File lib/ingenico/connect/sdk/logging/logging_util.rb, line 57
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

Private Instance Methods

repeat_mask(count) click to toggle source
# File lib/ingenico/connect/sdk/logging/logging_util.rb, line 71
def repeat_mask(count)
  @mask_character * count
end