Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
akopachov committed Jul 11, 2023
1 parent 749fbf4 commit bf3952d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .ofwcatalog/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## [v2.2.3](https://github.com/akopachov/flipper-zero_authenticator/releases/tag/v2.2.3) - 19 Jun 2023
## [v2.2.3](https://github.com/akopachov/flipper-zero_authenticator/releases/tag/v2.2.3) - 10 Jul 2023

* Refactoring [#162](https://github.com/akopachov/flipper-zero_authenticator/issues/158)
* Updated repo to match [OFW catalog](https://github.com/flipperdevices/flipper-application-catalog/) requirements
Expand Down
5 changes: 1 addition & 4 deletions cli/cli_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ extern const char* TOTP_CLI_COLOR_INFO;
#define TOTP_CLI_PRINTF(format, ...) printf(format, ##__VA_ARGS__)

#define TOTP_CLI_PRINTF_COLORFUL(color, format, ...) \
printf("\e[%s", color); \
printf(format, ##__VA_ARGS__); \
printf("\e[0m"); \
fflush(stdout)
TOTP_CLI_PRINTF("\e[%s" format "\e[0m", color, ##__VA_ARGS__)

#define TOTP_CLI_PRINTF_ERROR(format, ...) \
TOTP_CLI_PRINTF_COLORFUL(TOTP_CLI_COLOR_ERROR, format, ##__VA_ARGS__)
Expand Down
4 changes: 2 additions & 2 deletions cli/commands/add/add.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void totp_cli_command_add_docopt_options() {
TOTP_CLI_PRINTF(" " DOCOPT_OPTION(
TOTP_CLI_COMMAND_ARG_DIGITS_PREFIX,
DOCOPT_ARGUMENT(
TOTP_CLI_COMMAND_ARG_DIGITS)) " Number of digits to generate, one of: 5, 6, 8 " DOCOPT_DEFAULT("6") "\r\n");
TOTP_CLI_COMMAND_ARG_DIGITS)) " Number of digits to generate, one of: %" PRIu8 ", %" PRIu8 ", %" PRIu8 " " DOCOPT_DEFAULT("%" PRIu8) "\r\n", TotpFiveDigitsCount, TotpSixDigitsCount, TotpEightDigitsCount, TotpSixDigitsCount);

TOTP_CLI_PRINTF(" " DOCOPT_OPTION(
TOTP_CLI_COMMAND_ARG_SECRET_ENCODING_PREFIX,
Expand All @@ -123,7 +123,7 @@ void totp_cli_command_add_docopt_options() {
TOTP_CLI_PRINTF(" " DOCOPT_OPTION(
TOTP_CLI_COMMAND_ARG_DURATION_PREFIX,
DOCOPT_ARGUMENT(
TOTP_CLI_COMMAND_ARG_DURATION)) " Token lifetime duration in seconds, between: 15 and 255 " DOCOPT_DEFAULT("30") "\r\n");
TOTP_CLI_COMMAND_ARG_DURATION)) " Token lifetime duration in seconds, between: %" PRIu8 " and %" PRIu8 " " DOCOPT_DEFAULT("%" PRIu8) "\r\n", TOTP_TOKEN_DURATION_MIN, TOTP_TOKEN_DURATION_MAX, TOTP_TOKEN_DURATION_DEFAULT);
TOTP_CLI_PRINTF(" " DOCOPT_SWITCH(
TOTP_CLI_COMMAND_ARG_UNSECURE_PREFIX) " Show console user input as-is without masking\r\n");
TOTP_CLI_PRINTF(" " DOCOPT_OPTION(
Expand Down
5 changes: 4 additions & 1 deletion types/token_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,13 @@ bool token_info_set_digits_from_int(TokenInfo* token_info, uint8_t digits) {
}

bool token_info_set_duration_from_int(TokenInfo* token_info, uint8_t duration) {
if(duration >= 15) {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wtype-limits"
if(duration >= TOTP_TOKEN_DURATION_MIN && duration <= TOTP_TOKEN_DURATION_MAX) {
token_info->duration = duration;
return true;
}
#pragma GCC diagnostic pop

return false;
}
Expand Down
3 changes: 2 additions & 1 deletion types/token_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
#include <furi/core/string.h>

#define TOTP_TOKEN_DURATION_DEFAULT (30)
#define TOTP_TOKEN_DURATION_MIN (15)
#define TOTP_TOKEN_DURATION_MAX UINT8_MAX

#define TOTP_TOKEN_ALGO_SHA1_NAME "sha1"
#define TOTP_TOKEN_ALGO_STEAM_NAME "steam"
#define TOTP_TOKEN_ALGO_SHA256_NAME "sha256"
#define TOTP_TOKEN_ALGO_SHA512_NAME "sha512"
#define TOTP_TOKEN_MAX_LENGTH (255)

#define PLAIN_TOKEN_ENCODING_BASE32_NAME "base32"
#define PLAIN_TOKEN_ENCODING_BASE64_NAME "base64"
Expand Down

0 comments on commit bf3952d

Please sign in to comment.