utils: the needed api is to decode

This commit is contained in:
Boris Faure 2023-08-20 16:00:21 +02:00
parent a0aa06c5ac
commit 3b0384f063
Signed by: borisfaure
GPG Key ID: EAA9CD729F522998
2 changed files with 16 additions and 16 deletions

View File

@ -78,7 +78,7 @@ end:
} }
char * char *
ty_eina_unicode_base64_encode(Eina_Unicode *unicode) ty_eina_unicode_base64_decode(Eina_Unicode *unicode)
{ {
int utf8_len = 0; int utf8_len = 0;
Eina_Binbuf *bb; Eina_Binbuf *bb;
@ -89,20 +89,20 @@ ty_eina_unicode_base64_encode(Eina_Unicode *unicode)
src = eina_unicode_unicode_to_utf8(unicode, &utf8_len); src = eina_unicode_unicode_to_utf8(unicode, &utf8_len);
if (!src) if (!src)
return NULL; return NULL;
bb = eina_binbuf_manage_new((const unsigned char*)src, utf8_len, EINA_FALSE); sb = eina_strbuf_manage_new_length(src, utf8_len);
if (!bb) if (!sb)
{ {
free(src); free(src);
return NULL; return NULL;
} }
sb = emile_base64_encode(bb); bb = emile_base64_decode(sb);
eina_binbuf_free(bb); eina_strbuf_free(sb);
if (!sb) if (!bb)
return NULL; return NULL;
res = (char*) eina_strbuf_string_steal(sb); res = (char*) eina_binbuf_string_steal(bb);
eina_strbuf_free(sb); eina_binbuf_free(bb);
return res; return res;
} }
@ -114,23 +114,23 @@ int tytest_base64(void)
const char *expected; const char *expected;
const char *terminology = "Terminology rox!"; const char *terminology_rox = "VGVybWlub2xvZ3kgcm94IQ==";
src = eina_unicode_utf8_to_unicode(terminology, NULL); src = eina_unicode_utf8_to_unicode(terminology_rox, NULL);
assert(src); assert(src);
res = ty_eina_unicode_base64_encode(src); res = ty_eina_unicode_base64_decode(src);
assert(res); assert(res);
expected = "VGVybWlub2xvZ3kgcm94IQ=="; expected = "Terminology rox!";
assert(memcmp(res, expected, strlen(expected)) == 0); assert(memcmp(res, expected, strlen(expected)) == 0);
free(src); free(src);
free(res); free(res);
const char *hearts = "♥♡👍🚲✿ ❀ ❁🙌"; const char *hearts = "4pml4pmh8J+RjfCfmrLinL8g4p2AIOKdgfCfmYw=";
src = eina_unicode_utf8_to_unicode(hearts, NULL); src = eina_unicode_utf8_to_unicode(hearts, NULL);
assert(src); assert(src);
res = ty_eina_unicode_base64_encode(src); res = ty_eina_unicode_base64_decode(src);
assert(res); assert(res);
expected = "4pml4pmh8J+RjfCfmrLinL8g4p2AIOKdgfCfmYw="; expected = "♥♡👍🚲✿ ❀ ❁🙌";
assert(memcmp(res, expected, strlen(expected)) == 0); assert(memcmp(res, expected, strlen(expected)) == 0);
free(src); free(src);
free(res); free(res);

View File

@ -7,5 +7,5 @@
Eina_Bool homedir_get(char *buf, size_t size); Eina_Bool homedir_get(char *buf, size_t size);
void open_url(const Config *config, const char *url); void open_url(const Config *config, const char *url);
char * ty_eina_unicode_base64_encode(Eina_Unicode *c); char * ty_eina_unicode_base64_decode(Eina_Unicode *c);
#endif #endif