コード例 #1
0
ファイル: test_cosekey.py プロジェクト: mpzaborski/pycose
def test_symmetric_mac(kid, alg, key_ops, base_iv, k, pl, algo, ct):
    key = SymmetricKey(kid=kid, alg=alg, key_ops=key_ops, base_iv=base_iv, k=k)

    assert ct == key.compute_tag(pl, algo)

    # switch to another key operation
    key.key_ops = KeyOps.MAC_VERIFY
    assert key.verify_tag(ct, pl, algo)
コード例 #2
0
ファイル: maccommon.py プロジェクト: mpzaborski/pycose
    def verify_tag(self,
                   key: SymmetricKey,
                   alg: Optional[CoseAlgorithms] = None) -> bool:
        """ Verifies the authentication tag of a received message. """

        if not isinstance(key, SymmetricKey):
            raise CoseIllegalKeyType(
                "COSE key should be of type 'SymmetricKey', got {}".format(
                    type(key)))

        return key.verify_tag(self.auth_tag, self._mac_structure, alg)