Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9373AC433ED for ; Fri, 7 May 2021 18:13:24 +0000 (UTC) Received: by mail.kernel.org (Postfix) id 76E7F6100A; Fri, 7 May 2021 18:13:24 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 3A73F61059 for ; Fri, 7 May 2021 18:13:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620411204; bh=8rOebsleLF5pOyVnOJn0CDsUGUutN53cOGFmqnPcSWU=; h=From:List-Id:To:Subject:Date:In-Reply-To:References:From; b=N9CPnu/gQ6j/tnw3tzT1dVqsEO39CNFTmXYT0j8I/TdOArl1XaHqBfLPWL6p9onh9 fhAfXl7ym8oaFRICQKfgnfDQWAOv2ZXyHAINQdtSXR8L1fifmGVBKlciv9oHzsCun2 u1noLYr1E3iFEEISbMJLcDhpkgx9iU2jY4B7vGrY= From: Konstantin Ryabitsev List-Id: To: signatures@kernel.org Subject: [PATCH 1/3] Nicer crash for when PyNaCl isn't available Date: Fri, 7 May 2021 14:13:20 -0400 Message-Id: <20210507181322.172569-2-konstantin@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210507181322.172569-1-konstantin@linuxfoundation.org> References: <20210507181322.172569-1-konstantin@linuxfoundation.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1643; h=from:subject; bh=8rOebsleLF5pOyVnOJn0CDsUGUutN53cOGFmqnPcSWU=; b=owGbwMvMwCG27YjM47CUmTmMp9WSGBKmNjuZRDLtMBCyyXqY58Jj56DrenVy1LP9a7slYm9d1lgS eH9SRykLgxgHg6yYIkvZvthNQYUPPeTSe0xh5rAygQxh4OIUgIlEMTIy7P16aBHrJu7VXy2EFj1cz7 t80pqWc2ozls7VnST2jzHc0YHhf8hRRqbazFafmNb3AYXObx9PPr1yUvuCyQZ7zGuS536czg4A X-Developer-Key: i=konstantin@linuxfoundation.org; a=openpgp; fpr=DE0E66E32F1FDD0902666B96E63EDCA9329DD07E Content-Transfer-Encoding: 8bit Don't backtrace all over the screen -- give a nice error message. Signed-off-by: Konstantin Ryabitsev --- patatt/__init__.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/patatt/__init__.py b/patatt/__init__.py index a3870b8..e54bb10 100644 --- a/patatt/__init__.py +++ b/patatt/__init__.py @@ -222,8 +222,11 @@ class DevsigHeader: @staticmethod def _sign_ed25519(payload: bytes, privkey: bytes) -> Tuple[bytes, bytes]: global KEYCACHE - from nacl.signing import SigningKey - from nacl.encoding import Base64Encoder + try: + from nacl.signing import SigningKey + from nacl.encoding import Base64Encoder + except ModuleNotFoundError: + raise RuntimeError('This operation requires PyNaCl libraries') if privkey not in KEYCACHE: sk = SigningKey(privkey, encoder=Base64Encoder) @@ -238,9 +241,12 @@ class DevsigHeader: @staticmethod def _validate_ed25519(sigdata: bytes, pubkey: bytes) -> bytes: - from nacl.signing import VerifyKey - from nacl.encoding import Base64Encoder - from nacl.exceptions import BadSignatureError + try: + from nacl.signing import VerifyKey + from nacl.encoding import Base64Encoder + from nacl.exceptions import BadSignatureError + except ModuleNotFoundError: + raise RuntimeError('This operation requires PyNaCl libraries') vk = VerifyKey(pubkey, encoder=Base64Encoder) try: -- 2.31.1