return toupper(c) - 'A' + 10;
}
-int hex2bin(const char *src, char *dst, int length) {
+int hex2bin(const char *src, void *vdst, int length) {
+ char *dst = vdst;
int i;
for(i = 0; i < length && isxdigit(src[i * 2]) && isxdigit(src[i * 2 + 1]); i++)
dst[i] = charhex2bin(src[i * 2]) * 16 + charhex2bin(src[i * 2 + 1]);
return i;
}
-int bin2hex(const char *src, char *dst, int length) {
+int bin2hex(const void *vsrc, char *dst, int length) {
+ const char *src = vsrc;
for(int i = length - 1; i >= 0; i--) {
dst[i * 2 + 1] = hexadecimals[(unsigned char) src[i] & 15];
dst[i * 2] = hexadecimals[(unsigned char) src[i] >> 4];
return length * 2;
}
-int b64decode(const char *src, char *dst, int length) {
+int b64decode(const char *src, void *dst, int length) {
int i;
uint32_t triplet = 0;
unsigned char *udst = (unsigned char *)dst;
}
}
-static int b64encode_internal(const char *src, char *dst, int length, const char *alphabet) {
+static int b64encode_internal(const void *src, char *dst, int length, const char *alphabet) {
uint32_t triplet;
const unsigned char *usrc = (unsigned char *)src;
int si = length / 3 * 3;
return length;
}
-int b64encode(const char *src, char *dst, int length) {
+int b64encode(const void *src, char *dst, int length) {
return b64encode_internal(src, dst, length, base64_original);
}
-int b64encode_urlsafe(const char *src, char *dst, int length) {
+int b64encode_urlsafe(const void *src, char *dst, int length) {
return b64encode_internal(src, dst, length, base64_urlsafe);
}
#ifndef __TINC_UTILS_H__
#define __TINC_UTILS_H__
-extern int hex2bin(const char *src, char *dst, int length);
-extern int bin2hex(const char *src, char *dst, int length);
+extern int hex2bin(const char *src, void *dst, int length);
+extern int bin2hex(const void *src, char *dst, int length);
-extern int b64encode(const char *src, char *dst, int length);
-extern int b64encode_urlsafe(const char *src, char *dst, int length);
-extern int b64decode(const char *src, char *dst, int length);
+extern int b64encode(const void *src, char *dst, int length);
+extern int b64encode_urlsafe(const void *src, char *dst, int length);
+extern int b64decode(const char *src, void *dst, int length);
#ifdef HAVE_MINGW
extern const char *winerror(int);