kubernaut/lib/sensitive.rb
Ryan Cavicchioni 629ea6eaee
Some checks failed
Gitea Actions Demo / lint (push) Failing after 28s
Gitea Actions Demo / test (push) Has been skipped
Gitea Actions Demo / release-image (push) Has been skipped
fix frozen string literal warning
2025-03-11 04:54:04 -05:00

40 lines
549 B
Ruby

class Sensitive
alias_method :eql?, :==
alias_method :equal?, :==
def initialize(v, ch: "*", head: 2, tail: 2)
@v = v
@ch = ch
@head = head
@tail = tail
end
def mask(v)
String.new.concat(v[0, @head], @ch * (v.length - (@head + @tail)), v[-@tail, @tail])
end
def unwrap
@v
end
def length
@v.length
end
def to_s
mask @v
end
def inspect
"#<#{self.class.name} @v=#{wrap}>"
end
def hash
@v.hash
end
def ==(other)
other.is_a?(Sensitive) && other.hash == hash
end
end