import six
import binascii
import hashlib


def get_token_fingerprint(blob):
  """Given a blob with a token returns first 16 bytes of its SHA256 as hex.

  It can be used to identify this particular token in logs without revealing it.
  """
  assert isinstance(blob, six.string_types)
  if isinstance(blob, six.text_type):
    blob = blob.encode('ascii', 'ignore')
  return binascii.hexlify(hashlib.sha256(blob).digest()[:16])