From: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
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 [thread overview]
Message-ID: <20210507181322.172569-2-konstantin@linuxfoundation.org> (raw)
In-Reply-To: <20210507181322.172569-1-konstantin@linuxfoundation.org>
Don't backtrace all over the screen -- give a nice error message.
Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
---
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
next prev parent reply other threads:[~2021-05-07 18:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-07 18:13 [PATCH 0/3] Test series signed by patatt-0.1.0 Konstantin Ryabitsev
2021-05-07 18:13 ` Konstantin Ryabitsev [this message]
2021-05-07 18:13 ` [PATCH 2/3] Throw a KeyError, not RuntimeError Konstantin Ryabitsev
2021-05-07 18:13 ` [PATCH 3/3] Add manpages and prepare for 0.1.0 release Konstantin Ryabitsev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210507181322.172569-2-konstantin@linuxfoundation.org \
--to=konstantin@linuxfoundation.org \
--cc=signatures@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).