Funkce pro overeni Base64 kodovaneho retezce
This commit is contained in:
parent
ed8d1e5a03
commit
7ba28c9ba2
@ -3,6 +3,23 @@
|
||||
#include <libb64/cdecode.h>
|
||||
#include <cutils.hpp>
|
||||
|
||||
bool isBase64(const char *p)
|
||||
{
|
||||
char c;
|
||||
|
||||
if (strlen(p) % 4 != 0)
|
||||
return false;
|
||||
do {
|
||||
c = *p;
|
||||
if (isalnum(c)) // alphanumberics are OK
|
||||
continue;
|
||||
if (c == '/' || c == '+' || c == '=') // + or / or = is OK.
|
||||
continue;
|
||||
return false;
|
||||
} while (*++p != 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
void strEncode(String &str)
|
||||
{
|
||||
|
||||
@ -41,9 +58,11 @@ void strDecode(String &str)
|
||||
uint32_t cid = ESP_getChipId();
|
||||
uint32_t *pkey = (uint32_t *)&key[0];
|
||||
uint8_t data[str.length()];
|
||||
unsigned int clen = base64_decode_chars(src, str.length(), (char *)data);
|
||||
String result = F("");
|
||||
|
||||
if (isBase64(str.c_str())) {
|
||||
unsigned int clen = base64_decode_chars(src, str.length(), (char *)data);
|
||||
|
||||
if (0 != clen) {
|
||||
*pkey = cid;
|
||||
for (i = 0; i < clen; i++) {
|
||||
@ -54,5 +73,6 @@ void strDecode(String &str)
|
||||
result.concat(char(b));
|
||||
}
|
||||
}
|
||||
}
|
||||
str = result;
|
||||
}
|
||||
|
@ -16,4 +16,13 @@ void strEncode(String &str);
|
||||
*/
|
||||
void strDecode(String &str);
|
||||
|
||||
/**
|
||||
* @brief Overeni, ze je retezec Base64
|
||||
*
|
||||
* @param p Ukazatel na retezec
|
||||
* @return true Retezec je kodovany pomoci Base64
|
||||
* @return false Retezec neni kodovany pomoci Base64
|
||||
*/
|
||||
bool isBase64(const char *p);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user