mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-15 01:55:03 +00:00
Got rid of xs_encdec.h.
This commit is contained in:
parent
7f1b87a6b6
commit
970ad7a540
13 changed files with 29 additions and 182 deletions
29
Makefile
29
Makefile
|
@ -27,24 +27,23 @@ install:
|
||||||
mkdir -p -m 755 $(PREFIX_MAN)/man8
|
mkdir -p -m 755 $(PREFIX_MAN)/man8
|
||||||
install -m 644 doc/snac.8 $(PREFIX_MAN)/man8/snac.8
|
install -m 644 doc/snac.8 $(PREFIX_MAN)/man8/snac.8
|
||||||
|
|
||||||
activitypub.o: activitypub.c xs.h xs_encdec.h xs_json.h xs_curl.h \
|
activitypub.o: activitypub.c xs.h xs_json.h xs_curl.h xs_mime.h \
|
||||||
xs_mime.h xs_openssl.h xs_regex.h xs_time.h xs_set.h snac.h
|
xs_openssl.h xs_regex.h xs_time.h xs_set.h snac.h
|
||||||
data.o: data.c xs.h xs_io.h xs_json.h xs_openssl.h xs_glob.h xs_set.h \
|
data.o: data.c xs.h xs_io.h xs_json.h xs_openssl.h xs_glob.h xs_set.h \
|
||||||
xs_time.h snac.h
|
xs_time.h snac.h
|
||||||
format.o: format.c xs.h xs_regex.h snac.h
|
format.o: format.c xs.h xs_regex.h snac.h
|
||||||
html.o: html.c xs.h xs_io.h xs_encdec.h xs_json.h xs_regex.h xs_set.h \
|
html.o: html.c xs.h xs_io.h xs_json.h xs_regex.h xs_set.h xs_openssl.h \
|
||||||
xs_openssl.h xs_time.h xs_mime.h snac.h
|
xs_time.h xs_mime.h snac.h
|
||||||
http.o: http.c xs.h xs_io.h xs_encdec.h xs_openssl.h xs_curl.h xs_time.h \
|
http.o: http.c xs.h xs_io.h xs_openssl.h xs_curl.h xs_time.h xs_json.h \
|
||||||
xs_json.h snac.h
|
snac.h
|
||||||
httpd.o: httpd.c xs.h xs_io.h xs_encdec.h xs_json.h xs_socket.h \
|
httpd.o: httpd.c xs.h xs_io.h xs_json.h xs_socket.h xs_httpd.h xs_mime.h \
|
||||||
xs_httpd.h xs_mime.h xs_time.h snac.h
|
xs_time.h snac.h
|
||||||
main.o: main.c xs.h xs_io.h xs_encdec.h xs_json.h snac.h
|
main.o: main.c xs.h xs_io.h xs_json.h snac.h
|
||||||
mastoapi.o: mastoapi.c xs.h xs_encdec.h xs_openssl.h xs_json.h xs_io.h \
|
mastoapi.o: mastoapi.c xs.h xs_openssl.h xs_json.h xs_io.h xs_time.h \
|
||||||
xs_time.h xs_glob.h snac.h
|
xs_glob.h xs_set.h snac.h
|
||||||
snac.o: snac.c xs.h xs_io.h xs_encdec.h xs_json.h xs_curl.h xs_openssl.h \
|
snac.o: snac.c xs.h xs_io.h xs_unicode.h xs_json.h xs_curl.h xs_openssl.h \
|
||||||
xs_socket.h xs_httpd.h xs_mime.h xs_regex.h xs_set.h xs_time.h xs_glob.h \
|
xs_socket.h xs_httpd.h xs_mime.h xs_regex.h xs_set.h xs_time.h xs_glob.h \
|
||||||
snac.h
|
snac.h
|
||||||
upgrade.o: upgrade.c xs.h xs_io.h xs_json.h xs_glob.h snac.h
|
upgrade.o: upgrade.c xs.h xs_io.h xs_json.h xs_glob.h snac.h
|
||||||
utils.o: utils.c xs.h xs_io.h xs_encdec.h xs_json.h xs_time.h \
|
utils.o: utils.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h snac.h
|
||||||
xs_openssl.h snac.h
|
webfinger.o: webfinger.c xs.h xs_json.h xs_curl.h snac.h
|
||||||
webfinger.o: webfinger.c xs.h xs_encdec.h xs_json.h xs_curl.h snac.h
|
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
/* copyright (c) 2022 - 2023 grunfink / MIT license */
|
/* copyright (c) 2022 - 2023 grunfink / MIT license */
|
||||||
|
|
||||||
#include "xs.h"
|
#include "xs.h"
|
||||||
#include "xs_encdec.h"
|
|
||||||
#include "xs_json.h"
|
#include "xs_json.h"
|
||||||
#include "xs_curl.h"
|
#include "xs_curl.h"
|
||||||
#include "xs_mime.h"
|
#include "xs_mime.h"
|
||||||
|
|
1
html.c
1
html.c
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
#include "xs.h"
|
#include "xs.h"
|
||||||
#include "xs_io.h"
|
#include "xs_io.h"
|
||||||
#include "xs_encdec.h"
|
|
||||||
#include "xs_json.h"
|
#include "xs_json.h"
|
||||||
#include "xs_regex.h"
|
#include "xs_regex.h"
|
||||||
#include "xs_set.h"
|
#include "xs_set.h"
|
||||||
|
|
1
http.c
1
http.c
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
#include "xs.h"
|
#include "xs.h"
|
||||||
#include "xs_io.h"
|
#include "xs_io.h"
|
||||||
#include "xs_encdec.h"
|
|
||||||
#include "xs_openssl.h"
|
#include "xs_openssl.h"
|
||||||
#include "xs_curl.h"
|
#include "xs_curl.h"
|
||||||
#include "xs_time.h"
|
#include "xs_time.h"
|
||||||
|
|
2
httpd.c
2
httpd.c
|
@ -3,12 +3,12 @@
|
||||||
|
|
||||||
#include "xs.h"
|
#include "xs.h"
|
||||||
#include "xs_io.h"
|
#include "xs_io.h"
|
||||||
#include "xs_encdec.h"
|
|
||||||
#include "xs_json.h"
|
#include "xs_json.h"
|
||||||
#include "xs_socket.h"
|
#include "xs_socket.h"
|
||||||
#include "xs_httpd.h"
|
#include "xs_httpd.h"
|
||||||
#include "xs_mime.h"
|
#include "xs_mime.h"
|
||||||
#include "xs_time.h"
|
#include "xs_time.h"
|
||||||
|
#include "xs_openssl.h"
|
||||||
|
|
||||||
#include "snac.h"
|
#include "snac.h"
|
||||||
|
|
||||||
|
|
1
main.c
1
main.c
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
#include "xs.h"
|
#include "xs.h"
|
||||||
#include "xs_io.h"
|
#include "xs_io.h"
|
||||||
#include "xs_encdec.h"
|
|
||||||
#include "xs_json.h"
|
#include "xs_json.h"
|
||||||
|
|
||||||
#include "snac.h"
|
#include "snac.h"
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
#ifndef NO_MASTODON_API
|
#ifndef NO_MASTODON_API
|
||||||
|
|
||||||
#include "xs.h"
|
#include "xs.h"
|
||||||
#include "xs_encdec.h"
|
|
||||||
#include "xs_openssl.h"
|
#include "xs_openssl.h"
|
||||||
#include "xs_json.h"
|
#include "xs_json.h"
|
||||||
#include "xs_io.h"
|
#include "xs_io.h"
|
||||||
|
|
1
snac.c
1
snac.c
|
@ -7,7 +7,6 @@
|
||||||
#include "xs_io.h"
|
#include "xs_io.h"
|
||||||
#include "xs_unicode.h"
|
#include "xs_unicode.h"
|
||||||
#include "xs_json.h"
|
#include "xs_json.h"
|
||||||
#include "xs_encdec.h"
|
|
||||||
#include "xs_curl.h"
|
#include "xs_curl.h"
|
||||||
#include "xs_openssl.h"
|
#include "xs_openssl.h"
|
||||||
#include "xs_socket.h"
|
#include "xs_socket.h"
|
||||||
|
|
1
utils.c
1
utils.c
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
#include "xs.h"
|
#include "xs.h"
|
||||||
#include "xs_io.h"
|
#include "xs_io.h"
|
||||||
#include "xs_encdec.h"
|
|
||||||
#include "xs_json.h"
|
#include "xs_json.h"
|
||||||
#include "xs_time.h"
|
#include "xs_time.h"
|
||||||
#include "xs_openssl.h"
|
#include "xs_openssl.h"
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
/* copyright (c) 2022 - 2023 grunfink / MIT license */
|
/* copyright (c) 2022 - 2023 grunfink / MIT license */
|
||||||
|
|
||||||
#include "xs.h"
|
#include "xs.h"
|
||||||
#include "xs_encdec.h"
|
|
||||||
#include "xs_json.h"
|
#include "xs_json.h"
|
||||||
#include "xs_curl.h"
|
#include "xs_curl.h"
|
||||||
|
|
||||||
|
|
155
xs_encdec.h
155
xs_encdec.h
|
@ -1,155 +0,0 @@
|
||||||
/* copyright (c) 2022 - 2023 grunfink / MIT license */
|
|
||||||
|
|
||||||
#ifndef _XS_ENCDEC_H
|
|
||||||
|
|
||||||
#define _XS_ENCDEC_H
|
|
||||||
|
|
||||||
xs_str *xs_base64_enc(const xs_val *data, int sz);
|
|
||||||
xs_val *xs_base64_dec(const xs_str *data, int *size);
|
|
||||||
int xs_is_base64(const char *str);
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef XS_IMPLEMENTATION
|
|
||||||
|
|
||||||
/** base64 */
|
|
||||||
|
|
||||||
static char *xs_b64_tbl = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
||||||
"abcdefghijklmnopqrstuvwxyz"
|
|
||||||
"0123456789+/=";
|
|
||||||
|
|
||||||
xs_str *xs_base64_enc_tbl(const xs_val *data, int sz, const char *b64_tbl)
|
|
||||||
/* encodes data to base64 using a table */
|
|
||||||
{
|
|
||||||
xs_str *s;
|
|
||||||
unsigned char *p;
|
|
||||||
char *i;
|
|
||||||
int bsz, n;
|
|
||||||
|
|
||||||
bsz = ((sz + 3 - 1) / 3) * 4;
|
|
||||||
i = s = xs_realloc(NULL, _xs_blk_size(bsz + 1));
|
|
||||||
p = (unsigned char *)data;
|
|
||||||
|
|
||||||
for (n = 0; n < sz; n += 3) {
|
|
||||||
int l = sz - n;
|
|
||||||
|
|
||||||
if (l == 1) {
|
|
||||||
*i++ = b64_tbl[(p[n] >> 2) & 0x3f];
|
|
||||||
*i++ = b64_tbl[(p[n] << 4) & 0x3f];
|
|
||||||
*i++ = '=';
|
|
||||||
*i++ = '=';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if (l == 2) {
|
|
||||||
*i++ = b64_tbl[(p[n] >> 2) & 0x3f];
|
|
||||||
*i++ = b64_tbl[(p[n] << 4 | p[n + 1] >> 4) & 0x3f];
|
|
||||||
*i++ = b64_tbl[(p[n + 1] << 2) & 0x3f];
|
|
||||||
*i++ = '=';
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
*i++ = b64_tbl[(p[n] >> 2) & 0x3f];
|
|
||||||
*i++ = b64_tbl[(p[n] << 4 | p[n + 1] >> 4) & 0x3f];
|
|
||||||
*i++ = b64_tbl[(p[n + 1] << 2 | p[n + 2] >> 6) & 0x3f];
|
|
||||||
*i++ = b64_tbl[(p[n + 2]) & 0x3f];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*i = '\0';
|
|
||||||
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
xs_str *xs_base64_enc(const xs_val *data, int sz)
|
|
||||||
/* encodes data to base64 */
|
|
||||||
{
|
|
||||||
return xs_base64_enc_tbl(data, sz, xs_b64_tbl);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
xs_val *xs_base64_dec_tbl(const xs_str *data, int *size, const char *b64_tbl)
|
|
||||||
/* decodes data from base64 using a table */
|
|
||||||
{
|
|
||||||
xs_val *s = NULL;
|
|
||||||
int sz = 0;
|
|
||||||
char *p;
|
|
||||||
|
|
||||||
p = (char *)data;
|
|
||||||
|
|
||||||
/* size of data must be a multiple of 4 */
|
|
||||||
if (strlen(p) % 4)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
for (p = (char *)data; *p; p += 4) {
|
|
||||||
int cs[4];
|
|
||||||
int n;
|
|
||||||
unsigned char tmp[3];
|
|
||||||
|
|
||||||
for (n = 0; n < 4; n++) {
|
|
||||||
char *ss = strchr(b64_tbl, p[n]);
|
|
||||||
|
|
||||||
if (ss == NULL) {
|
|
||||||
/* not a base64 char */
|
|
||||||
return xs_free(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
cs[n] = ss - b64_tbl;
|
|
||||||
}
|
|
||||||
|
|
||||||
n = 0;
|
|
||||||
|
|
||||||
/* first byte */
|
|
||||||
tmp[n++] = cs[0] << 2 | ((cs[1] >> 4) & 0x0f);
|
|
||||||
|
|
||||||
/* second byte */
|
|
||||||
if (cs[2] != 64)
|
|
||||||
tmp[n++] = cs[1] << 4 | ((cs[2] >> 2) & 0x3f);
|
|
||||||
|
|
||||||
/* third byte */
|
|
||||||
if (cs[3] != 64)
|
|
||||||
tmp[n++] = cs[2] << 6 | (cs[3] & 0x3f);
|
|
||||||
|
|
||||||
/* must be done manually because data can be pure binary */
|
|
||||||
s = xs_realloc(s, _xs_blk_size(sz + n));
|
|
||||||
memcpy(s + sz, tmp, n);
|
|
||||||
sz += n;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* asciiz it to use it as a string */
|
|
||||||
s = xs_realloc(s, _xs_blk_size(sz + 1));
|
|
||||||
s[sz] = '\0';
|
|
||||||
|
|
||||||
*size = sz;
|
|
||||||
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
xs_val *xs_base64_dec(const xs_str *data, int *size)
|
|
||||||
/* decodes data from base64 */
|
|
||||||
{
|
|
||||||
return xs_base64_dec_tbl(data, size, xs_b64_tbl);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int xs_is_base64_tbl(const char *str, const char *b64_tbl)
|
|
||||||
/* returns 1 if str is a base64 string, with table */
|
|
||||||
{
|
|
||||||
while (*str) {
|
|
||||||
if (strchr(b64_tbl, *str++) == NULL)
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int xs_is_base64(const char *str)
|
|
||||||
/* returns 1 if str is a base64 string */
|
|
||||||
{
|
|
||||||
return xs_is_base64_tbl(str, xs_b64_tbl);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* XS_IMPLEMENTATION */
|
|
||||||
|
|
||||||
#endif /* _XS_ENCDEC_H */
|
|
15
xs_openssl.h
15
xs_openssl.h
|
@ -6,7 +6,15 @@
|
||||||
|
|
||||||
xs_str *_xs_digest(const xs_val *input, int size, const char *digest, int as_hex);
|
xs_str *_xs_digest(const xs_val *input, int size, const char *digest, int as_hex);
|
||||||
|
|
||||||
|
#ifndef _XS_MD5_H
|
||||||
#define xs_md5_hex(input, size) _xs_digest(input, size, "md5", 1)
|
#define xs_md5_hex(input, size) _xs_digest(input, size, "md5", 1)
|
||||||
|
#endif /* XS_MD5_H */
|
||||||
|
|
||||||
|
#ifndef _XS_BASE64_H
|
||||||
|
xs_str *xs_base64_enc(const xs_val *data, int sz);
|
||||||
|
xs_val *xs_base64_dec(const xs_str *data, int *size);
|
||||||
|
#endif /* XS_BASE64_H */
|
||||||
|
|
||||||
#define xs_sha1_hex(input, size) _xs_digest(input, size, "sha1", 1)
|
#define xs_sha1_hex(input, size) _xs_digest(input, size, "sha1", 1)
|
||||||
#define xs_sha256_hex(input, size) _xs_digest(input, size, "sha256", 1)
|
#define xs_sha256_hex(input, size) _xs_digest(input, size, "sha256", 1)
|
||||||
#define xs_sha256_base64(input, size) _xs_digest(input, size, "sha256", 0)
|
#define xs_sha256_base64(input, size) _xs_digest(input, size, "sha256", 0)
|
||||||
|
@ -22,7 +30,9 @@ int xs_evp_verify(const char *pubkey, const char *mem, int size, const char *b64
|
||||||
#include "openssl/pem.h"
|
#include "openssl/pem.h"
|
||||||
#include "openssl/evp.h"
|
#include "openssl/evp.h"
|
||||||
|
|
||||||
#if 0
|
|
||||||
|
#ifndef _XS_BASE64_H
|
||||||
|
|
||||||
xs_str *xs_base64_enc(const xs_val *data, int sz)
|
xs_str *xs_base64_enc(const xs_val *data, int sz)
|
||||||
/* encodes data to base64 */
|
/* encodes data to base64 */
|
||||||
{
|
{
|
||||||
|
@ -77,7 +87,8 @@ xs_val *xs_base64_dec(const xs_str *data, int *size)
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
#endif /* _XS_BASE64_H */
|
||||||
|
|
||||||
|
|
||||||
xs_str *_xs_digest(const xs_val *input, int size, const char *digest, int as_hex)
|
xs_str *_xs_digest(const xs_val *input, int size, const char *digest, int as_hex)
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
/* e0835629880a2846ad69c02a63a9209d5dd34945 */
|
/* 1948fa3c5f0df994170cd38b9144b99734b071e6 */
|
||||||
|
|
Loading…
Reference in a new issue