imgtool: Fix PEP8 warnings on modules in this PR
Fix the remaining PEP8 warnings that appear on image.py, ecdsa.py
or main.py for imgtool.
Signed-off-by: Antonio de Angelis <Antonio.deAngelis@arm.com>
diff --git a/scripts/imgtool/keys/ecdsa.py b/scripts/imgtool/keys/ecdsa.py
index 0433beb..79e4bb8 100644
--- a/scripts/imgtool/keys/ecdsa.py
+++ b/scripts/imgtool/keys/ecdsa.py
@@ -12,9 +12,11 @@
from .general import KeyClass
+
class ECDSAUsageError(Exception):
pass
+
class ECDSA256P1Public(KeyClass):
def __init__(self, key):
self.key = key
@@ -160,7 +162,8 @@
return priv
def export_private(self, path, passwd=None):
- """Write the private key to the given file, protecting it with the optional password."""
+ """Write the private key to the given file, protecting it with '
+ 'the optional password."""
if passwd is None:
enc = serialization.NoEncryption()
else:
diff --git a/scripts/imgtool/main.py b/scripts/imgtool/main.py
old mode 100644
new mode 100755
index e43eaf1..e485a1a
--- a/scripts/imgtool/main.py
+++ b/scripts/imgtool/main.py
@@ -71,16 +71,19 @@
}
valid_formats = ['openssl', 'pkcs8']
+
def load_signature(sigfile):
with open(sigfile, 'rb') as f:
signature = base64.b64decode(f.read())
return signature
+
def save_signature(sigfile, sig):
with open(sigfile, 'wb') as f:
signature = base64.b64encode(sig)
f.write(signature)
+
def load_key(keyfile):
# TODO: better handling of invalid pass-phrase
key = keys.load(keyfile)
@@ -127,7 +130,8 @@
@click.command(help='Dump public key from keypair')
def getpub(key, encoding, lang):
if encoding and lang:
- raise click.UsageError('Please use only one of `--encoding/-e` or `--lang/-l`')
+ raise click.UsageError('Please use only one of `--encoding/-e` '
+ 'or `--lang/-l`')
elif not encoding and not lang:
# Preserve old behavior defaulting to `c`. If `lang` is removed,
# `default=valid_encodings[0]` should be added to `-e` param.
@@ -281,7 +285,7 @@
help='Encrypt image using the provided public key. '
'(Not supported in direct-xip or ram-load mode.)')
@click.option('--encrypt-keylen', default='128',
- type=click.Choice(['128','256']),
+ type=click.Choice(['128', '256']),
help='When encrypting the image using AES, select a 128 bit or '
'256 bit key len.')
@click.option('-c', '--clear', required=False, is_flag=True, default=False,
@@ -342,8 +346,8 @@
help='Path to the file to which signature will be written. '
'The image signature will be encoded as base64 formatted string')
@click.option('--vector-to-sign', type=click.Choice(['payload', 'digest']),
- help='send to OUTFILE the payload or payload''s digest instead of '
- 'complied image. These data can be used for external image '
+ help='send to OUTFILE the payload or payload''s digest instead '
+ 'of complied image. These data can be used for external image '
'signing')
@click.command(help='''Create a signed or unsigned image\n
INFILE and OUTFILE are parsed as Intel HEX if the params have
@@ -407,18 +411,18 @@
if raw_signature is not None:
if fix_sig_pubkey is None:
- raise click.UsageError(
+ raise click.UsageError(
'public key of the fixed signature is not specified')
pub_key = load_key(fix_sig_pubkey)
baked_signature = {
- 'value' : raw_signature
+ 'value': raw_signature
}
img.create(key, public_key_format, enckey, dependencies, boot_record,
- custom_tlvs, int(encrypt_keylen), clear, baked_signature, pub_key,
- vector_to_sign)
+ custom_tlvs, int(encrypt_keylen), clear, baked_signature,
+ pub_key, vector_to_sign)
img.save(outfile, hex_addr)
if sig_out is not None: