@@ -454,24 +454,21 @@ def format_keyval_to_metadata(keytype, scheme, key_value, private=False):
454
454
# key in the returned dictionary, ensure the private key is actually
455
455
# present in 'key_val' (a private key is optional for 'KEYVAL_SCHEMA'
456
456
# dicts).
457
- if "private" not in key_value : # pylint: disable=no-else-raise
457
+ if "private" not in key_value :
458
458
raise exceptions .FormatError (
459
- "The required private key"
460
- " is missing from: " + repr (key_value )
459
+ "The required private key is missing from: " + repr (key_value )
461
460
)
462
461
463
- else :
464
- return {"keytype" : keytype , "scheme" : scheme , "keyval" : key_value }
462
+ return {"keytype" : keytype , "scheme" : scheme , "keyval" : key_value }
465
463
466
- else :
467
- public_key_value = {"public" : key_value ["public" ]}
464
+ public_key_value = {"public" : key_value ["public" ]}
468
465
469
- return {
470
- "keytype" : keytype ,
471
- "scheme" : scheme ,
472
- "keyid_hash_algorithms" : settings .HASH_ALGORITHMS ,
473
- "keyval" : public_key_value ,
474
- }
466
+ return {
467
+ "keytype" : keytype ,
468
+ "scheme" : scheme ,
469
+ "keyid_hash_algorithms" : settings .HASH_ALGORITHMS ,
470
+ "keyval" : public_key_value ,
471
+ }
475
472
476
473
477
474
def format_metadata_to_key (
@@ -830,15 +827,14 @@ def verify_signature(
830
827
831
828
# Verify that the KEYID in 'key_dict' matches the KEYID listed in the
832
829
# 'signature'.
833
- if key_dict ["keyid" ] != signature ["keyid" ]: # pylint: disable=no-else-raise
830
+ if key_dict ["keyid" ] != signature ["keyid" ]:
834
831
raise exceptions .CryptoError (
835
832
"The KEYID ("
836
833
" " + repr (key_dict ["keyid" ]) + " ) in the given key does not match"
837
834
" the KEYID ( " + repr (signature ["keyid" ]) + " ) in the signature."
838
835
)
839
836
840
- else :
841
- logger .debug ("The KEYIDs of key_dict and the signature match." )
837
+ logger .debug ("The KEYIDs of key_dict and the signature match." )
842
838
843
839
# Using the public key belonging to 'key_dict'
844
840
# (i.e., rsakey_dict['keyval']['public']), verify whether 'signature'
@@ -1235,42 +1231,40 @@ def extract_pem(pem, private_pem=False):
1235
1231
1236
1232
except ValueError :
1237
1233
# Be careful not to print private key material in exception message.
1238
- if not private_pem : # pylint: disable=no-else-raise
1239
- raise exceptions .FormatError ( # pylint: disable=raise-missing-from
1240
- "Required PEM"
1241
- " header " + repr (pem_header ) + "\n not found in PEM"
1242
- " string: " + repr (pem )
1243
- )
1244
-
1245
- else :
1234
+ if not private_pem :
1246
1235
raise exceptions .FormatError ( # pylint: disable=raise-missing-from
1247
- "Required PEM"
1248
- " header "
1236
+ "Required PEM header "
1249
1237
+ repr (pem_header )
1250
- + "\n not found in private PEM string."
1238
+ + "\n not found in PEM string: "
1239
+ + repr (pem )
1251
1240
)
1252
1241
1242
+ raise exceptions .FormatError ( # pylint: disable=raise-missing-from
1243
+ "Required PEM header "
1244
+ + repr (pem_header )
1245
+ + "\n not found in private PEM string."
1246
+ )
1247
+
1253
1248
try :
1254
1249
# Search for 'pem_footer' after the PEM header.
1255
1250
footer_start = pem .index (pem_footer , header_start + len (pem_header ))
1256
1251
1257
1252
except ValueError :
1258
1253
# Be careful not to print private key material in exception message.
1259
- if not private_pem : # pylint: disable=no-else-raise
1254
+ if not private_pem :
1260
1255
raise exceptions .FormatError ( # pylint: disable=raise-missing-from
1261
- "Required PEM"
1262
- " footer " + repr (pem_footer ) + "\n not found in PEM"
1263
- " string " + repr (pem )
1264
- )
1265
-
1266
- else :
1267
- raise exceptions .FormatError ( # pylint: disable=raise-missing-from
1268
- "Required PEM"
1269
- " footer "
1256
+ "Required PEM footer "
1270
1257
+ repr (pem_footer )
1271
- + "\n not found in private PEM string."
1258
+ + "\n not found in PEM string "
1259
+ + repr (pem )
1272
1260
)
1273
1261
1262
+ raise exceptions .FormatError ( # pylint: disable=raise-missing-from
1263
+ "Required PEM footer "
1264
+ + repr (pem_footer )
1265
+ + "\n not found in private PEM string."
1266
+ )
1267
+
1274
1268
# Extract only the public portion of 'pem'. Leading or trailing whitespace
1275
1269
# is excluded.
1276
1270
pem = pem [header_start : footer_start + len (pem_footer )]
0 commit comments