mirror of
https://github.com/cedricbonhomme/Stegano.git
synced 2025-05-12 17:18:30 +02:00
chg: [flake] Addressed some flake and mypy issues.
This commit is contained in:
parent
fc53f2a6b9
commit
e290d1260e
6 changed files with 17 additions and 24 deletions
|
@ -6,3 +6,5 @@ from . import exifHeader
|
|||
from . import lsb
|
||||
|
||||
from . import steganalysis
|
||||
|
||||
__all__ = ["red", "exifHeader", "lsb", "steganalysis"]
|
||||
|
|
|
@ -183,8 +183,8 @@ class Revealer:
|
|||
self.encoded_image = open_image(encoded_image)
|
||||
self._encoding_length = ENCODINGS[encoding]
|
||||
self._buff, self._count = 0, 0
|
||||
self._bitab = []
|
||||
self._limit = None
|
||||
self._bitab: List[str] = []
|
||||
self._limit: Union[None, int] = None
|
||||
self.secret_message = ""
|
||||
|
||||
def decode_pixel(self, coordinate: tuple):
|
||||
|
@ -209,7 +209,7 @@ class Revealer:
|
|||
raise IndexError("Impossible to detect message.")
|
||||
|
||||
if len(self._bitab) - len(str(self._limit)) - 1 == self._limit:
|
||||
self.secret_message = "".join(self._bitab)[len(str(self._limit)) + 1 :]
|
||||
self.secret_message = "".join(self._bitab)[len(str(self._limit)) + 1:]
|
||||
self.encoded_image.close()
|
||||
|
||||
return True
|
||||
|
|
|
@ -35,10 +35,9 @@ from stegano import exifHeader
|
|||
class TestEXIFHeader(unittest.TestCase):
|
||||
def test_hide_empty_message(self):
|
||||
"""Test hiding the empty string."""
|
||||
secret = exifHeader.hide(
|
||||
exifHeader.hide(
|
||||
"./tests/sample-files/20160505T130442.jpg", "./image.jpg", secret_message=""
|
||||
)
|
||||
# secret.save(""./image.png"")
|
||||
|
||||
clear_message = exifHeader.reveal("./image.jpg")
|
||||
|
||||
|
@ -48,7 +47,7 @@ class TestEXIFHeader(unittest.TestCase):
|
|||
messages_to_hide = ["a", "foo", "Hello World!", ":Python:"]
|
||||
|
||||
for message in messages_to_hide:
|
||||
secret = exifHeader.hide(
|
||||
exifHeader.hide(
|
||||
"./tests/sample-files/20160505T130442.jpg",
|
||||
"./image.jpg",
|
||||
secret_message=message,
|
||||
|
@ -56,13 +55,12 @@ class TestEXIFHeader(unittest.TestCase):
|
|||
|
||||
clear_message = exifHeader.reveal("./image.jpg")
|
||||
|
||||
self.assertEqual(message, message)
|
||||
self.assertEqual(message, clear_message.decode())
|
||||
|
||||
def test_with_image_without_exif_data(self):
|
||||
secret = exifHeader.hide(
|
||||
exifHeader.hide(
|
||||
"./tests/sample-files/Lenna.jpg", "./image.jpg", secret_message=""
|
||||
)
|
||||
# secret.save(""./image.png"")
|
||||
|
||||
clear_message = exifHeader.reveal("./image.jpg")
|
||||
|
||||
|
@ -72,7 +70,7 @@ class TestEXIFHeader(unittest.TestCase):
|
|||
text_file_to_hide = "./tests/sample-files/lorem_ipsum.txt"
|
||||
with open(text_file_to_hide, "rb") as f:
|
||||
message = f.read()
|
||||
secret = exifHeader.hide(
|
||||
exifHeader.hide(
|
||||
"./tests/sample-files/20160505T130442.jpg",
|
||||
img_enc="./image.jpg",
|
||||
secret_file=text_file_to_hide,
|
||||
|
@ -82,13 +80,12 @@ class TestEXIFHeader(unittest.TestCase):
|
|||
self.assertEqual(message, clear_message)
|
||||
|
||||
def test_with_png_image(self):
|
||||
secret = exifHeader.hide(
|
||||
exifHeader.hide(
|
||||
"./tests/sample-files/Lenna.png", "./image.png", secret_message="Secret"
|
||||
)
|
||||
# secret.save(""./image.png"")
|
||||
|
||||
with self.assertRaises(ValueError):
|
||||
clear_message = exifHeader.reveal("./image.png")
|
||||
exifHeader.reveal("./image.png")
|
||||
|
||||
def test_with_bytes(self):
|
||||
outputBytes = io.BytesIO()
|
||||
|
@ -102,11 +99,11 @@ class TestEXIFHeader(unittest.TestCase):
|
|||
def tearDown(self):
|
||||
try:
|
||||
os.unlink("./image.jpg")
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
os.unlink("./image.png")
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ class TestRed(unittest.TestCase):
|
|||
Test hiding the empty string.
|
||||
"""
|
||||
with self.assertRaises(AssertionError):
|
||||
secret = red.hide("./tests/sample-files/Lenna.png", "")
|
||||
red.hide("./tests/sample-files/Lenna.png", "")
|
||||
|
||||
def test_hide_and_reveal(self):
|
||||
messages_to_hide = ["a", "foo", "Hello World!", ":Python:"]
|
||||
|
@ -47,7 +47,7 @@ class TestRed(unittest.TestCase):
|
|||
|
||||
clear_message = red.reveal("./image.png")
|
||||
|
||||
self.assertEqual(message, message)
|
||||
self.assertEqual(message, clear_message)
|
||||
|
||||
def test_with_too_long_message(self):
|
||||
with open("./tests/sample-files/lorem_ipsum.txt") as f:
|
||||
|
@ -58,7 +58,7 @@ class TestRed(unittest.TestCase):
|
|||
def tearDown(self):
|
||||
try:
|
||||
os.unlink("./image.png")
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
|
|
|
@ -25,11 +25,7 @@ __date__ = "$Date: 2019/06/06 $"
|
|||
__revision__ = "$Date: 2019/06/06 $"
|
||||
__license__ = "GPLv3"
|
||||
|
||||
import io
|
||||
import os
|
||||
import base64
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from stegano import lsb
|
||||
from stegano.steganalysis import parity, statistics
|
||||
|
|
|
@ -25,9 +25,7 @@ __date__ = "$Date: 2017/02/22 $"
|
|||
__revision__ = "$Date: 2017/02/22 $"
|
||||
__license__ = "GPLv3"
|
||||
|
||||
import os
|
||||
import unittest
|
||||
import io
|
||||
|
||||
from stegano import tools
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue