1
0
Fork 0
mirror of https://github.com/deltachat/deltachat-core.git synced 2025-10-05 19:42:04 +02:00

split binary-fingerprint-to-hex from get-fingerprint-function

This commit is contained in:
B. Petersen 2018-04-29 01:38:07 +02:00
parent 53e3bbd6ee
commit bbf329f9ba
2 changed files with 20 additions and 9 deletions

View file

@ -475,12 +475,29 @@ char* mr_normalize_fingerprint(const char* in)
}
char* mr_binary_fingerprint_to_uc_hex(const uint8_t* fingerprint_buf, size_t fingerprint_bytes)
{
char* fingerprint_hex = NULL;
int i;
if( (fingerprint_hex=calloc(1, fingerprint_bytes*2+1))==NULL ) {
goto cleanup;
}
for( i = 0; i < fingerprint_bytes; i++ ) {
snprintf(&fingerprint_hex[i*2], 3, "%02X", (int)fingerprint_buf[i]); /* 'X' instead of 'x' ensures the fingerprint is uppercase which is needed as we do not search case-insensitive, see comment in mrsqlite3.c */
}
cleanup:
return fingerprint_hex;
}
char* mrkey_get_fingerprint(const mrkey_t* key)
{
uint8_t* fingerprint_buf = NULL;
size_t fingerprint_bytes = 0;
char* fingerprint_hex = NULL;
int i;
if( key == NULL ) {
goto cleanup;
@ -490,13 +507,7 @@ char* mrkey_get_fingerprint(const mrkey_t* key)
goto cleanup;
}
if( (fingerprint_hex=calloc(1, fingerprint_bytes*2+1))==NULL ) {
goto cleanup;
}
for( i = 0; i < fingerprint_bytes; i++ ) {
snprintf(&fingerprint_hex[i*2], 3, "%02X", (int)fingerprint_buf[i]); /* 'X' instead of 'x' ensures the fingerprint is uppercase which is needed as we do not search case-insensitive, see comment in mrsqlite3.c */
}
fingerprint_hex = mr_binary_fingerprint_to_uc_hex(fingerprint_buf, fingerprint_bytes);
cleanup:
free(fingerprint_buf);

View file

@ -76,7 +76,7 @@ char* mrkey_get_fingerprint (const mrkey_t*);
char* mrkey_get_formatted_fingerprint(const mrkey_t*);
void mr_wipe_secret_mem(void* buf, size_t buf_bytes);
char* mr_binary_fingerprint_to_uc_hex(const uint8_t* fingerprint_buf, size_t fingerprint_bytes);
#ifdef __cplusplus
} /* /extern "C" */