Use const pointer to source in base64 and hex routines.
This commit is contained in:
parent
574b380dfc
commit
fa4a01e4a2
2 changed files with 8 additions and 8 deletions
|
@ -46,14 +46,14 @@ static int charb64decode(char c) {
|
||||||
return 63;
|
return 63;
|
||||||
}
|
}
|
||||||
|
|
||||||
int hex2bin(char *src, char *dst, int length) {
|
int hex2bin(const char *src, char *dst, int length) {
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; i < length && src[i * 2] && src[i * 2 + 1]; i++)
|
for(i = 0; i < length && src[i * 2] && src[i * 2 + 1]; i++)
|
||||||
dst[i] = charhex2bin(src[i * 2]) * 16 + charhex2bin(src[i * 2 + 1]);
|
dst[i] = charhex2bin(src[i * 2]) * 16 + charhex2bin(src[i * 2 + 1]);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
int bin2hex(char *src, char *dst, int length) {
|
int bin2hex(const char *src, char *dst, int length) {
|
||||||
int i;
|
int i;
|
||||||
for(i = length - 1; i >= 0; i--) {
|
for(i = length - 1; i >= 0; i--) {
|
||||||
dst[i * 2 + 1] = hexadecimals[(unsigned char) src[i] & 15];
|
dst[i * 2 + 1] = hexadecimals[(unsigned char) src[i] & 15];
|
||||||
|
@ -63,7 +63,7 @@ int bin2hex(char *src, char *dst, int length) {
|
||||||
return length * 2;
|
return length * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
int b64decode(char *src, char *dst, int length) {
|
int b64decode(const char *src, char *dst, int length) {
|
||||||
int i;
|
int i;
|
||||||
uint32_t triplet = 0;
|
uint32_t triplet = 0;
|
||||||
unsigned char *udst = dst;
|
unsigned char *udst = dst;
|
||||||
|
@ -90,7 +90,7 @@ int b64decode(char *src, char *dst, int length) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int b64encode(char *src, char *dst, int length) {
|
int b64encode(const char *src, char *dst, int length) {
|
||||||
uint32_t triplet;
|
uint32_t triplet;
|
||||||
const unsigned char *usrc = src;
|
const unsigned char *usrc = src;
|
||||||
int si = length / 3 * 3;
|
int si = length / 3 * 3;
|
||||||
|
|
|
@ -21,11 +21,11 @@
|
||||||
#ifndef __TINC_UTILS_H__
|
#ifndef __TINC_UTILS_H__
|
||||||
#define __TINC_UTILS_H__
|
#define __TINC_UTILS_H__
|
||||||
|
|
||||||
extern int hex2bin(char *src, char *dst, int length);
|
extern int hex2bin(const char *src, char *dst, int length);
|
||||||
extern int bin2hex(char *src, char *dst, int length);
|
extern int bin2hex(const char *src, char *dst, int length);
|
||||||
|
|
||||||
extern int b64encode(char *src, char *dst, int length);
|
extern int b64encode(const char *src, char *dst, int length);
|
||||||
extern int b64decode(char *src, char *dst, int length);
|
extern int b64decode(const char *src, char *dst, int length);
|
||||||
|
|
||||||
#ifdef HAVE_MINGW
|
#ifdef HAVE_MINGW
|
||||||
extern const char *winerror(int);
|
extern const char *winerror(int);
|
||||||
|
|
Loading…
Reference in a new issue