From 302ccfd429226d43f31dd1b189de64df0f67e0be Mon Sep 17 00:00:00 2001 From: Lee Salminen Date: Fri, 19 Aug 2022 16:52:06 -0600 Subject: [PATCH] add better error handling --- lnbits/extensions/boltcards/views_api.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lnbits/extensions/boltcards/views_api.py b/lnbits/extensions/boltcards/views_api.py index 2271f1504..d58369f7f 100644 --- a/lnbits/extensions/boltcards/views_api.py +++ b/lnbits/extensions/boltcards/views_api.py @@ -55,6 +55,26 @@ async def api_card_create_or_update( card_id: str = None, wallet: WalletTypeInfo = Depends(require_admin_key), ): + if(len(bytes.fromhex(data.uid)) != 7): + raise HTTPException( + detail="Invalid bytes for card uid.", status_code=HTTPStatus.BAD_REQUEST + ) + + if(len(bytes.fromhex(data.k0)) != 16): + raise HTTPException( + detail="Invalid bytes for k0.", status_code=HTTPStatus.BAD_REQUEST + ) + + if(len(bytes.fromhex(data.k1)) != 16): + raise HTTPException( + detail="Invalid bytes for k1.", status_code=HTTPStatus.BAD_REQUEST + ) + + if(len(bytes.fromhex(data.k2)) != 16): + raise HTTPException( + detail="Invalid bytes for k2.", status_code=HTTPStatus.BAD_REQUEST + ) + if card_id: card = await get_card(card_id) if not card: