imgtool: fixed keys/general.py to pass existing unittests

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).

Fixed all explicit checks for sys.stdio usage in favor of
io.TextIOBase, also improve a single unit test to cover
also all the changed methods.

Signed-off-by: Denis Mingulov <denis@mingulov.com>
diff --git a/scripts/imgtool/keys/rsa_test.py b/scripts/imgtool/keys/rsa_test.py
index 4b2106a..7610106 100644
--- a/scripts/imgtool/keys/rsa_test.py
+++ b/scripts/imgtool/keys/rsa_test.py
@@ -63,15 +63,34 @@
         for key_size in RSA_KEY_SIZES:
             k = RSA.generate(key_size=key_size)
 
+            pubpem = io.StringIO()
+            k.emit_public_pem(pubpem)
+            self.assertIn("BEGIN PUBLIC KEY", pubpem.getvalue())
+            self.assertIn("END PUBLIC KEY", pubpem.getvalue())
+
             ccode = io.StringIO()
             k.emit_c_public(ccode)
             self.assertIn("rsa_pub_key", ccode.getvalue())
             self.assertIn("rsa_pub_key_len", ccode.getvalue())
 
+            hashccode = io.StringIO()
+            k.emit_c_public_hash(hashccode)
+            self.assertIn("rsa_pub_key_hash", hashccode.getvalue())
+            self.assertIn("rsa_pub_key_hash_len", hashccode.getvalue())
+
             rustcode = io.StringIO()
             k.emit_rust_public(rustcode)
             self.assertIn("RSA_PUB_KEY", rustcode.getvalue())
 
+            # raw data - bytes
+            pubraw = io.BytesIO()
+            k.emit_raw_public(pubraw)
+            self.assertTrue(len(pubraw.getvalue()) > 0)
+
+            hashraw = io.BytesIO()
+            k.emit_raw_public_hash(hashraw)
+            self.assertTrue(len(hashraw.getvalue()) > 0)
+
     def test_emit_pub(self):
         """Basic sanity check on the code emitters, from public key."""
         pubname = self.tname("public.pem")