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.
This commit is contained in:
Thomas Haller 2018-08-30 12:32:29 +02:00
parent 639e6de6e3
commit 9153d9e2ea
2 changed files with 36 additions and 30 deletions

View file

@ -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);

View file

@ -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__ */