def check_session_id_signature(session_id, secret_key=settings.secret_key_bytes(), signed=settings.sign_sessions()):
 secret_key = _ensure_bytes(secret_key)
 if signed:
  pieces = session_id.split('-', 1)
  if (len(pieces) != 2):
   return False
  base_id = pieces[0]
  provided_signature = pieces[1]
  expected_signature = _signature(base_id, secret_key)
  return hmac.compare_digest(expected_signature, provided_signature)
 else:
  return True

def check_session_id_signature ( session_id , secret_key = settings . secret_key_bytes ( ) , signed = settings . sign_sessions ( ) ) : secret_key = _ensure_bytes ( secret_key ) if signed : pieces = session_id . split ( '-' , 1 ) if ( len ( pieces ) != 2 ) : return False base_id = pieces [ 0 ] provided_signature = pieces [ 1 ] expected_signature = _signature ( base_id , secret_key ) return hmac . compare_digest ( expected_signature , provided_signature ) else : return True
check the signature of a session id .