Add some const modifiers

This allows these functions to be used with const buffers.
This commit is contained in:
Hardening 2014-05-09 22:36:50 +02:00
parent 3b47715a78
commit 50f1f0df6f
4 changed files with 19 additions and 17 deletions

View File

@ -143,7 +143,7 @@ FREERDP_API int crypto_rsa_private_decrypt(const BYTE* input, int length, UINT32
FREERDP_API void crypto_reverse(BYTE* data, int length);
FREERDP_API void crypto_nonce(BYTE* nonce, int size);
FREERDP_API char* crypto_base64_encode(BYTE* data, int length);
FREERDP_API void crypto_base64_decode(BYTE* enc_data, int length, BYTE** dec_data, int* res_length);
FREERDP_API char* crypto_base64_encode(const BYTE* data, int length);
FREERDP_API void crypto_base64_decode(const BYTE* enc_data, int length, BYTE** dec_data, int* res_length);
#endif /* FREERDP_CRYPTO_H */

View File

@ -27,16 +27,18 @@
static const char base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
char* crypto_base64_encode(BYTE* data, int length)
char* crypto_base64_encode(const BYTE* data, int length)
{
int c;
BYTE* q;
const BYTE* q;
char* p;
char* str;
char* ret;
int i = 0;
q = data;
p = str = (char*) malloc((length + 3) * 4 / 3 + 1);
p = ret = (char*) malloc((length + 3) * 4 / 3 + 1);
if (!p)
return NULL;
while (i < length)
{
@ -68,7 +70,7 @@ char* crypto_base64_encode(BYTE* data, int length)
*p = 0;
return str;
return ret;
}
static int base64_decode_char(char c)
@ -94,7 +96,7 @@ static int base64_decode_char(char c)
return -1;
}
static void* base64_decode(BYTE* s, int length, int* data_len)
static void* base64_decode(const BYTE* s, int length, int* data_len)
{
char* p;
int n[4];
@ -142,7 +144,7 @@ static void* base64_decode(BYTE* s, int length, int* data_len)
return data;
}
void crypto_base64_decode(BYTE* enc_data, int length, BYTE** dec_data, int* res_length)
void crypto_base64_decode(const BYTE* enc_data, int length, BYTE** dec_data, int* res_length)
{
*dec_data = base64_decode(enc_data, length, res_length);
}

View File

@ -33,10 +33,10 @@
extern "C" {
#endif
WINPR_API void winpr_HexDump(BYTE* data, int length);
WINPR_API void winpr_CArrayDump(BYTE* data, int length, int width);
WINPR_API void winpr_HexDump(const BYTE* data, int length);
WINPR_API void winpr_CArrayDump(const BYTE* data, int length, int width);
WINPR_API char* winpr_BinToHexString(BYTE* data, int length, BOOL space);
WINPR_API char* winpr_BinToHexString(const BYTE* data, int length, BOOL space);
WINPR_API int wprintfx(const char *fmt, ...);
WINPR_API int wvprintfx(const char *fmt, va_list args);

View File

@ -30,9 +30,9 @@
#include "trio.h"
void winpr_HexDump(BYTE* data, int length)
void winpr_HexDump(const BYTE* data, int length)
{
BYTE* p = data;
const BYTE* p = data;
int i, line, offset = 0;
while (offset < length)
@ -60,9 +60,9 @@ void winpr_HexDump(BYTE* data, int length)
}
}
void winpr_CArrayDump(BYTE* data, int length, int width)
void winpr_CArrayDump(const BYTE* data, int length, int width)
{
BYTE* p = data;
const BYTE* p = data;
int i, line, offset = 0;
while (offset < length)
@ -86,7 +86,7 @@ void winpr_CArrayDump(BYTE* data, int length, int width)
printf("\n");
}
char* winpr_BinToHexString(BYTE* data, int length, BOOL space)
char* winpr_BinToHexString(const BYTE* data, int length, BOOL space)
{
int i;
int n;