Skip to content

Commit

Permalink
imgtool: fixed keys/general.py to pass existing unittests
Browse files Browse the repository at this point in the history
keys.KeyClass._emit is able to use 'file' parameter not as a file
but some object (not only sys.stdout but io.StringIO, like by
tests).

Signed-off-by: Denis Mingulov <denis@mingulov.com>
  • Loading branch information
mingulov committed Sep 26, 2023
1 parent 9213346 commit 9aa872d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions scripts/imgtool/keys/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# SPDX-License-Identifier: Apache-2.0

import io
import sys
from cryptography.hazmat.primitives.hashes import Hash, SHA256

Expand All @@ -11,13 +12,13 @@
class KeyClass(object):
def _emit(self, header, trailer, encoded_bytes, indent, file=sys.stdout,
len_format=None):
if file and file is not sys.stdout:
if file and not isinstance(file, io.TextIOBase):
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)
file, len_format)

def _emit_to_output(self, header, trailer, encoded_bytes, indent, file,
len_format):
Expand Down

0 comments on commit 9aa872d

Please sign in to comment.