2022-11-10 08:32:21 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2023-04-26 23:50:37 +03:00
|
|
|
#include <stddef.h>
|
2022-11-10 08:32:21 +03:00
|
|
|
|
2022-11-24 01:19:19 +03:00
|
|
|
typedef uint8_t TotpRollValueOverflowBehavior;
|
|
|
|
|
|
|
|
enum TotpRollValueOverflowBehaviors {
|
2022-11-17 22:33:31 +03:00
|
|
|
/**
|
|
|
|
* @brief Do not change value if it reached constraint
|
|
|
|
*/
|
|
|
|
RollOverflowBehaviorStop,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set value to opposite constraint value if it reached constraint
|
|
|
|
*/
|
|
|
|
RollOverflowBehaviorRoll
|
2022-11-24 01:19:19 +03:00
|
|
|
};
|
2022-11-10 08:32:21 +03:00
|
|
|
|
|
|
|
#define TOTP_ROLL_VALUE_FN_HEADER(type, step_type) \
|
|
|
|
void totp_roll_value_##type( \
|
|
|
|
type* value, \
|
|
|
|
step_type step, \
|
|
|
|
type min, \
|
|
|
|
type max, \
|
|
|
|
TotpRollValueOverflowBehavior overflow_behavior)
|
|
|
|
|
2022-11-17 22:33:31 +03:00
|
|
|
/**
|
|
|
|
* @brief Rolls \c int8_t \p value using \p min and \p max as an value constraints with \p step step.
|
|
|
|
* When value reaches constraint value \p overflow_behavior defines what to do next.
|
|
|
|
* @param[in,out] value value to roll
|
|
|
|
* @param step step to be used to change value
|
|
|
|
* @param min minimal possible value
|
|
|
|
* @param max maximum possible value
|
|
|
|
* @param overflow_behavior defines what to do when value reaches constraint value
|
|
|
|
*/
|
2022-11-10 08:32:21 +03:00
|
|
|
TOTP_ROLL_VALUE_FN_HEADER(int8_t, int8_t);
|
2022-11-17 22:33:31 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Rolls \c uint8_t \p value using \p min and \p max as an value constraints with \p step step.
|
|
|
|
* When value reaches constraint value \p overflow_behavior defines what to do next.
|
|
|
|
* @param[in,out] value value to roll
|
|
|
|
* @param step step to be used to change value
|
|
|
|
* @param min minimal possible value
|
|
|
|
* @param max maximum possible value
|
|
|
|
* @param overflow_behavior defines what to do when value reaches constraint value
|
|
|
|
*/
|
2022-11-10 08:32:21 +03:00
|
|
|
TOTP_ROLL_VALUE_FN_HEADER(uint8_t, int8_t);
|
2022-11-17 22:33:31 +03:00
|
|
|
|
|
|
|
/**
|
2023-04-26 23:50:37 +03:00
|
|
|
* @brief Rolls \c size_t \p value using \p min and \p max as an value constraints with \p step step.
|
2022-11-17 22:33:31 +03:00
|
|
|
* When value reaches constraint value \p overflow_behavior defines what to do next.
|
|
|
|
* @param[in,out] value value to roll
|
|
|
|
* @param step step to be used to change value
|
|
|
|
* @param min minimal possible value
|
|
|
|
* @param max maximum possible value
|
|
|
|
* @param overflow_behavior defines what to do when value reaches constraint value
|
|
|
|
*/
|
2023-04-26 23:50:37 +03:00
|
|
|
TOTP_ROLL_VALUE_FN_HEADER(size_t, int16_t);
|