本文整理汇总了Python中cryptography.hazmat.primitives.cmac.CMAC.update方法的典型用法代码示例。如果您正苦于以下问题:Python CMAC.update方法的具体用法?Python CMAC.update怎么用?Python CMAC.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cryptography.hazmat.primitives.cmac.CMAC
的用法示例。
在下文中一共展示了CMAC.update方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_invalid_verify
# 需要导入模块: from cryptography.hazmat.primitives.cmac import CMAC [as 别名]
# 或者: from cryptography.hazmat.primitives.cmac.CMAC import update [as 别名]
def test_invalid_verify(self, backend):
key = b"2b7e151628aed2a6abf7158809cf4f3c"
cmac = CMAC(AES(key), backend)
cmac.update(b"6bc1bee22e409f96e93d7e117393172a")
with pytest.raises(InvalidSignature):
cmac.verify(b"foobar")
示例2: test_aes_verify
# 需要导入模块: from cryptography.hazmat.primitives.cmac import CMAC [as 别名]
# 或者: from cryptography.hazmat.primitives.cmac.CMAC import update [as 别名]
def test_aes_verify(self, backend, params):
key = params["key"]
message = params["message"]
output = params["output"]
cmac = CMAC(AES(binascii.unhexlify(key)), backend)
cmac.update(binascii.unhexlify(message))
assert cmac.verify(binascii.unhexlify(output)) is None
示例3: test_aes_generate
# 需要导入模块: from cryptography.hazmat.primitives.cmac import CMAC [as 别名]
# 或者: from cryptography.hazmat.primitives.cmac.CMAC import update [as 别名]
def test_aes_generate(self, backend, params):
key = params["key"]
message = params["message"]
output = params["output"]
cmac = CMAC(AES(binascii.unhexlify(key)), backend)
cmac.update(binascii.unhexlify(message))
assert binascii.hexlify(cmac.finalize()) == output
示例4: test_verify_reject_unicode
# 需要导入模块: from cryptography.hazmat.primitives.cmac import CMAC [as 别名]
# 或者: from cryptography.hazmat.primitives.cmac.CMAC import update [as 别名]
def test_verify_reject_unicode(self, backend):
key = b"2b7e151628aed2a6abf7158809cf4f3c"
cmac = CMAC(AES(key), backend)
with pytest.raises(TypeError):
cmac.update(six.u(''))
with pytest.raises(TypeError):
cmac.verify(six.u(''))
示例5: test_3des_generate
# 需要导入模块: from cryptography.hazmat.primitives.cmac import CMAC [as 别名]
# 或者: from cryptography.hazmat.primitives.cmac.CMAC import update [as 别名]
def test_3des_generate(self, backend, params):
key1 = params["key1"]
key2 = params["key2"]
key3 = params["key3"]
key = key1 + key2 + key3
message = params["message"]
output = params["output"]
cmac = CMAC(TripleDES(binascii.unhexlify(key)), backend)
cmac.update(binascii.unhexlify(message))
assert binascii.hexlify(cmac.finalize()) == output
示例6: test_3des_verify
# 需要导入模块: from cryptography.hazmat.primitives.cmac import CMAC [as 别名]
# 或者: from cryptography.hazmat.primitives.cmac.CMAC import update [as 别名]
def test_3des_verify(self, backend, params):
key1 = params["key1"]
key2 = params["key2"]
key3 = params["key3"]
key = key1 + key2 + key3
message = params["message"]
output = params["output"]
cmac = CMAC(TripleDES(binascii.unhexlify(key)), backend)
cmac.update(binascii.unhexlify(message))
assert cmac.verify(binascii.unhexlify(output)) is None
示例7: test_raises_after_finalize
# 需要导入模块: from cryptography.hazmat.primitives.cmac import CMAC [as 别名]
# 或者: from cryptography.hazmat.primitives.cmac.CMAC import update [as 别名]
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()
示例8: test_aes_cmac
# 需要导入模块: from cryptography.hazmat.primitives.cmac import CMAC [as 别名]
# 或者: from cryptography.hazmat.primitives.cmac.CMAC import update [as 别名]
def test_aes_cmac(backend, wycheproof):
key = binascii.unhexlify(wycheproof.testcase["key"])
msg = binascii.unhexlify(wycheproof.testcase["msg"])
tag = binascii.unhexlify(wycheproof.testcase["tag"])
# skip truncated tags, which we don't support in the API
if wycheproof.valid and len(tag) == 16:
ctx = CMAC(AES(key), backend)
ctx.update(msg)
ctx.verify(tag)
elif len(key) not in [16, 24, 32]:
with pytest.raises(ValueError):
CMAC(AES(key), backend)
else:
ctx = CMAC(AES(key), backend)
ctx.update(msg)
with pytest.raises(InvalidSignature):
ctx.verify(tag)
示例9: test_copy_with_backend
# 需要导入模块: from cryptography.hazmat.primitives.cmac import CMAC [as 别名]
# 或者: from cryptography.hazmat.primitives.cmac.CMAC import update [as 别名]
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()