Example #1
0
 def test_truncated(self):
     b = BytesIO(
         b"BM000000000000"  # head_data
         + _binary.o32le(
             ImageFile.SAFEBLOCK + 1 + 4
         )  # header_size, so BmpImagePlugin will try to read SAFEBLOCK + 1 bytes
         + (b"0" * ImageFile.SAFEBLOCK
            )  # only SAFEBLOCK bytes, so that the header is truncated
     )
     with pytest.raises(OSError) as e:
         BmpImagePlugin.BmpImageFile(b)
     assert str(e.value) == "Truncated File Read"
Example #2
0
 def test_invalid_file(self):
     with open("Tests/images/flower.jpg", "rb") as fp:
         self.assertRaises(SyntaxError,
                           lambda: BmpImagePlugin.BmpImageFile(fp))
Example #3
0
from cryptography.hazmat.backends import default_backend

backend = default_backend()

#Gerar chave aleatoria

key = os.urandom(32)
key

# initialization vector
iv = os.urandom(16)
iv

#Lendo e manipulando imagem de entrada em formato bmp:

input_image = BmpImagePlugin.BmpImageFile("teste.bmp")

image_data = input_image.tobytes()

# cifrando o dado com algoritmo AES no modo CBC:

# 1 - o objeto que criptografa AES com a chave gerada
aes = algorithms.AES(key)

# 2 - o  modo CBC em inicializaĆ§Ć£o
cbc = modes.CBC(iv)

# 3 - criando e encriptando a partir do cipher
cipher = Cipher(aes, cbc, backend=backend)
encryptor = cipher.encryptor()
ct = encryptor.update(image_data) + encryptor.finalize()
Example #4
0
def test_invalid_file():
    with open("Tests/images/flower.jpg", "rb") as fp:
        with pytest.raises(SyntaxError):
            BmpImagePlugin.BmpImageFile(fp)