1
Fork 0
mirror of https://github.com/redstrate/Astra.git synced 2025-04-25 13:57:45 +00:00
astra/external/libbaseencode/src/common.h
Joshua Goins 5ee036dd09 Add option to generate OTP codes automatically
* This uses the great libcotp library, I stripped it down to fit inside
the repository.
* This is a security-convenience trade-off, and it's made very clear
with the tooltips on the settings page.
* It's still secured by your system keychain, and it's up to the users
whether that's good enough for them. Eventually down the line
I would like to support more esoteric keychains such as Bitwarden or
KeePass.
* Right now it's only integrated into the auto-login desktop feature,
but there will eventually be like an "auto-fill OTP" button in the main
window.

There's still a lot to clean up with these new features but they work
a little at least :-)
2022-08-31 21:19:25 -04:00

50 lines
No EOL
1.2 KiB
C

#pragma once
#include "baseencode.h"
#define BITS_PER_BYTE 8
#define BITS_PER_B32_BLOCK 5
#define BITS_PER_B64_BLOCK 6
// 64 MB should be more than enough
#define MAX_ENCODE_INPUT_LEN 64*1024*1024
// if 64 MB of data is encoded than it should be also possible to decode it. That's why a bigger input is allowed for decoding
#define MAX_DECODE_BASE32_INPUT_LEN ((MAX_ENCODE_INPUT_LEN * 8 + 4) / 5)
#define MAX_DECODE_BASE64_INPUT_LEN ((MAX_ENCODE_INPUT_LEN * 8 + 4) / 6)
static int
strip_char(char *str, char strip)
{
int found = 0;
char *p, *q;
for (q = p = str; *p; p++) {
if (*p != strip) {
*q++ = *p;
} else {
found++;
}
}
*q = '\0';
return found;
}
static void
check_input(const unsigned char *user_data, size_t data_len, int max_len, baseencode_error_t *err)
{
if (user_data == NULL || (data_len == 0 && user_data[0] != '\0')) {
*err = INVALID_INPUT;
return;
} else if (user_data[0] == '\0') {
*err = EMPTY_STRING;
return;
}
if (data_len > max_len) {
*err = INPUT_TOO_BIG;
return;
}
*err = SUCCESS;
}