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

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

Overview

Deprecated.

This class shouldn’t have been exposed

Class responsible for obfuscating sensitive data in a message body.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fixed_length, keep_start_count, keep_end_count) ⇒ ValueObfuscator

Creates a new ValueObfuscator.

Parameters:

  • fixed_length (Integer)

    if greater than 0, all values that will be obfuscated will be replaced with that number of asterisks.

  • 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.

  • 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.



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

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

Class Method Details

.ALLObject



40
41
42
43
# File 'lib/ingenico/connect/sdk/logging/logging_util.rb', line 40

def self.ALL
  # use lazy instantiation
  @@ALL ||= ValueObfuscator.send(:private_new, 0, 0, 0)
end

.fixed_length(fixed_length) ⇒ Object

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



46
47
48
# File 'lib/ingenico/connect/sdk/logging/logging_util.rb', line 46

def self.fixed_length(fixed_length)
  ValueObfuscator.send(:private_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.



58
59
60
# File 'lib/ingenico/connect/sdk/logging/logging_util.rb', line 58

def self.keep_end_count(count)
  ValueObfuscator.send(:private_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.



52
53
54
# File 'lib/ingenico/connect/sdk/logging/logging_util.rb', line 52

def self.keep_start_count(count)
  ValueObfuscator.send(:private_new, 0, count, 0)
end

.new(*args) ⇒ Object

Raises:

  • (NoMethodError)


17
18
19
# File 'lib/ingenico/connect/sdk/logging/logging_util.rb', line 17

def new(*args)
  raise NoMethodError.new('ValueObfuscator should not explicitly instantiated!')
end

.private_newObject



15
# File 'lib/ingenico/connect/sdk/logging/logging_util.rb', line 15

alias_method :private_new, :new

Instance Method Details

#obfuscate_value(value) ⇒ Object

Obfuscates the parameter value.



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/ingenico/connect/sdk/logging/logging_util.rb', line 63

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