Beispiel #1
0
    def test_raises_after_finalize(self, backend):
        key = b"2b7e151628aed2a6abf7158809cf4f3c"
        cmac = CMAC(AES(key), backend)
        cmac.finalize()

        with pytest.raises(AlreadyFinalized):
            cmac.update(b"foo")

        with pytest.raises(AlreadyFinalized):
            cmac.copy()

        with pytest.raises(AlreadyFinalized):
            cmac.finalize()
Beispiel #2
0
    def test_raises_after_finalize(self, backend):
        key = b"2b7e151628aed2a6abf7158809cf4f3c"
        cmac = CMAC(AES(key), backend)
        cmac.finalize()

        with pytest.raises(AlreadyFinalized):
            cmac.update(b"foo")

        with pytest.raises(AlreadyFinalized):
            cmac.copy()

        with pytest.raises(AlreadyFinalized):
            cmac.finalize()
Beispiel #3
0
def test_copy():
    backend = DummyCMACBackend([AES])
    copied_ctx = pretend.stub()
    pretend_ctx = pretend.stub(copy=lambda: copied_ctx)
    key = b"2b7e151628aed2a6abf7158809cf4f3c"
    cmac = CMAC(AES(key), backend=backend, ctx=pretend_ctx)

    assert cmac._backend is backend
    assert cmac.copy()._backend is backend
def test_copy():
    backend = DummyCMACBackend([AES])
    copied_ctx = pretend.stub()
    pretend_ctx = pretend.stub(copy=lambda: copied_ctx)
    key = b"2b7e151628aed2a6abf7158809cf4f3c"
    cmac = CMAC(AES(key), backend=backend, ctx=pretend_ctx)

    assert cmac._backend is backend
    assert cmac.copy()._backend is backend
Beispiel #5
0
def test_copy():
    @utils.register_interface(CMACBackend)
    class PretendBackend(object):
        pass

    pretend_backend = PretendBackend()
    copied_ctx = pretend.stub()
    pretend_ctx = pretend.stub(copy=lambda: copied_ctx)
    key = b"2b7e151628aed2a6abf7158809cf4f3c"
    cmac = CMAC(AES(key), backend=pretend_backend, ctx=pretend_ctx)

    assert cmac._backend is pretend_backend
    assert cmac.copy()._backend is pretend_backend
Beispiel #6
0
def test_copy():
    @utils.register_interface(CMACBackend)
    class PretendBackend(object):
        pass

    pretend_backend = PretendBackend()
    copied_ctx = pretend.stub()
    pretend_ctx = pretend.stub(copy=lambda: copied_ctx)
    key = b"2b7e151628aed2a6abf7158809cf4f3c"
    cmac = CMAC(AES(key), backend=pretend_backend, ctx=pretend_ctx)

    assert cmac._backend is pretend_backend
    assert cmac.copy()._backend is pretend_backend
Beispiel #7
0
 def test_copy_with_backend(self, backend):
     key = b"2b7e151628aed2a6abf7158809cf4f3c"
     cmac = CMAC(AES(key), backend)
     cmac.update(b"6bc1bee22e409f96e93d7e117393172a")
     copy_cmac = cmac.copy()
     assert cmac.finalize() == copy_cmac.finalize()
Beispiel #8
0
 def test_copy_with_backend(self, backend):
     key = b"2b7e151628aed2a6abf7158809cf4f3c"
     cmac = CMAC(AES(key), backend)
     cmac.update(b"6bc1bee22e409f96e93d7e117393172a")
     copy_cmac = cmac.copy()
     assert cmac.finalize() == copy_cmac.finalize()