From 53cb28e6d9daa7cbcc190cd02aeaba37c297adc4 Mon Sep 17 00:00:00 2001 From: Santino Mazza Date: Mon, 21 Feb 2022 12:13:44 +0100 Subject: [PATCH] ncrypt/tests: Test for NCryptSetProperty. Signed-off-by: Santino Mazza Signed-off-by: Hans Leidekker Signed-off-by: Alexandre Julliard --- dlls/ncrypt/tests/ncrypt.c | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/dlls/ncrypt/tests/ncrypt.c b/dlls/ncrypt/tests/ncrypt.c index 58173fd0ff0..d1bcbbcab2a 100644 --- a/dlls/ncrypt/tests/ncrypt.c +++ b/dlls/ncrypt/tests/ncrypt.c @@ -205,6 +205,51 @@ static void test_get_property(void) NCryptFreeObject(prov); } +static void test_set_property(void) +{ + NCRYPT_PROV_HANDLE prov; + SECURITY_STATUS ret; + NCRYPT_KEY_HANDLE key; + DWORD keylength; + + ret = NCryptOpenStorageProvider(&prov, NULL, 0); + ok(ret == ERROR_SUCCESS, "got %#lx\n", ret); + + ret = NCryptImportKey(prov, 0, BCRYPT_RSAPUBLIC_BLOB, NULL, &key, rsa_key_blob, sizeof(rsa_key_blob), 0); + ok(ret == ERROR_SUCCESS, "got %#lx\n", ret); + + keylength = 2048; + ret = NCryptSetProperty(key, NCRYPT_LENGTH_PROPERTY, (BYTE *)&keylength, sizeof(keylength), 0); + ok(ret == ERROR_SUCCESS || broken(ret == NTE_INVALID_HANDLE), "got %#lx\n", ret); + + ret = NCryptSetProperty(0, NCRYPT_LENGTH_PROPERTY, (BYTE *)&keylength, sizeof(keylength), 0); + ok(ret == NTE_INVALID_HANDLE, "got %#lx\n", ret); + + todo_wine + { + ret = NCryptSetProperty(key, NCRYPT_NAME_PROPERTY, (BYTE *)L"Key name", sizeof(L"Key name"), 0); + ok(ret == NTE_NOT_SUPPORTED, "got %#lx\n", ret); + NCryptFreeObject(key); + + key = 0; + ret = NCryptCreatePersistedKey(prov, &key, BCRYPT_RSA_ALGORITHM, NULL, 0, 0); + ok(ret == ERROR_SUCCESS, "got %#lx\n", ret); + ok(key, "got null handle\n"); + + keylength = 2048; + ret = NCryptSetProperty(key, NCRYPT_LENGTH_PROPERTY, (BYTE *)&keylength, sizeof(keylength), 0); + ok(ret == ERROR_SUCCESS, "got %#lx\n", ret); + + ret = NCryptSetProperty(key, NCRYPT_NAME_PROPERTY, (BYTE *)L"Key name", sizeof(L"Key name"), 0); + ok(ret == NTE_NOT_SUPPORTED, "got %#lx\n", ret); + + ret = NCryptSetProperty(key, L"My Custom Property", (BYTE *)L"value", sizeof(L"value"), 0); + ok(ret == NTE_NOT_SUPPORTED, "got %#lx\n", ret); + } + NCryptFreeObject(key); + NCryptFreeObject(prov); +} + static void test_create_persisted_key(void) { NCRYPT_PROV_HANDLE prov; @@ -255,5 +300,6 @@ START_TEST(ncrypt) test_key_import_rsa(); test_free_object(); test_get_property(); + test_set_property(); test_create_persisted_key(); }