Skip to content

Commit 20be13f

Browse files
authored
line length change to 88 chars (ruff default) (#841)
* ruff linter line length set to default (88 chars), code changes to comply Co-authored-by: l77h <>
1 parent 9a45179 commit 20be13f

26 files changed

+113
-280
lines changed

pyproject.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,12 @@ lint.select = [
8181
"N", # pep8-naming: all
8282
"RUF100" # ruff: find unused noqa
8383
]
84-
lint.ignore = [
85-
"E501" # ignore line-too-long
86-
]
8784
exclude = ["_vendor"]
8885

89-
# Same as Black.
90-
line-length = 80
9186
indent-width = 4
9287

9388
[tool.ruff.lint.per-file-ignores]
9489
"tests/*" = [
9590
"S", # bandit: Not running bandit on tests
91+
"E501" # line-too-long
9692
]

securesystemslib/_gpg/common.py

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ def parse_pubkey_bundle(data):
266266
PACKET_TYPE_USER_ID,
267267
]:
268268
if key_bundle[_type]:
269-
# Add to most recently added packet's signatures of matching type
269+
# Add to most recently added packet's
270+
# signatures of matching type
270271
key_bundle[_type][next(reversed(key_bundle[_type]))][
271272
"signatures"
272273
].append(packet)
@@ -275,9 +276,7 @@ def parse_pubkey_bundle(data):
275276
else:
276277
# If no packets are available for any of above types (yet), the
277278
# signature belongs to the primary key
278-
key_bundle[PACKET_TYPE_PRIMARY_KEY]["signatures"].append(
279-
packet
280-
)
279+
key_bundle[PACKET_TYPE_PRIMARY_KEY]["signatures"].append(packet)
281280

282281
else:
283282
packets_list = [
@@ -358,9 +357,7 @@ def _assign_certified_key_info(bundle):
358357
)
359358
# verify_signature requires a "keyid" even if it is short.
360359
# (see parse_signature_packet for more information about keyids)
361-
signature["keyid"] = (
362-
signature["keyid"] or signature["short_keyid"]
363-
)
360+
signature["keyid"] = signature["keyid"] or signature["short_keyid"]
364361

365362
# TODO: Revise exception taxonomy:
366363
# It's okay to ignore some exceptions (unsupported algorithms etc.) but
@@ -430,10 +427,7 @@ def _assign_certified_key_info(bundle):
430427
if is_primary_user and not tmp_is_primary_user:
431428
continue
432429

433-
if (
434-
not sig_creation_time
435-
or sig_creation_time < tmp_sig_creation_time
436-
):
430+
if not sig_creation_time or sig_creation_time < tmp_sig_creation_time:
437431
# This is the most recent certificate that has a validity_period and
438432
# doesn't have lower priority in regard to the primary user id flag. We
439433
# accept it the keys validty_period, until we get a newer value from
@@ -445,9 +439,7 @@ def _assign_certified_key_info(bundle):
445439
sig_creation_time = tmp_sig_creation_time
446440

447441
if validity_period is not None:
448-
bundle[PACKET_TYPE_PRIMARY_KEY]["key"]["validity_period"] = (
449-
validity_period
450-
)
442+
bundle[PACKET_TYPE_PRIMARY_KEY]["key"]["validity_period"] = validity_period
451443

452444
return bundle[PACKET_TYPE_PRIMARY_KEY]["key"]
453445

@@ -495,9 +487,7 @@ def _get_verified_subkeys(bundle):
495487

496488
# Construct signed content (see RFC4880 section 5.2.4. paragraph 3)
497489
signed_content = (
498-
bundle[PACKET_TYPE_PRIMARY_KEY]["packet"]
499-
+ b"\x99"
500-
+ subkey_packet[1:]
490+
bundle[PACKET_TYPE_PRIMARY_KEY]["packet"] + b"\x99" + subkey_packet[1:]
501491
)
502492

503493
# Filter sub key binding signature from other signatures, e.g. subkey
@@ -513,9 +503,7 @@ def _get_verified_subkeys(bundle):
513503
)
514504
# verify_signature requires a "keyid" even if it is short.
515505
# (see parse_signature_packet for more information about keyids)
516-
signature["keyid"] = (
517-
signature["keyid"] or signature["short_keyid"]
518-
)
506+
signature["keyid"] = signature["keyid"] or signature["short_keyid"]
519507
key_binding_signatures.append(signature)
520508

521509
# TODO: Revise exception taxonomy
@@ -555,9 +543,7 @@ def _get_verified_subkeys(bundle):
555543
# If the signature is valid, we may also extract relevant information from
556544
# its "info" field (e.g. subkey expiration date) and assign to it to the
557545
# subkey here
558-
validity_period = signature["info"]["subpackets"].get(
559-
KEY_EXPIRATION_SUBPACKET
560-
)
546+
validity_period = signature["info"]["subpackets"].get(KEY_EXPIRATION_SUBPACKET)
561547
if validity_period is not None:
562548
subkey["validity_period"] = struct.unpack(">I", validity_period)[0]
563549

@@ -878,9 +864,7 @@ def parse_signature_packet(
878864

879865
signature_data = {
880866
"keyid": keyid,
881-
"other_headers": binascii.hexlify(data[:other_headers_ptr]).decode(
882-
"ascii"
883-
),
867+
"other_headers": binascii.hexlify(data[:other_headers_ptr]).decode("ascii"),
884868
"signature": binascii.hexlify(signature).decode("ascii"),
885869
}
886870

securesystemslib/_gpg/eddsa.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,7 @@ def verify_signature(signature_object, pubkey_info, content, hash_algorithm_id):
227227
)
228228

229229
try:
230-
pubkey_object.verify(
231-
binascii.unhexlify(signature_object["signature"]), digest
232-
)
230+
pubkey_object.verify(binascii.unhexlify(signature_object["signature"]), digest)
233231
return True
234232

235233
except InvalidSignature:

securesystemslib/_gpg/exceptions.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ def __init__(self, key):
4444
self.key = key
4545

4646
def __str__(self):
47-
creation_time = datetime.datetime.utcfromtimestamp(
48-
self.key["creation_time"]
49-
)
47+
creation_time = datetime.datetime.utcfromtimestamp(self.key["creation_time"])
5048
expiration_time = datetime.datetime.utcfromtimestamp(
5149
self.key["creation_time"] + self.key["validity_period"]
5250
)

securesystemslib/_gpg/functions.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,7 @@ def create_signature(content, keyid=None, homedir=None, timeout=GPG_TIMEOUT):
161161

162162
# ... or one of the subkeys, and add the full keyid to the signature dict.
163163
else:
164-
for sub_key_full_keyid in list(
165-
public_key_bundle.get("subkeys", {}).keys()
166-
):
164+
for sub_key_full_keyid in list(public_key_bundle.get("subkeys", {}).keys()):
167165
if sub_key_full_keyid.endswith(short_keyid.lower()):
168166
signature["keyid"] = sub_key_full_keyid
169167
break
@@ -237,9 +235,7 @@ def verify_signature(signature_object, pubkey_info, content):
237235
):
238236
raise KeyExpirationError(verification_key)
239237

240-
return handler.verify_signature(
241-
signature_object, verification_key, content, SHA256
242-
)
238+
return handler.verify_signature(signature_object, verification_key, content, SHA256)
243239

244240

245241
def export_pubkey(keyid, homedir=None, timeout=GPG_TIMEOUT):

securesystemslib/_gpg/util.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,7 @@ def parse_packet_header(data, expected_type=None): # noqa: PLR0912
159159

160160
elif data[1] >= 224 and data[1] < 255:
161161
raise PacketParsingError(
162-
"New length "
163-
"format packets of partial body lengths are not supported"
162+
"New length format packets of partial body lengths are not supported"
164163
)
165164

166165
elif data[1] == 255:
@@ -193,8 +192,7 @@ def parse_packet_header(data, expected_type=None): # noqa: PLR0912
193192

194193
elif length_type == 3:
195194
raise PacketParsingError(
196-
"Old length "
197-
"format packets of indeterminate length are not supported"
195+
"Old length " "format packets of indeterminate length are not supported"
198196
)
199197

200198
else: # pragma: no cover (unreachable)

securesystemslib/signer/_aws_signer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def import_(
128128
129129
Arguments:
130130
aws_key_id (str): AWS KMS key ID.
131-
local_scheme (Optional[str]): The Secure Systems Library RSA or ECDSA scheme.
131+
local_scheme (Optional[str]): The Secure Systems Library RSA/ECDSA scheme.
132132
Defaults to 'rsassa-pss-sha256' if not provided and RSA.
133133
134134
Returns:

securesystemslib/signer/_azure_signer.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828
PublicFormat,
2929
)
3030
except ImportError:
31-
AZURE_IMPORT_ERROR = "Signing with Azure Key Vault requires azure-identity, azure-keyvault-keys and cryptography."
31+
AZURE_IMPORT_ERROR = (
32+
"Signing with Azure Key Vault requires azure-identity, "
33+
"azure-keyvault-keys and cryptography."
34+
)
3235

3336
logger = logging.getLogger(__name__)
3437

@@ -77,9 +80,7 @@ def __init__(self, az_key_uri: str, public_key: Key):
7780
)
7881
self.hash_algorithm = self._get_hash_algorithm(public_key)
7982
except UnsupportedKeyType as e:
80-
logger.info(
81-
"Key %s has unsupported key type or unsupported elliptic curve"
82-
)
83+
logger.info("Key %s has unsupported key type or unsupported elliptic curve")
8384
raise e
8485
self._public_key = public_key
8586

@@ -101,7 +102,8 @@ def _get_key_vault_key(
101102
return key_client.get_key(key_name)
102103
except (HttpResponseError,) as e:
103104
logger.info(
104-
"Key %s/%s failed to create key client from credentials, key ID, and Vault URL: %s",
105+
"Key %s/%s failed to create key client from credentials, "
106+
"key ID, and Vault URL: %s",
105107
vault_name,
106108
key_name,
107109
str(e),
@@ -118,7 +120,8 @@ def _create_crypto_client(
118120
return CryptographyClient(kv_key, credential=cred)
119121
except (HttpResponseError,) as e:
120122
logger.info(
121-
"Key %s failed to create crypto client from credentials and KeyVaultKey: %s",
123+
"Key %s failed to create crypto client from "
124+
"credentials and KeyVaultKey: %s",
122125
kv_key,
123126
str(e),
124127
)
@@ -198,14 +201,10 @@ def import_(cls, az_vault_name: str, az_key_name: str) -> Tuple[str, Key]:
198201
raise UnsupportedLibraryError(AZURE_IMPORT_ERROR)
199202

200203
credential = DefaultAzureCredential()
201-
key_vault_key = cls._get_key_vault_key(
202-
credential, az_vault_name, az_key_name
203-
)
204+
key_vault_key = cls._get_key_vault_key(credential, az_vault_name, az_key_name)
204205

205206
if not key_vault_key.key.kty.startswith("EC"):
206-
raise UnsupportedKeyType(
207-
f"Unsupported key type {key_vault_key.key.kty}"
208-
)
207+
raise UnsupportedKeyType(f"Unsupported key type {key_vault_key.key.kty}")
209208

210209
if key_vault_key.key.crv == KeyCurveName.p_256:
211210
crv: ec.EllipticCurve = ec.SECP256R1()
@@ -214,19 +213,15 @@ def import_(cls, az_vault_name: str, az_key_name: str) -> Tuple[str, Key]:
214213
elif key_vault_key.key.crv == KeyCurveName.p_521:
215214
crv = ec.SECP521R1()
216215
else:
217-
raise UnsupportedKeyType(
218-
f"Unsupported curve type {key_vault_key.key.crv}"
219-
)
216+
raise UnsupportedKeyType(f"Unsupported curve type {key_vault_key.key.crv}")
220217

221218
# Key is in JWK format, create a curve from it with the parameters
222219
x = int.from_bytes(key_vault_key.key.x, byteorder="big")
223220
y = int.from_bytes(key_vault_key.key.y, byteorder="big")
224221

225222
cpub = ec.EllipticCurvePublicNumbers(x, y, crv)
226223
pub_key = cpub.public_key()
227-
pem = pub_key.public_bytes(
228-
Encoding.PEM, PublicFormat.SubjectPublicKeyInfo
229-
)
224+
pem = pub_key.public_bytes(Encoding.PEM, PublicFormat.SubjectPublicKeyInfo)
230225

231226
keytype, scheme = cls._get_keytype_and_scheme(key_vault_key.key.crv)
232227
keyval = {"public": pem.decode("utf-8")}

securesystemslib/signer/_crypto_signer.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ def _get_hash_algorithm(name: str) -> "HashAlgorithm":
9292
return algorithm
9393

9494

95-
def _get_rsa_padding(
96-
name: str, hash_algorithm: "HashAlgorithm"
97-
) -> "AsymmetricPadding":
95+
def _get_rsa_padding(name: str, hash_algorithm: "HashAlgorithm") -> "AsymmetricPadding":
9896
"""Helper to return rsa signature padding for name."""
9997
padding: AsymmetricPadding
10098
if name == "pss":
@@ -279,9 +277,7 @@ def generate_ed25519(
279277
raise UnsupportedLibraryError(CRYPTO_IMPORT_ERROR)
280278

281279
private_key = Ed25519PrivateKey.generate()
282-
public_key = SSlibKey.from_crypto(
283-
private_key.public_key(), keyid, "ed25519"
284-
)
280+
public_key = SSlibKey.from_crypto(private_key.public_key(), keyid, "ed25519")
285281
return CryptoSigner(private_key, public_key)
286282

287283
@staticmethod
@@ -310,9 +306,7 @@ def generate_rsa(
310306
public_exponent=65537,
311307
key_size=size,
312308
)
313-
public_key = SSlibKey.from_crypto(
314-
private_key.public_key(), keyid, scheme
315-
)
309+
public_key = SSlibKey.from_crypto(private_key.public_key(), keyid, scheme)
316310
return CryptoSigner(private_key, public_key)
317311

318312
@staticmethod

securesystemslib/signer/_gpg_signer.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,7 @@ def _key_from_legacy_dict(key_dict: Dict[str, Any]) -> GPGKey:
147147
return GPGKey(keyid, keytype, scheme, keyval)
148148

149149
@classmethod
150-
def import_(
151-
cls, keyid: str, homedir: Optional[str] = None
152-
) -> Tuple[str, Key]:
150+
def import_(cls, keyid: str, homedir: Optional[str] = None) -> Tuple[str, Key]:
153151
"""Load key and signer details from GnuPG keyring.
154152
155153
NOTE: Information about the key validity (expiration, revocation, etc.)
@@ -189,8 +187,7 @@ def import_(
189187

190188
else:
191189
raise ValueError(
192-
f"No exact match found for passed keyid"
193-
f" {keyid}, found: {keyids}."
190+
f"No exact match found for passed keyid {keyid}, found: {keyids}."
194191
)
195192

196193
return (uri, public_key)
@@ -214,9 +211,7 @@ def sign(self, payload: bytes) -> Signature:
214211
215212
"""
216213
try:
217-
raw_sig = gpg.create_signature(
218-
payload, self.public_key.keyid, self.homedir
219-
)
214+
raw_sig = gpg.create_signature(payload, self.public_key.keyid, self.homedir)
220215
except gpg_exceptions.KeyNotFoundError as e:
221216
raise ValueError(e) from e
222217

0 commit comments

Comments
 (0)