summary refs log tree commit diff
path: root/src/libnm-core-impl/tests/test-crypto.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2022-05-04 15:35:24 +0200
committerMichael Biebl <biebl@debian.org>2022-05-04 15:35:24 +0200
commit9959fdb2e8ddd06f2161798ca0a39c77d67c652d (patch)
tree2ce24a336d2b1c5fd5dec3090db312eded6c78ba /src/libnm-core-impl/tests/test-crypto.c
parent8c623dddbdebe354cb94bfc559a5371a14865317 (diff)
New upstream version 1.37.92 upstream/1.37.92
Diffstat (limited to 'src/libnm-core-impl/tests/test-crypto.c')
-rw-r--r--src/libnm-core-impl/tests/test-crypto.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/src/libnm-core-impl/tests/test-crypto.c b/src/libnm-core-impl/tests/test-crypto.c
index 6a6e7fbc..896c3c2e 100644
--- a/src/libnm-core-impl/tests/test-crypto.c
+++ b/src/libnm-core-impl/tests/test-crypto.c
@@ -10,7 +10,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 
-#include "nm-crypto-impl.h"
+#include "libnm-crypto/nm-crypto-impl.h"
 #include "nm-utils.h"
 #include "nm-errors.h"
 #include "libnm-core-intern/nm-core-internal.h"
@@ -92,7 +92,7 @@ test_cert(gconstpointer test_data)
     nmtst_assert_success(success, error);
     g_assert_cmpint(format, ==, NM_CRYPTO_FILE_FORMAT_X509);
 
-    g_assert(nm_utils_file_is_certificate(path));
+    g_assert(nm_crypto_utils_file_is_certificate(path));
 }
 
 static void
@@ -106,7 +106,7 @@ test_load_private_key(const char *path,
     gs_unref_bytes GBytes *array        = NULL;
     GError                *error        = NULL;
 
-    g_assert(nm_utils_file_is_private_key(path, &is_encrypted));
+    g_assert(nm_crypto_utils_file_is_private_key(path, &is_encrypted));
     g_assert(is_encrypted);
 
     array = nmtst_crypto_decrypt_openssl_private_key(path, password, &key_type, &error);
@@ -146,7 +146,7 @@ test_load_pkcs12(const char *path, const char *password, int expected_error)
     gboolean           is_encrypted = FALSE;
     GError            *error        = NULL;
 
-    g_assert(nm_utils_file_is_private_key(path, NULL));
+    g_assert(nm_crypto_utils_file_is_private_key(path, NULL));
 
     format = nm_crypto_verify_private_key(path, password, &is_encrypted, &error);
     if (expected_error != -1) {
@@ -167,7 +167,7 @@ test_load_pkcs12_no_password(const char *path)
     gboolean           is_encrypted = FALSE;
     GError            *error        = NULL;
 
-    g_assert(nm_utils_file_is_private_key(path, NULL));
+    g_assert(nm_crypto_utils_file_is_private_key(path, NULL));
 
     /* We should still get a valid returned crypto file format */
     format = nm_crypto_verify_private_key(path, NULL, &is_encrypted, &error);
@@ -201,7 +201,7 @@ test_load_pkcs8(const char *path, const char *password, int expected_error)
     gboolean           is_encrypted = FALSE;
     GError            *error        = NULL;
 
-    g_assert(nm_utils_file_is_private_key(path, NULL));
+    g_assert(nm_crypto_utils_file_is_private_key(path, NULL));
 
     format = nm_crypto_verify_private_key(path, password, &is_encrypted, &error);
     if (expected_error != -1) {
@@ -285,7 +285,7 @@ test_key_decrypted(gconstpointer test_data)
 
     path = g_build_filename(TEST_CERT_DIR, file, NULL);
 
-    g_assert(nm_utils_file_is_private_key(path, &is_encrypted));
+    g_assert(nm_crypto_utils_file_is_private_key(path, &is_encrypted));
     g_assert(!is_encrypted);
 
     g_free(path);
@@ -399,6 +399,23 @@ test_md5(void)
     }
 }
 
+/*****************************************************************************/
+
+static void
+test_crypto_error(void)
+{
+    G_STATIC_ASSERT(NM_CRYPTO_ERROR_FAILED == _NM_CRYPTO_ERROR_FAILED);
+    G_STATIC_ASSERT(NM_CRYPTO_ERROR_INVALID_DATA == _NM_CRYPTO_ERROR_INVALID_DATA);
+    G_STATIC_ASSERT(NM_CRYPTO_ERROR_INVALID_PASSWORD == _NM_CRYPTO_ERROR_INVALID_PASSWORD);
+    G_STATIC_ASSERT(NM_CRYPTO_ERROR_UNKNOWN_CIPHER == _NM_CRYPTO_ERROR_UNKNOWN_CIPHER);
+    G_STATIC_ASSERT(NM_CRYPTO_ERROR_DECRYPTION_FAILED == _NM_CRYPTO_ERROR_DECRYPTION_FAILED);
+    G_STATIC_ASSERT(NM_CRYPTO_ERROR_ENCRYPTION_FAILED == _NM_CRYPTO_ERROR_ENCRYPTION_FAILED);
+
+    g_assert_cmpint(NM_CRYPTO_ERROR, ==, _NM_CRYPTO_ERROR);
+}
+
+/*****************************************************************************/
+
 NMTST_DEFINE();
 
 int
@@ -448,6 +465,7 @@ main(int argc, char **argv)
     g_test_add_data_func("/libnm/crypto/PKCS#8", "pkcs8-enc-key.pem, 1234567890", test_pkcs8);
 
     g_test_add_func("/libnm/crypto/md5", test_md5);
+    g_test_add_func("/libnm/crypto/error", test_crypto_error);
 
     ret = g_test_run();