def _get_val(): token = get_token(request) if token is None: # In order to be able to provide debugging info in the # case of misconfiguration, we use a sentinel value # instead of returning an empty dict. return 'NOTPROVIDED' else: token = force_bytes(token, encoding='latin-1') key = force_bytes(get_random_string(len(token)), encoding='latin-1') value = b64_encode(xor(token, key)) return force_text(b'$'.join((key, value)), encoding='latin-1')
def _get_val(): token = get_token(request) if token is None: # In order to be able to provide debugging info in the # case of misconfiguration, we use a sentinel value # instead of returning an empty dict. return 'NOTPROVIDED' else: token = force_bytes(token, encoding='latin-1') key = force_bytes( get_random_string(len(token)), encoding='latin-1' ) value = b64_encode(xor(token, key)) return force_text(b'$'.join((key, value)), encoding='latin-1')
def _decode(self, token): key, value = force_bytes(token, encoding='latin-1').split(b'$', 1) return force_text(xor(b64_decode(value), key), encoding='latin-1')