ddat interop with dat js cable interop with cabal js ddat's frontend = dat-thang cable fe = cable-thang dillo support based on cel's dillo-dat bootstrap node xplatform support Signed-off-by: divo <418@cryspace.space>
47 lines
2.0 KiB
C
47 lines
2.0 KiB
C
#include "base32768.h"
|
|
#include "dat.h"
|
|
#include <assert.h>
|
|
#include <errno.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
int main(void)
|
|
{
|
|
static const uint8_t hello[] = {104,101,108,108,111,32,119,111,114,108,100};
|
|
static const char encoded_hello[] = "媒腻㐤┖ꈳ埳";
|
|
uint8_t input[257], decoded[257];
|
|
char encoded[1200];
|
|
char archive_url[DAT_URL_BYTES];
|
|
char compact_link[DAT_LINK_BYTES];
|
|
dat_url_t parsed_url;
|
|
static const char historical_address[] =
|
|
"dat://59d8099399510e23a3c693fb5887b7bba1586f4117f7ef1c5872622ada0c1181";
|
|
static const char compact_historical_address[] =
|
|
"dat://卌Ꭴ馊㜢䍞䂏鴑╗萰类躂ꜞ齂蠩檵聬♠ʟ";
|
|
uint8_t archive_key[DAT_KEY_BYTES];
|
|
size_t length, i, decoded_length;
|
|
assert(base32768_encode(hello, sizeof(hello), encoded, sizeof(encoded)) == 0);
|
|
assert(!strcmp(encoded, encoded_hello));
|
|
assert(base32768_decode(encoded_hello, decoded, sizeof(decoded), &decoded_length) == 0);
|
|
assert(decoded_length == sizeof(hello) && !memcmp(decoded, hello, sizeof(hello)));
|
|
for (length = 0; length <= sizeof(input); length++) {
|
|
for (i = 0; i < length; i++) input[i] = (uint8_t)(i * 37u + length);
|
|
assert(base32768_encode(input, length, encoded, sizeof(encoded)) == 0);
|
|
assert(base32768_decode(encoded, decoded, sizeof(decoded), &decoded_length) == 0);
|
|
assert(decoded_length == length && !memcmp(decoded, input, length));
|
|
}
|
|
assert(base32768_decode("A", decoded, sizeof(decoded), &decoded_length) == -1);
|
|
assert(errno == EILSEQ);
|
|
assert(dat_url_to_key(historical_address, archive_key) == 0);
|
|
assert(dat_key_to_compact_url(archive_key, archive_url) == 0);
|
|
assert(!strcmp(archive_url, compact_historical_address));
|
|
snprintf(compact_link, sizeof(compact_link), "%s+7/readme.txt", archive_url);
|
|
assert(dat_url_parse(compact_link, &parsed_url) == 0);
|
|
assert(parsed_url.has_version && parsed_url.version == 7);
|
|
assert(!strcmp(parsed_url.host, compact_historical_address + 6));
|
|
assert(dat_url_to_key(parsed_url.host, decoded) == 0);
|
|
assert(!memcmp(decoded, archive_key, sizeof(archive_key)));
|
|
return 0;
|
|
}
|