class KPM::Account

def b64_decode_if_needed(input)

def b64_decode_if_needed(input)
  # Exclude nil or non string
  return input if input.nil? || !input.is_a?(String)
  # Apply regex to check that string is built as a B64 string: the character set is [A-Z, a-z, 0-9, and + /]
  # and if the rest length is less than 4, the string is padded with '=' characters.
  return input if input.match(B64_REGEX).nil?
  # Decode
  result = Base64.decode64(input)
  # Verify encoded of the decoded value == input prior return result
  return input if  Base64.strict_encode64(result) != input
  Blob.new(result, TMP_DIR)
end