Loading scripts/imgtool/keys/general.py +16 −1 Changes for scripts/imgtool/keys/general.py: 16 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -8,7 +8,18 @@ AUTOGEN_MESSAGE = "/* Autogenerated by imgtool.py, do not edit. */" class KeyClass(object): def _emit(self, header, trailer, encoded_bytes, indent, file=sys.stdout, len_format=None): def _emit(self, header, trailer, encoded_bytes, indent, file=sys.stdout, len_format=None): if file and file is not sys.stdout: with open(file, 'w') as file: self._emit_to_output(header, trailer, encoded_bytes, indent, file, len_format) else: self._emit_to_output(header, trailer, encoded_bytes, indent, sys.stdout, len_format) def _emit_to_output(self, header, trailer, encoded_bytes, indent, file, len_format): print(AUTOGEN_MESSAGE, file=file) print(header, end='', file=file) for count, b in enumerate(encoded_bytes): Loading Loading @@ -39,7 +50,11 @@ class KeyClass(object): file=file) def emit_public_pem(self, file=sys.stdout): if file and file is not sys.stdout: with open(file, 'w') as file: print(str(self.get_public_pem(), 'utf-8'), file=file, end='') else: print(str(self.get_public_pem(), 'utf-8'), file=sys.stdout, end='') def emit_private(self, minimal, format, file=sys.stdout): self._emit( Loading scripts/imgtool/main.py +10 −4 Changes for scripts/imgtool/main.py: 10 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -128,8 +128,11 @@ def keygen(type, key, password): type=click.Choice(valid_encodings), help='Valid encodings: {}'.format(', '.join(valid_encodings))) @click.option('-k', '--key', metavar='filename', required=True) @click.option('-o', '--output', metavar='output', required=False, help='Specify the output file\'s name. \ The stdout is used if it is not provided.') @click.command(help='Dump public key from keypair') def getpub(key, encoding, lang): def getpub(key, encoding, lang, output): if encoding and lang: raise click.UsageError('Please use only one of `--encoding/-e` ' 'or `--lang/-l`') Loading @@ -138,14 +141,17 @@ def getpub(key, encoding, lang): # `default=valid_encodings[0]` should be added to `-e` param. lang = valid_langs[0] key = load_key(key) if not output: output = sys.stdout if key is None: print("Invalid passphrase") elif lang == 'c' or encoding == 'lang-c': key.emit_c_public() key.emit_c_public(file=output) elif lang == 'rust' or encoding == 'lang-rust': key.emit_rust_public() key.emit_rust_public(file=output) elif encoding == 'pem': key.emit_public_pem() key.emit_public_pem(file=output) else: raise click.UsageError() Loading Loading
scripts/imgtool/keys/general.py +16 −1 Changes for scripts/imgtool/keys/general.py: 16 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -8,7 +8,18 @@ AUTOGEN_MESSAGE = "/* Autogenerated by imgtool.py, do not edit. */" class KeyClass(object): def _emit(self, header, trailer, encoded_bytes, indent, file=sys.stdout, len_format=None): def _emit(self, header, trailer, encoded_bytes, indent, file=sys.stdout, len_format=None): if file and file is not sys.stdout: with open(file, 'w') as file: self._emit_to_output(header, trailer, encoded_bytes, indent, file, len_format) else: self._emit_to_output(header, trailer, encoded_bytes, indent, sys.stdout, len_format) def _emit_to_output(self, header, trailer, encoded_bytes, indent, file, len_format): print(AUTOGEN_MESSAGE, file=file) print(header, end='', file=file) for count, b in enumerate(encoded_bytes): Loading Loading @@ -39,7 +50,11 @@ class KeyClass(object): file=file) def emit_public_pem(self, file=sys.stdout): if file and file is not sys.stdout: with open(file, 'w') as file: print(str(self.get_public_pem(), 'utf-8'), file=file, end='') else: print(str(self.get_public_pem(), 'utf-8'), file=sys.stdout, end='') def emit_private(self, minimal, format, file=sys.stdout): self._emit( Loading
scripts/imgtool/main.py +10 −4 Changes for scripts/imgtool/main.py: 10 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -128,8 +128,11 @@ def keygen(type, key, password): type=click.Choice(valid_encodings), help='Valid encodings: {}'.format(', '.join(valid_encodings))) @click.option('-k', '--key', metavar='filename', required=True) @click.option('-o', '--output', metavar='output', required=False, help='Specify the output file\'s name. \ The stdout is used if it is not provided.') @click.command(help='Dump public key from keypair') def getpub(key, encoding, lang): def getpub(key, encoding, lang, output): if encoding and lang: raise click.UsageError('Please use only one of `--encoding/-e` ' 'or `--lang/-l`') Loading @@ -138,14 +141,17 @@ def getpub(key, encoding, lang): # `default=valid_encodings[0]` should be added to `-e` param. lang = valid_langs[0] key = load_key(key) if not output: output = sys.stdout if key is None: print("Invalid passphrase") elif lang == 'c' or encoding == 'lang-c': key.emit_c_public() key.emit_c_public(file=output) elif lang == 'rust' or encoding == 'lang-rust': key.emit_rust_public() key.emit_rust_public(file=output) elif encoding == 'pem': key.emit_public_pem() key.emit_public_pem(file=output) else: raise click.UsageError() Loading