Skip to content

Commit 15f89a3

Browse files
authored
MONGOCRYPT-916 remove debug hex helper (#1176)
Addresses finding ID:8
1 parent 7c9bb66 commit 15f89a3

6 files changed

Lines changed: 17 additions & 62 deletions

src/mongocrypt-buffer-private.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ void _mongocrypt_buffer_copy_from_hex(_mongocrypt_buffer_t *buf, const char *hex
102102

103103
int _mongocrypt_buffer_cmp_hex(_mongocrypt_buffer_t *buf, const char *hex);
104104

105-
char *_mongocrypt_buffer_to_hex(_mongocrypt_buffer_t *buf) MONGOCRYPT_WARN_UNUSED_RESULT;
106-
107105
bool _mongocrypt_buffer_concat(_mongocrypt_buffer_t *dst, const _mongocrypt_buffer_t *srcs, uint32_t num_srcs);
108106

109107
struct _mongocrypt_binary_t *_mongocrypt_buffer_as_binary(_mongocrypt_buffer_t *buf);

src/mongocrypt-buffer.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -451,22 +451,6 @@ int _mongocrypt_buffer_cmp_hex(_mongocrypt_buffer_t *buf, const char *hex) {
451451
return res;
452452
}
453453

454-
char *_mongocrypt_buffer_to_hex(_mongocrypt_buffer_t *buf) {
455-
BSON_ASSERT_PARAM(buf);
456-
/* since buf->len is a uint32_t, even doubling it won't bring it anywhere
457-
* near to SIZE_MAX */
458-
459-
char *hex = bson_malloc0(buf->len * 2 + 1);
460-
BSON_ASSERT(hex);
461-
462-
char *out = hex;
463-
464-
for (uint32_t i = 0; i < buf->len; i++, out += 2) {
465-
BSON_ASSERT(2 == bson_snprintf(out, 3, "%02X", buf->data[i]));
466-
}
467-
return hex;
468-
}
469-
470454
bool _mongocrypt_buffer_concat(_mongocrypt_buffer_t *dst, const _mongocrypt_buffer_t *srcs, uint32_t num_srcs) {
471455
uint32_t total = 0;
472456
uint32_t offset;

src/mongocrypt-cache-key.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,6 @@ static void *_copy_contents(void *value) {
7171
return _mongocrypt_cache_key_value_new(key_value->key_doc, &key_value->decrypted_key_material);
7272
}
7373

74-
static void _dump_attr(void *attr_in) {
75-
_mongocrypt_cache_key_attr_t *attr;
76-
_mongocrypt_key_alt_name_t *altname;
77-
char *hex;
78-
79-
BSON_ASSERT_PARAM(attr_in);
80-
81-
attr = (_mongocrypt_cache_key_attr_t *)attr_in;
82-
hex = _mongocrypt_buffer_to_hex(&attr->id);
83-
printf("_id=%s,", hex);
84-
printf("keyAltNames=");
85-
for (altname = attr->alt_names; NULL != altname; altname = altname->next) {
86-
printf("%s\n", _mongocrypt_key_alt_name_get_string(altname));
87-
}
88-
bson_free(hex);
89-
}
90-
9174
_mongocrypt_cache_key_value_t *_mongocrypt_cache_key_value_new(_mongocrypt_key_doc_t *key_doc,
9275
_mongocrypt_buffer_t *decrypted_key_material) {
9376
_mongocrypt_cache_key_value_t *key_value;
@@ -126,7 +109,6 @@ void _mongocrypt_cache_key_init(_mongocrypt_cache_t *cache) {
126109
cache->destroy_attr = _destroy_attr;
127110
cache->copy_value = _copy_contents;
128111
cache->destroy_value = _mongocrypt_cache_key_value_destroy;
129-
cache->dump_attr = _dump_attr;
130112
_mongocrypt_mutex_init(&cache->mutex);
131113
cache->pair = NULL;
132114
cache->expiration = CACHE_EXPIRATION_MS_DEFAULT;

src/mongocrypt-cache-private.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ bool _mongocrypt_cache_add_stolen(_mongocrypt_cache_t *cache, void *attr, void *
6666

6767
void _mongocrypt_cache_cleanup(_mongocrypt_cache_t *cache);
6868

69-
/* A helper debug function to dump the state of the cache. */
70-
void _mongocrypt_cache_dump(_mongocrypt_cache_t *cache);
71-
7269
/* Tests may override the default expiration */
7370
void _mongocrypt_cache_set_expiration(_mongocrypt_cache_t *cache, uint64_t milli);
7471

src/mongocrypt-cache.c

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -249,28 +249,6 @@ void _mongocrypt_cache_cleanup(_mongocrypt_cache_t *cache) {
249249
}
250250
}
251251

252-
/* Print the contents of the cache (for debugging purposes) */
253-
void _mongocrypt_cache_dump(_mongocrypt_cache_t *cache) {
254-
_mongocrypt_cache_pair_t *pair;
255-
int count;
256-
257-
BSON_ASSERT_PARAM(cache);
258-
259-
_mongocrypt_mutex_lock(&cache->mutex);
260-
count = 0;
261-
for (pair = cache->pair; pair != NULL; pair = pair->next) {
262-
/* don't check that int64_t fits in int, since this is only diagnostic */
263-
printf("entry:%d last_updated:%d\n", count, (int)pair->last_updated);
264-
if (cache->dump_attr) {
265-
printf("- attr:");
266-
cache->dump_attr(pair->attr);
267-
}
268-
count++;
269-
}
270-
271-
_mongocrypt_mutex_unlock(&cache->mutex);
272-
}
273-
274252
uint32_t _mongocrypt_cache_num_entries(_mongocrypt_cache_t *cache) {
275253
_mongocrypt_cache_pair_t *pair;
276254
uint32_t count;

test/test-mongocrypt-crypto-hooks.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,28 @@ static char *call_history;
5353
} else \
5454
(void)0
5555

56+
static char *to_hex(_mongocrypt_buffer_t *buf) {
57+
BSON_ASSERT_PARAM(buf);
58+
59+
BSON_ASSERT(buf->len < (UINT32_MAX - 1) / 2);
60+
61+
char *hex = bson_malloc0(buf->len * 2 + 1);
62+
BSON_ASSERT(hex);
63+
64+
char *out = hex;
65+
66+
for (uint32_t i = 0; i < buf->len; i++, out += 2) {
67+
BSON_ASSERT(2 == bson_snprintf(out, 3, "%02X", buf->data[i]));
68+
}
69+
return hex;
70+
}
71+
5672
static void _append_bin(const char *name, mongocrypt_binary_t *bin) {
5773
_mongocrypt_buffer_t tmp;
5874
char *hex;
5975

6076
_mongocrypt_buffer_from_binary(&tmp, bin);
61-
hex = _mongocrypt_buffer_to_hex(&tmp);
77+
hex = to_hex(&tmp);
6278
APPEND_CALLHISTORY("%s:%s\n", name, hex);
6379
bson_free(hex);
6480
_mongocrypt_buffer_cleanup(&tmp);

0 commit comments

Comments
 (0)