async def _validate(key: str): if not muid.validate(key): raise HTTPException(status_code=http.HTTPStatus.BAD_REQUEST, detail='Invalid key') record = await database.fetch_one("select * from keys where key=:key", values={'key': key}) if record is not None: raise HTTPException(status_code=http.HTTPStatus.ALREADY_REPORTED, detail=f'key already in db: {record}')
def test_create(): key = create(difficulty=7) assert validate(key)
def is_valid_key(key): """ Check if key is hash-memorable """ return isinstance(key, str) and muid.validate(key)