mirror of
https://github.com/cathugger/mkp224o.git
synced 2025-06-24 18:10:55 +00:00
optional functionality for writing results to the single file and extracting specific keys from it
This commit is contained in:
parent
37a1506b18
commit
6a416795b7
7 changed files with 554 additions and 47 deletions
44
test_base64.c
Normal file
44
test_base64.c
Normal file
|
@ -0,0 +1,44 @@
|
|||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include "types.h"
|
||||
#include "base64.h"
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <sodium/randombytes.h>
|
||||
|
||||
struct texttestcase {
|
||||
const char *in;
|
||||
const char *out;
|
||||
const char *rev;
|
||||
} tests0[] = {
|
||||
{"", "", ""},
|
||||
{"f", "Zg==", "f"},
|
||||
{"fo", "Zm8=", "fo"},
|
||||
{"foo", "Zm9v", "foo"},
|
||||
{"foob", "Zm9vYg==", "foob"},
|
||||
{"fooba", "Zm9vYmE=", "fooba"},
|
||||
{"foobar", "Zm9vYmFy", "foobar"},
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char buf[1024], buf2[1024];
|
||||
size_t r;
|
||||
for (size_t i = 0; i < sizeof(tests0)/sizeof(tests0[0]); ++i) {
|
||||
base64_to(buf, (const u8 *)tests0[i].in, strlen(tests0[i].in));
|
||||
if (strcmp(buf, tests0[i].out) != 0) {
|
||||
printf("invalid encoding result: \"%s\" -> encoded as \"%s\", but expected \"%s\".\n",
|
||||
tests0[i].in, buf, tests0[i].out);
|
||||
return 1;
|
||||
}
|
||||
r = base64_from((u8 *)buf2, buf, strlen(buf));
|
||||
buf2[r] = '\0';
|
||||
if (strcmp(buf2, tests0[i].rev) != 0) {
|
||||
printf("invalid decoding result: encoded \"%s\", decoded as \"%s\", but expected \"%s\".\n",
|
||||
tests0[i].out, buf2, tests0[i].rev);
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue