コード例 #1
0
def test_exact_data_with_data_inverse():
    """The data entered is the data returned. The storing data is the exact length needed."""
    test_string = "This is a test String"
    test_data = bytes(test_string, 'utf-8')
    stegs = Steganographer()
    stegs._header.data_len = len(test_string)
    blank_data = bytes(b'\x01' * len(test_string) * stegs._BYTELEN)

    revealed_data = stegs._reveal_data(stegs._hide_data(blank_data, test_data))

    assert test_data == revealed_data
コード例 #2
0
def test_hide_reveal_data_inverse(string_to_hide):
    """Anything hidden by _hide_data is revealed by _reveal_data."""
    clean_data = bytes(b'\x01' * 5000)
    data_to_hide = bytes(string_to_hide, 'utf-8')

    stegs = Steganographer()
    stegs._header.data_len = len(string_to_hide.encode('utf-8'))
    revealed_data = stegs._reveal_data(
        stegs._hide_data(clean_data, data_to_hide))

    assert revealed_data == data_to_hide
コード例 #3
0
def test_short_data_with_data_inverse():
    """When the data is too small, by a full byte, everything that can be returned is returned."""
    test_string = "This is a test String"
    test_data = bytes(test_string, 'utf-8')
    stegs = Steganographer()
    stegs._header.data_len = len(test_string)
    blank_data = bytes(b'\x01' *
                       (len(test_string) * stegs._BYTELEN - stegs._BYTELEN))

    revealed_data = stegs._reveal_data(stegs._hide_data(blank_data, test_data))

    assert test_data[:-1] == revealed_data
コード例 #4
0
def test_short_partial_data_w_data_inverse():
    """When the data is too small, by a half byte, everything that can be returned is returned."""
    test_string = "This is a test String"
    test_data = bytes(test_string, 'utf-8')
    solution_data = bytearray(test_data)
    stegs = Steganographer()
    stegs._header.data_len = len(test_string)
    solution_data[
        -1] = solution_data[-1] >> stegs._BYTELEN // 2 << stegs._BYTELEN // 2
    blank_data = bytes(
        b'\x01' * (len(test_string) * stegs._BYTELEN - stegs._BYTELEN // 2))

    revealed_data = stegs._reveal_data(stegs._hide_data(blank_data, test_data))

    assert solution_data == revealed_data
コード例 #5
0
def test_reveal_data():
    """Will return the correct data that is hidden inside the test_data."""
    solution_data = bytes('ABC', 'utf-8')
    stegs = Steganographer()
    stegs._header.data_len = len(solution_data)
    test_data = bytearray(stegs._BYTELEN * 3)
    test_data[1] = 1
    test_data[7] = 1
    test_data[9] = 1
    test_data[14] = 1
    test_data[17] = 1
    test_data[22] = 1
    test_data[23] = 1

    assert stegs._reveal_data(test_data) == solution_data
コード例 #6
0
def test_reveal_data_partial():
    """
    Will return as much data as possible.

    When the container bytes object passed in is too small for all the data to be hidden.
    """
    stegs = Steganographer()
    solution_data = bytes('AB@', 'utf-8')
    test_data = bytearray(
        stegs._BYTELEN * 3
    )  # Will contain 'ABC' but will be truncated when passed to _reveal_data
    test_data[1] = 1
    test_data[7] = 1
    test_data[9] = 1
    test_data[14] = 1
    test_data[17] = 1
    test_data[22] = 1
    test_data[23] = 1
    stegs._data_len = len('ABC')

    assert stegs._reveal_data(test_data[:-stegs._BYTELEN //
                                        2]) == solution_data