Commit 7ba01c0d authored by Antonio de Angelis's avatar Antonio de Angelis Committed by Fabio Utzig
Browse files

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: default avatarAntonio de Angelis <Antonio.deAngelis@arm.com>
parent c6e7e9be
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -12,9 +12,11 @@ from cryptography.hazmat.primitives.hashes import SHA256

from .general import KeyClass


class ECDSAUsageError(Exception):
    pass


class ECDSA256P1Public(KeyClass):
    def __init__(self, key):
        self.key = key
@@ -160,7 +162,8 @@ class ECDSA256P1(ECDSA256P1Public):
        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:

scripts/imgtool/main.py

100644 → 100755
+12 −8
Original line number Diff line number Diff line
@@ -71,16 +71,19 @@ keygens = {
}
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 @@ def keygen(type, key, password):
@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.
@@ -342,8 +346,8 @@ class BasedIntParamType(click.ParamType):
              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
@@ -417,8 +421,8 @@ def sign(key, public_key_format, align, version, pad_sig, header_size,
        }

    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: