checkMac method

Future<void> checkMac({
  1. required MacAlgorithm macAlgorithm,
  2. required SecretKey secretKey,
  3. required List<int> aad,
})

Checks that the secret box has correct MAC.

Throws SecretBoxAuthenticationError if the MAC is incorrect.

Implementation

Future<void> checkMac({
  required MacAlgorithm macAlgorithm,
  required SecretKey secretKey,
  required List<int> aad,
}) async {
  final correctMac = await macAlgorithm.calculateMac(
    cipherText,
    secretKey: secretKey,
    nonce: nonce,
    aad: aad,
  );
  if (correctMac != mac) {
    throw SecretBoxAuthenticationError();
  }
}