From 9153d9e2ea2a696221c4b160625c3b7f7f8753a7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 30 Aug 2018 12:32:29 +0200 Subject: [PATCH] libnm-core/trivial: rename testing related functions in crypto code In nm-crypto.c we have functions that are only called from tests. Maybe these functions should move away from libnm-core to the test. Leave it, but at least rename them to make it clear that these functions are not relevant for libnm's actual usage. For a reviewer that makes a big difference as crypto functions in libnm have a significantly higher requirement for quality. There is nothing new here. We already have other *nmtst* functions beside our regular code. The concention is, that functions that are only for testing are named explicitly ("nmtst"), and that they can only be called by test functions themselves. --- libnm-core/nm-crypto.c | 40 ++++++++++++++++++++-------------------- libnm-core/nm-crypto.h | 26 ++++++++++++++++---------- 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/libnm-core/nm-crypto.c b/libnm-core/nm-crypto.c index ab52c94d69..c529cf458d 100644 --- a/libnm-core/nm-crypto.c +++ b/libnm-core/nm-crypto.c @@ -355,9 +355,9 @@ file_read_contents (const char *filename, * Convert a hex string into bytes. */ static guint8 * -convert_iv (const char *src, - gsize *out_len, - GError **error) +_nmtst_convert_iv (const char *src, + gsize *out_len, + GError **error) { gsize i, num; gs_free guint8 *c = NULL; @@ -451,14 +451,14 @@ nm_crypto_make_des_aes_key (const char *cipher, } static gboolean -decrypt_key (const char *cipher, - int key_type, - const guint8 *data, - gsize data_len, - const char *iv, - const char *password, - NMSecretPtr *parsed, - GError **error) +_nmtst_crypto_decrypt_key (const char *cipher, + int key_type, + const guint8 *data, + gsize data_len, + const char *iv, + const char *password, + NMSecretPtr *parsed, + GError **error) { nm_auto_clear_secret_ptr NMSecretPtr bin_iv = { 0 }; nm_auto_clear_secret_ptr NMSecretPtr key = { 0 }; @@ -471,7 +471,7 @@ decrypt_key (const char *cipher, nm_assert (!parsed->bin); nm_assert (parsed->len == 0); - bin_iv.bin = convert_iv (iv, &bin_iv.len, error); + bin_iv.bin = _nmtst_convert_iv (iv, &bin_iv.len, error); if (!bin_iv.bin) return FALSE; @@ -544,14 +544,14 @@ nmtst_crypto_decrypt_openssl_private_key_data (const guint8 *data, return NULL; } - if (!decrypt_key (cipher, - key_type, - parsed.bin, - parsed.len, - iv, - password, - &parsed2, - error)) + if (!_nmtst_crypto_decrypt_key (cipher, + key_type, + parsed.bin, + parsed.len, + iv, + password, + &parsed2, + error)) return NULL; return nm_secret_copy_to_gbytes (parsed2.bin, parsed2.len); diff --git a/libnm-core/nm-crypto.h b/libnm-core/nm-crypto.h index 88fec819e7..2b56f4371b 100644 --- a/libnm-core/nm-crypto.h +++ b/libnm-core/nm-crypto.h @@ -49,16 +49,7 @@ typedef enum { NM_CRYPTO_FILE_FORMAT_PKCS12 } NMCryptoFileFormat; -GBytes *nmtst_crypto_decrypt_openssl_private_key_data (const guint8 *data, - gsize data_len, - const char *password, - NMCryptoKeyType *out_key_type, - GError **error); - -GBytes *nmtst_crypto_decrypt_openssl_private_key (const char *file, - const char *password, - NMCryptoKeyType *out_key_type, - GError **error); +/*****************************************************************************/ gboolean nm_crypto_load_and_verify_certificate (const char *file, NMCryptoFileFormat *out_file_format, @@ -106,4 +97,19 @@ char * nm_crypto_encrypt (const char *cipher, gboolean nm_crypto_randomize (void *buffer, gsize buffer_len, GError **error); +/*****************************************************************************/ + +GBytes *nmtst_crypto_decrypt_openssl_private_key_data (const guint8 *data, + gsize data_len, + const char *password, + NMCryptoKeyType *out_key_type, + GError **error); + +GBytes *nmtst_crypto_decrypt_openssl_private_key (const char *file, + const char *password, + NMCryptoKeyType *out_key_type, + GError **error); + +/*****************************************************************************/ + #endif /* __NM_CRYPTO_H__ */