Skip to content

Commit fcfe613

Browse files
committed
CDRIVER-508 namespace b64_ functions
We really shouldn't be kicking around non-static b64_ functions. Namespace them all and let's be done with it.
1 parent 224a27e commit fcfe613

File tree

4 files changed

+55
-55
lines changed

4 files changed

+55
-55
lines changed

src/mongoc/mongoc-b64-private.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@
2626
#include "mongoc-config.h"
2727

2828
int
29-
b64_ntop (uint8_t const *src,
30-
size_t srclength,
31-
char *target,
32-
size_t targsize);
29+
mongoc_b64_ntop (uint8_t const *src,
30+
size_t srclength,
31+
char *target,
32+
size_t targsize);
3333

3434
void
35-
b64_initialize_rmap (void);
35+
mongoc_b64_initialize_rmap (void);
3636

3737
#ifdef MONGOC_ENABLE_SSL
3838
int
39-
b64_pton (char const *src,
40-
uint8_t *target,
41-
size_t targsize);
39+
mongoc_b64_pton (char const *src,
40+
uint8_t *target,
41+
size_t targsize);
4242
#endif
4343

4444
#endif /* MONGOC_B64_PRIVATE_H */

src/mongoc/mongoc-b64.c

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ static const char Pad64 = '=';
111111
*/
112112

113113
int
114-
b64_ntop (uint8_t const *src,
115-
size_t srclength,
116-
char *target,
117-
size_t targsize)
114+
mongoc_b64_ntop (uint8_t const *src,
115+
size_t srclength,
116+
char *target,
117+
size_t targsize)
118118
{
119119
size_t datalength = 0;
120120
uint8_t input[3];
@@ -251,49 +251,49 @@ b64_ntop (uint8_t const *src,
251251
it returns the number of data bytes stored at the target, or -1 on error.
252252
*/
253253

254-
static int b64rmap_initialized = 0;
255-
static uint8_t b64rmap[256];
254+
static int mongoc_b64rmap_initialized = 0;
255+
static uint8_t mongoc_b64rmap[256];
256256

257-
static const uint8_t b64rmap_special = 0xf0;
258-
static const uint8_t b64rmap_end = 0xfd;
259-
static const uint8_t b64rmap_space = 0xfe;
260-
static const uint8_t b64rmap_invalid = 0xff;
257+
static const uint8_t mongoc_b64rmap_special = 0xf0;
258+
static const uint8_t mongoc_b64rmap_end = 0xfd;
259+
static const uint8_t mongoc_b64rmap_space = 0xfe;
260+
static const uint8_t mongoc_b64rmap_invalid = 0xff;
261261

262262
/**
263263
* Initializing the reverse map is not thread safe.
264264
* Which is fine for NSD. For now...
265265
**/
266266
void
267-
b64_initialize_rmap (void)
267+
mongoc_b64_initialize_rmap (void)
268268
{
269269
int i;
270270
unsigned char ch;
271271

272272
/* Null: end of string, stop parsing */
273-
b64rmap[0] = b64rmap_end;
273+
mongoc_b64rmap[0] = mongoc_b64rmap_end;
274274

275275
for (i = 1; i < 256; ++i) {
276276
ch = (unsigned char)i;
277277
/* Whitespaces */
278278
if (isspace(ch))
279-
b64rmap[i] = b64rmap_space;
279+
mongoc_b64rmap[i] = mongoc_b64rmap_space;
280280
/* Padding: stop parsing */
281281
else if (ch == Pad64)
282-
b64rmap[i] = b64rmap_end;
282+
mongoc_b64rmap[i] = mongoc_b64rmap_end;
283283
/* Non-base64 char */
284284
else
285-
b64rmap[i] = b64rmap_invalid;
285+
mongoc_b64rmap[i] = mongoc_b64rmap_invalid;
286286
}
287287

288288
/* Fill reverse mapping for base64 chars */
289289
for (i = 0; Base64[i] != '\0'; ++i)
290-
b64rmap[(uint8_t)Base64[i]] = i;
290+
mongoc_b64rmap[(uint8_t)Base64[i]] = i;
291291

292-
b64rmap_initialized = 1;
292+
mongoc_b64rmap_initialized = 1;
293293
}
294294

295295
static int
296-
b64_pton_do(char const *src, uint8_t *target, size_t targsize)
296+
mongoc_b64_pton_do(char const *src, uint8_t *target, size_t targsize)
297297
{
298298
int tarindex, state, ch;
299299
uint8_t ofs;
@@ -304,14 +304,14 @@ b64_pton_do(char const *src, uint8_t *target, size_t targsize)
304304
while (1)
305305
{
306306
ch = *src++;
307-
ofs = b64rmap[ch];
307+
ofs = mongoc_b64rmap[ch];
308308

309-
if (ofs >= b64rmap_special) {
309+
if (ofs >= mongoc_b64rmap_special) {
310310
/* Ignore whitespaces */
311-
if (ofs == b64rmap_space)
311+
if (ofs == mongoc_b64rmap_space)
312312
continue;
313313
/* End of base64 characters */
314-
if (ofs == b64rmap_end)
314+
if (ofs == mongoc_b64rmap_end)
315315
break;
316316
/* A non-base64 character. */
317317
return (-1);
@@ -369,7 +369,7 @@ b64_pton_do(char const *src, uint8_t *target, size_t targsize)
369369
case 2: /* Valid, means one byte of info */
370370
/* Skip any number of spaces. */
371371
for ((void)NULL; ch != '\0'; ch = *src++)
372-
if (b64rmap[ch] != b64rmap_space)
372+
if (mongoc_b64rmap[ch] != mongoc_b64rmap_space)
373373
break;
374374
/* Make sure there is another trailing = sign. */
375375
if (ch != Pad64)
@@ -384,7 +384,7 @@ b64_pton_do(char const *src, uint8_t *target, size_t targsize)
384384
* whitespace after it?
385385
*/
386386
for ((void)NULL; ch != '\0'; ch = *src++)
387-
if (b64rmap[ch] != b64rmap_space)
387+
if (mongoc_b64rmap[ch] != mongoc_b64rmap_space)
388388
return (-1);
389389

390390
/*
@@ -412,7 +412,7 @@ b64_pton_do(char const *src, uint8_t *target, size_t targsize)
412412

413413

414414
static int
415-
b64_pton_len(char const *src)
415+
mongoc_b64_pton_len(char const *src)
416416
{
417417
int tarindex, state, ch;
418418
uint8_t ofs;
@@ -423,14 +423,14 @@ b64_pton_len(char const *src)
423423
while (1)
424424
{
425425
ch = *src++;
426-
ofs = b64rmap[ch];
426+
ofs = mongoc_b64rmap[ch];
427427

428-
if (ofs >= b64rmap_special) {
428+
if (ofs >= mongoc_b64rmap_special) {
429429
/* Ignore whitespaces */
430-
if (ofs == b64rmap_space)
430+
if (ofs == mongoc_b64rmap_space)
431431
continue;
432432
/* End of base64 characters */
433-
if (ofs == b64rmap_end)
433+
if (ofs == mongoc_b64rmap_end)
434434
break;
435435
/* A non-base64 character. */
436436
return (-1);
@@ -472,7 +472,7 @@ b64_pton_len(char const *src)
472472
case 2: /* Valid, means one byte of info */
473473
/* Skip any number of spaces. */
474474
for ((void)NULL; ch != '\0'; ch = *src++)
475-
if (b64rmap[ch] != b64rmap_space)
475+
if (mongoc_b64rmap[ch] != mongoc_b64rmap_space)
476476
break;
477477
/* Make sure there is another trailing = sign. */
478478
if (ch != Pad64)
@@ -487,7 +487,7 @@ b64_pton_len(char const *src)
487487
* whitespace after it?
488488
*/
489489
for ((void)NULL; ch != '\0'; ch = *src++)
490-
if (b64rmap[ch] != b64rmap_space)
490+
if (mongoc_b64rmap[ch] != mongoc_b64rmap_space)
491491
return (-1);
492492

493493
default:
@@ -507,15 +507,15 @@ b64_pton_len(char const *src)
507507

508508

509509
int
510-
b64_pton(char const *src, uint8_t *target, size_t targsize)
510+
mongoc_b64_pton(char const *src, uint8_t *target, size_t targsize)
511511
{
512-
if (!b64rmap_initialized)
513-
b64_initialize_rmap ();
512+
if (!mongoc_b64rmap_initialized)
513+
mongoc_b64_initialize_rmap ();
514514

515515
if (target)
516-
return b64_pton_do (src, target, targsize);
516+
return mongoc_b64_pton_do (src, target, targsize);
517517
else
518-
return b64_pton_len (src);
518+
return mongoc_b64_pton_len (src);
519519
}
520520

521521
#endif /* MONGOC_ENABLE_SSL */

src/mongoc/mongoc-cluster.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1605,7 +1605,7 @@ _mongoc_cluster_auth_node_plain (mongoc_cluster_t *cluster,
16051605

16061606
str = bson_strdup_printf ("%c%s%c%s", '\0', username, '\0', password);
16071607
len = strlen (username) + strlen (password) + 2;
1608-
buflen = b64_ntop ((const uint8_t *) str, len, buf, sizeof buf);
1608+
buflen = mongoc_b64_ntop ((const uint8_t *) str, len, buf, sizeof buf);
16091609
bson_free (str);
16101610

16111611
if (buflen == -1) {

src/mongoc/mongoc-scram.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
void
4343
_mongoc_scram_startup()
4444
{
45-
b64_initialize_rmap();
45+
mongoc_b64_initialize_rmap();
4646
}
4747

4848

@@ -153,8 +153,8 @@ _mongoc_scram_start (mongoc_scram_t *scram,
153153
}
154154

155155
scram->encoded_nonce_len =
156-
b64_ntop (nonce, sizeof (nonce), scram->encoded_nonce,
157-
sizeof (scram->encoded_nonce));
156+
mongoc_b64_ntop (nonce, sizeof (nonce), scram->encoded_nonce,
157+
sizeof (scram->encoded_nonce));
158158

159159
if (-1 == scram->encoded_nonce_len) {
160160
bson_set_error (error,
@@ -344,9 +344,9 @@ _mongoc_scram_generate_client_proof (mongoc_scram_t *scram,
344344
client_proof[i] = client_key[i] ^ client_signature[i];
345345
}
346346

347-
r = b64_ntop (client_proof, sizeof (client_proof),
348-
(char *)outbuf + *outbuflen,
349-
outbufmax - *outbuflen);
347+
r = mongoc_b64_ntop (client_proof, sizeof (client_proof),
348+
(char *)outbuf + *outbuflen,
349+
outbufmax - *outbuflen);
350350

351351
if (-1 == r) {
352352
return false;
@@ -534,7 +534,7 @@ _mongoc_scram_step2 (mongoc_scram_t *scram,
534534
}
535535

536536
decoded_salt_len =
537-
b64_pton ((char *)val_s, decoded_salt, sizeof (decoded_salt));
537+
mongoc_b64_pton ((char *)val_s, decoded_salt, sizeof (decoded_salt));
538538

539539
if (-1 == decoded_salt_len) {
540540
bson_set_error (error,
@@ -635,9 +635,9 @@ _mongoc_scram_verify_server_signature (mongoc_scram_t *scram,
635635
&hash_len);
636636

637637
encoded_server_signature_len =
638-
b64_ntop (server_signature, sizeof (server_signature),
639-
encoded_server_signature,
640-
sizeof (encoded_server_signature));
638+
mongoc_b64_ntop (server_signature, sizeof (server_signature),
639+
encoded_server_signature,
640+
sizeof (encoded_server_signature));
641641

642642
return (len == encoded_server_signature_len) &&
643643
(memcmp (verification, encoded_server_signature, len) == 0);

0 commit comments

Comments
 (0)