Skip to content

is_mac_valid#

The is_mac_valid() function checks if a provided message with MAC (Message Authentication Code) is valid.

Syntax#

is_mac_valid(secret, message_mac, ttl, timestamp, separator_len)

Parameters#

  • secret: The secret key used for MAC generation (bytes, literal)
  • message_mac: The message with MAC to validate (bytes, field/expression)
  • ttl: Time-to-live in seconds (int, literal)
  • timestamp: UNIX timestamp (int, typically http.request.timestamp.sec)
  • separator_len: Length of the separator between message and MAC (int, optional, defaults to 0)

Return Value#

Returns a boolean value: true if the MAC is valid, false otherwise.

Example#

is_mac_valid(
  "secret_key",
  http.request.uri,
  3600,
  http.request.timestamp.sec,
  5
)

Use Cases#

  • Validating signed URLs
  • Authenticating API requests
  • Ensuring message integrity in communication protocols