mirror of
https://github.com/postgres/postgres.git
synced 2025-11-16 15:02:33 +03:00
Use 'void *' for arbitrary buffers, 'uint8 *' for byte arrays
A 'void *' argument suggests that the caller might pass an arbitrary struct, which is appropriate for functions like libc's read/write, or pq_sendbytes(). 'uint8 *' is more appropriate for byte arrays that have no structure, like the cancellation keys or SCRAM tokens. Some places used 'char *', but 'uint8 *' is better because 'char *' is commonly used for null-terminated strings. Change code around SCRAM, MD5 authentication, and cancellation key handling to follow these conventions. Discussion: https://www.postgresql.org/message-id/61be9e31-7b7d-49d5-bc11-721800d89d64@eisentraut.org
This commit is contained in:
@@ -41,15 +41,15 @@ static const int8 b64lookup[128] = {
|
||||
/*
|
||||
* pg_b64_encode
|
||||
*
|
||||
* Encode into base64 the given string. Returns the length of the encoded
|
||||
* string, and -1 in the event of an error with the result buffer zeroed
|
||||
* for safety.
|
||||
* Encode the 'src' byte array into base64. Returns the length of the encoded
|
||||
* string, and -1 in the event of an error with the result buffer zeroed for
|
||||
* safety.
|
||||
*/
|
||||
int
|
||||
pg_b64_encode(const char *src, int len, char *dst, int dstlen)
|
||||
pg_b64_encode(const uint8 *src, int len, char *dst, int dstlen)
|
||||
{
|
||||
char *p;
|
||||
const char *s,
|
||||
const uint8 *s,
|
||||
*end = src + len;
|
||||
int pos = 2;
|
||||
uint32 buf = 0;
|
||||
@@ -59,7 +59,7 @@ pg_b64_encode(const char *src, int len, char *dst, int dstlen)
|
||||
|
||||
while (s < end)
|
||||
{
|
||||
buf |= (unsigned char) *s << (pos << 3);
|
||||
buf |= *s << (pos << 3);
|
||||
pos--;
|
||||
s++;
|
||||
|
||||
@@ -113,11 +113,11 @@ error:
|
||||
* buffer zeroed for safety.
|
||||
*/
|
||||
int
|
||||
pg_b64_decode(const char *src, int len, char *dst, int dstlen)
|
||||
pg_b64_decode(const char *src, int len, uint8 *dst, int dstlen)
|
||||
{
|
||||
const char *srcend = src + len,
|
||||
*s = src;
|
||||
char *p = dst;
|
||||
uint8 *p = dst;
|
||||
char c;
|
||||
int b = 0;
|
||||
uint32 buf = 0;
|
||||
|
||||
Reference in New Issue
Block a user