Skip to content

Commit

Permalink
Fix errors from running ruff check
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiasertl committed Sep 29, 2024
1 parent d1ddb0b commit 958b015
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
6 changes: 3 additions & 3 deletions pkcs11/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class DataInvalid(PKCS11Error):
class DataLenRange(PKCS11Error):
"""
The plaintext input data to a cryptographic operation has a bad length.
Depending on the operations mechanism, this could mean that the plaintext
Depending on the operation's mechanism, this could mean that the plaintext
data is too short, too long, or is not a multiple of some particular block
size.
"""
Expand Down Expand Up @@ -103,7 +103,7 @@ class EncryptedDataLenRange(PKCS11Error):
"""
The ciphertext input to a decryption operation has been determined to be
invalid ciphertext solely on the basis of its length. Depending on the
operations mechanism, this could mean that the ciphertext is too short,
operation's mechanism, this could mean that the ciphertext is too short,
too long, or is not a multiple of some particular block size.
"""

Expand Down Expand Up @@ -232,7 +232,7 @@ class OperationActive(PKCS11Error):
activating an encryption operation with C_EncryptInit. Or, an active
digesting operation and an active encryption operation would prevent
Cryptoki from activating a signature operation. Or, on a token which
doesnt support simultaneous dual cryptographic operations in a session
doesn't support simultaneous dual cryptographic operations in a session
(see the description of the CKF_DUAL_CRYPTO_OPERATIONS flag in the
CK_TOKEN_INFO structure), an active signature operation would prevent
Cryptoki from activating an encryption operation.
Expand Down
8 changes: 4 additions & 4 deletions pkcs11/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ def get_key(self, object_class=None, key_type=None, label=None, id=None):
try:
try:
key = next(iterator)
except StopIteration:
raise NoSuchKey("No key matching %s" % attrs)
except StopIteration as ex:
raise NoSuchKey("No key matching %s" % attrs) from ex

try:
next(iterator)
Expand Down Expand Up @@ -645,8 +645,8 @@ def __getitem__(self, key):
if self._handle is None:
try:
return self.params[key]
except KeyError:
raise AttributeTypeInvalid
except KeyError as ex:
raise AttributeTypeInvalid from ex
else:
return super().__getitem__(key)

Expand Down
17 changes: 10 additions & 7 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,30 @@

try:
LIB = os.environ["PKCS11_MODULE"]
except KeyError:
raise RuntimeError("Must define `PKCS11_MODULE' to run tests.")
except KeyError as ex:
raise RuntimeError("Must define `PKCS11_MODULE' to run tests.") from ex


try:
TOKEN = os.environ["PKCS11_TOKEN_LABEL"]
except KeyError:
raise RuntimeError("Must define `PKCS11_TOKEN_LABEL' to run tests.")
except KeyError as ex:
raise RuntimeError("Must define `PKCS11_TOKEN_LABEL' to run tests.") from ex

TOKEN_PIN = os.environ.get("PKCS11_TOKEN_PIN") # Can be None
if TOKEN_PIN is None:
warn("`PKCS11_TOKEN_PIN' env variable is unset.")
warn("`PKCS11_TOKEN_PIN' env variable is unset.", stacklevel=2)

TOKEN_SO_PIN = os.environ.get("PKCS11_TOKEN_SO_PIN")
if TOKEN_SO_PIN is None:
TOKEN_SO_PIN = TOKEN_PIN
warn("`PKCS11_TOKEN_SO_PIN' env variable is unset. Using value from `PKCS11_TOKEN_PIN'")
warn(
"`PKCS11_TOKEN_SO_PIN' env variable is unset. Using value from `PKCS11_TOKEN_PIN'",
stacklevel=2,
)

OPENSSL = shutil.which("openssl", path=os.environ.get("OPENSSL_PATH"))
if OPENSSL is None:
warn("Path to OpenSSL not found. Please adjust `PATH' or define `OPENSSL_PATH'")
warn("Path to OpenSSL not found. Please adjust `PATH' or define `OPENSSL_PATH'", stacklevel=2)


class TestCase(unittest.TestCase):
Expand Down

0 comments on commit 958b015

Please sign in to comment.