From 6da92ded75b266d3136533c84b85c933031a5091 Mon Sep 17 00:00:00 2001 From: Juan Lang Date: Wed, 22 Feb 2006 16:26:52 -0800 Subject: [PATCH] crypt32: Move OIDToAlgID and AlgIDToOID to oid.c. --- dlls/crypt32/main.c | 90 --------------------------------- dlls/crypt32/oid.c | 90 +++++++++++++++++++++++++++++++++ dlls/crypt32/tests/main.c | 103 -------------------------------------- dlls/crypt32/tests/oid.c | 103 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 193 insertions(+), 193 deletions(-) diff --git a/dlls/crypt32/main.c b/dlls/crypt32/main.c index 6333f0ca95a..bc5c8c55780 100644 --- a/dlls/crypt32/main.c +++ b/dlls/crypt32/main.c @@ -218,96 +218,6 @@ BOOL WINAPI CryptSIPLoad return FALSE; } -struct OIDToAlgID -{ - LPCSTR oid; - DWORD algID; -}; - -static const struct OIDToAlgID oidToAlgID[] = { - { szOID_RSA_RSA, CALG_RSA_KEYX }, - { szOID_RSA_MD2RSA, CALG_MD2 }, - { szOID_RSA_MD4RSA, CALG_MD4 }, - { szOID_RSA_MD5RSA, CALG_MD5 }, - { szOID_RSA_SHA1RSA, CALG_SHA }, - { szOID_RSA_DH, CALG_DH_SF }, - { szOID_RSA_SMIMEalgESDH, CALG_DH_EPHEM }, - { szOID_RSA_SMIMEalgCMS3DESwrap, CALG_3DES }, - { szOID_RSA_SMIMEalgCMSRC2wrap, CALG_RC2 }, - { szOID_RSA_MD2, CALG_MD2 }, - { szOID_RSA_MD4, CALG_MD4 }, - { szOID_RSA_MD5, CALG_MD5 }, - { szOID_RSA_RC2CBC, CALG_RC2 }, - { szOID_RSA_RC4, CALG_RC4 }, - { szOID_RSA_DES_EDE3_CBC, CALG_3DES }, - { szOID_ANSI_X942_DH, CALG_DH_SF }, - { szOID_X957_DSA, CALG_DSS_SIGN }, - { szOID_X957_SHA1DSA, CALG_SHA }, - { szOID_OIWSEC_md4RSA, CALG_MD4 }, - { szOID_OIWSEC_md5RSA, CALG_MD5 }, - { szOID_OIWSEC_md4RSA2, CALG_MD4 }, - { szOID_OIWSEC_desCBC, CALG_DES }, - { szOID_OIWSEC_dsa, CALG_DSS_SIGN }, - { szOID_OIWSEC_shaDSA, CALG_SHA }, - { szOID_OIWSEC_shaRSA, CALG_SHA }, - { szOID_OIWSEC_sha, CALG_SHA }, - { szOID_OIWSEC_rsaXchg, CALG_RSA_KEYX }, - { szOID_OIWSEC_sha1, CALG_SHA }, - { szOID_OIWSEC_dsaSHA1, CALG_SHA }, - { szOID_OIWSEC_sha1RSASign, CALG_SHA }, - { szOID_OIWDIR_md2RSA, CALG_MD2 }, - { szOID_INFOSEC_mosaicUpdatedSig, CALG_SHA }, - { szOID_INFOSEC_mosaicKMandUpdSig, CALG_DSS_SIGN }, -}; - -LPCSTR WINAPI CertAlgIdToOID(DWORD dwAlgId) -{ - switch (dwAlgId) - { - case CALG_RSA_KEYX: - return szOID_RSA_RSA; - case CALG_DH_EPHEM: - return szOID_RSA_SMIMEalgESDH; - case CALG_MD2: - return szOID_RSA_MD2; - case CALG_MD4: - return szOID_RSA_MD4; - case CALG_MD5: - return szOID_RSA_MD5; - case CALG_RC2: - return szOID_RSA_RC2CBC; - case CALG_RC4: - return szOID_RSA_RC4; - case CALG_3DES: - return szOID_RSA_DES_EDE3_CBC; - case CALG_DH_SF: - return szOID_ANSI_X942_DH; - case CALG_DSS_SIGN: - return szOID_X957_DSA; - case CALG_DES: - return szOID_OIWSEC_desCBC; - case CALG_SHA: - return szOID_OIWSEC_sha1; - default: - return NULL; - } -} - -DWORD WINAPI CertOIDToAlgId(LPCSTR pszObjId) -{ - int i; - - if (pszObjId) - { - for (i = 0; i < sizeof(oidToAlgID) / sizeof(oidToAlgID[0]); i++) - { - if (!strcmp(pszObjId, oidToAlgID[i].oid)) - return oidToAlgID[i].algID; - } - } - return 0; -} - LPVOID WINAPI CryptMemAlloc(ULONG cbSize) { return HeapAlloc(GetProcessHeap(), 0, cbSize); diff --git a/dlls/crypt32/oid.c b/dlls/crypt32/oid.c index f474639e09d..f87af418b7a 100644 --- a/dlls/crypt32/oid.c +++ b/dlls/crypt32/oid.c @@ -571,3 +571,93 @@ BOOL WINAPI CryptSetOIDFunctionValue(DWORD dwEncodingType, LPCSTR pszFuncName, } return rc ? FALSE : TRUE; } + +struct OIDToAlgID +{ + LPCSTR oid; + DWORD algID; +}; + +static const struct OIDToAlgID oidToAlgID[] = { + { szOID_RSA_RSA, CALG_RSA_KEYX }, + { szOID_RSA_MD2RSA, CALG_MD2 }, + { szOID_RSA_MD4RSA, CALG_MD4 }, + { szOID_RSA_MD5RSA, CALG_MD5 }, + { szOID_RSA_SHA1RSA, CALG_SHA }, + { szOID_RSA_DH, CALG_DH_SF }, + { szOID_RSA_SMIMEalgESDH, CALG_DH_EPHEM }, + { szOID_RSA_SMIMEalgCMS3DESwrap, CALG_3DES }, + { szOID_RSA_SMIMEalgCMSRC2wrap, CALG_RC2 }, + { szOID_RSA_MD2, CALG_MD2 }, + { szOID_RSA_MD4, CALG_MD4 }, + { szOID_RSA_MD5, CALG_MD5 }, + { szOID_RSA_RC2CBC, CALG_RC2 }, + { szOID_RSA_RC4, CALG_RC4 }, + { szOID_RSA_DES_EDE3_CBC, CALG_3DES }, + { szOID_ANSI_X942_DH, CALG_DH_SF }, + { szOID_X957_DSA, CALG_DSS_SIGN }, + { szOID_X957_SHA1DSA, CALG_SHA }, + { szOID_OIWSEC_md4RSA, CALG_MD4 }, + { szOID_OIWSEC_md5RSA, CALG_MD5 }, + { szOID_OIWSEC_md4RSA2, CALG_MD4 }, + { szOID_OIWSEC_desCBC, CALG_DES }, + { szOID_OIWSEC_dsa, CALG_DSS_SIGN }, + { szOID_OIWSEC_shaDSA, CALG_SHA }, + { szOID_OIWSEC_shaRSA, CALG_SHA }, + { szOID_OIWSEC_sha, CALG_SHA }, + { szOID_OIWSEC_rsaXchg, CALG_RSA_KEYX }, + { szOID_OIWSEC_sha1, CALG_SHA }, + { szOID_OIWSEC_dsaSHA1, CALG_SHA }, + { szOID_OIWSEC_sha1RSASign, CALG_SHA }, + { szOID_OIWDIR_md2RSA, CALG_MD2 }, + { szOID_INFOSEC_mosaicUpdatedSig, CALG_SHA }, + { szOID_INFOSEC_mosaicKMandUpdSig, CALG_DSS_SIGN }, +}; + +LPCSTR WINAPI CertAlgIdToOID(DWORD dwAlgId) +{ + switch (dwAlgId) + { + case CALG_RSA_KEYX: + return szOID_RSA_RSA; + case CALG_DH_EPHEM: + return szOID_RSA_SMIMEalgESDH; + case CALG_MD2: + return szOID_RSA_MD2; + case CALG_MD4: + return szOID_RSA_MD4; + case CALG_MD5: + return szOID_RSA_MD5; + case CALG_RC2: + return szOID_RSA_RC2CBC; + case CALG_RC4: + return szOID_RSA_RC4; + case CALG_3DES: + return szOID_RSA_DES_EDE3_CBC; + case CALG_DH_SF: + return szOID_ANSI_X942_DH; + case CALG_DSS_SIGN: + return szOID_X957_DSA; + case CALG_DES: + return szOID_OIWSEC_desCBC; + case CALG_SHA: + return szOID_OIWSEC_sha1; + default: + return NULL; + } +} + +DWORD WINAPI CertOIDToAlgId(LPCSTR pszObjId) +{ + int i; + + if (pszObjId) + { + for (i = 0; i < sizeof(oidToAlgID) / sizeof(oidToAlgID[0]); i++) + { + if (!strcmp(pszObjId, oidToAlgID[i].oid)) + return oidToAlgID[i].algID; + } + } + return 0; +} diff --git a/dlls/crypt32/tests/main.c b/dlls/crypt32/tests/main.c index c3bea63a057..734378fde38 100644 --- a/dlls/crypt32/tests/main.c +++ b/dlls/crypt32/tests/main.c @@ -27,107 +27,6 @@ #include "wine/test.h" -struct OIDToAlgID -{ - LPCSTR oid; - DWORD algID; -}; - -static const struct OIDToAlgID oidToAlgID[] = { - { szOID_RSA_RSA, CALG_RSA_KEYX }, - { szOID_RSA_MD2RSA, CALG_MD2 }, - { szOID_RSA_MD4RSA, CALG_MD4 }, - { szOID_RSA_MD5RSA, CALG_MD5 }, - { szOID_RSA_SHA1RSA, CALG_SHA }, - { szOID_RSA_DH, CALG_DH_SF }, - { szOID_RSA_SMIMEalgESDH, CALG_DH_EPHEM }, - { szOID_RSA_SMIMEalgCMS3DESwrap, CALG_3DES }, - { szOID_RSA_SMIMEalgCMSRC2wrap, CALG_RC2 }, - { szOID_RSA_MD2, CALG_MD2 }, - { szOID_RSA_MD4, CALG_MD4 }, - { szOID_RSA_MD5, CALG_MD5 }, - { szOID_RSA_RC2CBC, CALG_RC2 }, - { szOID_RSA_RC4, CALG_RC4 }, - { szOID_RSA_DES_EDE3_CBC, CALG_3DES }, - { szOID_ANSI_X942_DH, CALG_DH_SF }, - { szOID_X957_DSA, CALG_DSS_SIGN }, - { szOID_X957_SHA1DSA, CALG_SHA }, - { szOID_OIWSEC_md4RSA, CALG_MD4 }, - { szOID_OIWSEC_md5RSA, CALG_MD5 }, - { szOID_OIWSEC_md4RSA2, CALG_MD4 }, - { szOID_OIWSEC_desCBC, CALG_DES }, - { szOID_OIWSEC_dsa, CALG_DSS_SIGN }, - { szOID_OIWSEC_shaDSA, CALG_SHA }, - { szOID_OIWSEC_shaRSA, CALG_SHA }, - { szOID_OIWSEC_sha, CALG_SHA }, - { szOID_OIWSEC_rsaXchg, CALG_RSA_KEYX }, - { szOID_OIWSEC_sha1, CALG_SHA }, - { szOID_OIWSEC_dsaSHA1, CALG_SHA }, - { szOID_OIWSEC_sha1RSASign, CALG_SHA }, - { szOID_OIWDIR_md2RSA, CALG_MD2 }, - { szOID_INFOSEC_mosaicUpdatedSig, CALG_SHA }, - { szOID_INFOSEC_mosaicKMandUpdSig, CALG_DSS_SIGN }, -}; - -static const struct OIDToAlgID algIDToOID[] = { - { szOID_RSA_RSA, CALG_RSA_KEYX }, - { szOID_RSA_SMIMEalgESDH, CALG_DH_EPHEM }, - { szOID_RSA_MD2, CALG_MD2 }, - { szOID_RSA_MD4, CALG_MD4 }, - { szOID_RSA_MD5, CALG_MD5 }, - { szOID_RSA_RC2CBC, CALG_RC2 }, - { szOID_RSA_RC4, CALG_RC4 }, - { szOID_RSA_DES_EDE3_CBC, CALG_3DES }, - { szOID_ANSI_X942_DH, CALG_DH_SF }, - { szOID_X957_DSA, CALG_DSS_SIGN }, - { szOID_OIWSEC_desCBC, CALG_DES }, - { szOID_OIWSEC_sha1, CALG_SHA }, -}; - -static void testOIDToAlgID(void) -{ - int i; - DWORD alg; - - /* Test with a bogus one */ - SetLastError(0xdeadbeef); - alg = CertOIDToAlgId("1.2.3"); - ok(!alg && (GetLastError() == 0xdeadbeef || - GetLastError() == ERROR_RESOURCE_NAME_NOT_FOUND), - "Expected ERROR_RESOURCE_NAME_NOT_FOUND or no error set, got %08lx\n", - GetLastError()); - - for (i = 0; i < sizeof(oidToAlgID) / sizeof(oidToAlgID[0]); i++) - { - alg = CertOIDToAlgId(oidToAlgID[i].oid); - /* Not all Windows installations support all these, so make sure it's - * at least not the wrong one. - */ - ok(alg == 0 || alg == oidToAlgID[i].algID, - "Expected %ld, got %ld\n", oidToAlgID[i].algID, alg); - } -} - -static void testAlgIDToOID(void) -{ - int i; - LPCSTR oid; - - /* Test with a bogus one */ - SetLastError(0xdeadbeef); - oid = CertAlgIdToOID(ALG_CLASS_SIGNATURE | ALG_TYPE_ANY | 80); - ok(!oid && GetLastError() == 0xdeadbeef, - "Didn't expect last error (%08lx) to be set\n", GetLastError()); - for (i = 0; i < sizeof(algIDToOID) / sizeof(algIDToOID[0]); i++) - { - oid = CertAlgIdToOID(algIDToOID[i].algID); - /* Allow failure, not every version of Windows supports every algo */ - if (oid) - ok(!strcmp(oid, algIDToOID[i].oid), - "Expected %s, got %s\n", algIDToOID[i].oid, oid); - } -} - static void test_findAttribute(void) { PCRYPT_ATTRIBUTE ret; @@ -374,8 +273,6 @@ static void test_cryptTls(void) START_TEST(main) { - testOIDToAlgID(); - testAlgIDToOID(); test_findAttribute(); test_findExtension(); test_findRDNAttr(); diff --git a/dlls/crypt32/tests/oid.c b/dlls/crypt32/tests/oid.c index d92bf5fc908..d44c66ddcc6 100644 --- a/dlls/crypt32/tests/oid.c +++ b/dlls/crypt32/tests/oid.c @@ -26,6 +26,107 @@ #include "wine/test.h" +struct OIDToAlgID +{ + LPCSTR oid; + DWORD algID; +}; + +static const struct OIDToAlgID oidToAlgID[] = { + { szOID_RSA_RSA, CALG_RSA_KEYX }, + { szOID_RSA_MD2RSA, CALG_MD2 }, + { szOID_RSA_MD4RSA, CALG_MD4 }, + { szOID_RSA_MD5RSA, CALG_MD5 }, + { szOID_RSA_SHA1RSA, CALG_SHA }, + { szOID_RSA_DH, CALG_DH_SF }, + { szOID_RSA_SMIMEalgESDH, CALG_DH_EPHEM }, + { szOID_RSA_SMIMEalgCMS3DESwrap, CALG_3DES }, + { szOID_RSA_SMIMEalgCMSRC2wrap, CALG_RC2 }, + { szOID_RSA_MD2, CALG_MD2 }, + { szOID_RSA_MD4, CALG_MD4 }, + { szOID_RSA_MD5, CALG_MD5 }, + { szOID_RSA_RC2CBC, CALG_RC2 }, + { szOID_RSA_RC4, CALG_RC4 }, + { szOID_RSA_DES_EDE3_CBC, CALG_3DES }, + { szOID_ANSI_X942_DH, CALG_DH_SF }, + { szOID_X957_DSA, CALG_DSS_SIGN }, + { szOID_X957_SHA1DSA, CALG_SHA }, + { szOID_OIWSEC_md4RSA, CALG_MD4 }, + { szOID_OIWSEC_md5RSA, CALG_MD5 }, + { szOID_OIWSEC_md4RSA2, CALG_MD4 }, + { szOID_OIWSEC_desCBC, CALG_DES }, + { szOID_OIWSEC_dsa, CALG_DSS_SIGN }, + { szOID_OIWSEC_shaDSA, CALG_SHA }, + { szOID_OIWSEC_shaRSA, CALG_SHA }, + { szOID_OIWSEC_sha, CALG_SHA }, + { szOID_OIWSEC_rsaXchg, CALG_RSA_KEYX }, + { szOID_OIWSEC_sha1, CALG_SHA }, + { szOID_OIWSEC_dsaSHA1, CALG_SHA }, + { szOID_OIWSEC_sha1RSASign, CALG_SHA }, + { szOID_OIWDIR_md2RSA, CALG_MD2 }, + { szOID_INFOSEC_mosaicUpdatedSig, CALG_SHA }, + { szOID_INFOSEC_mosaicKMandUpdSig, CALG_DSS_SIGN }, +}; + +static const struct OIDToAlgID algIDToOID[] = { + { szOID_RSA_RSA, CALG_RSA_KEYX }, + { szOID_RSA_SMIMEalgESDH, CALG_DH_EPHEM }, + { szOID_RSA_MD2, CALG_MD2 }, + { szOID_RSA_MD4, CALG_MD4 }, + { szOID_RSA_MD5, CALG_MD5 }, + { szOID_RSA_RC2CBC, CALG_RC2 }, + { szOID_RSA_RC4, CALG_RC4 }, + { szOID_RSA_DES_EDE3_CBC, CALG_3DES }, + { szOID_ANSI_X942_DH, CALG_DH_SF }, + { szOID_X957_DSA, CALG_DSS_SIGN }, + { szOID_OIWSEC_desCBC, CALG_DES }, + { szOID_OIWSEC_sha1, CALG_SHA }, +}; + +static void testOIDToAlgID(void) +{ + int i; + DWORD alg; + + /* Test with a bogus one */ + SetLastError(0xdeadbeef); + alg = CertOIDToAlgId("1.2.3"); + ok(!alg && (GetLastError() == 0xdeadbeef || + GetLastError() == ERROR_RESOURCE_NAME_NOT_FOUND), + "Expected ERROR_RESOURCE_NAME_NOT_FOUND or no error set, got %08lx\n", + GetLastError()); + + for (i = 0; i < sizeof(oidToAlgID) / sizeof(oidToAlgID[0]); i++) + { + alg = CertOIDToAlgId(oidToAlgID[i].oid); + /* Not all Windows installations support all these, so make sure it's + * at least not the wrong one. + */ + ok(alg == 0 || alg == oidToAlgID[i].algID, + "Expected %ld, got %ld\n", oidToAlgID[i].algID, alg); + } +} + +static void testAlgIDToOID(void) +{ + int i; + LPCSTR oid; + + /* Test with a bogus one */ + SetLastError(0xdeadbeef); + oid = CertAlgIdToOID(ALG_CLASS_SIGNATURE | ALG_TYPE_ANY | 80); + ok(!oid && GetLastError() == 0xdeadbeef, + "Didn't expect last error (%08lx) to be set\n", GetLastError()); + for (i = 0; i < sizeof(algIDToOID) / sizeof(algIDToOID[0]); i++) + { + oid = CertAlgIdToOID(algIDToOID[i].algID); + /* Allow failure, not every version of Windows supports every algo */ + if (oid) + ok(!strcmp(oid, algIDToOID[i].oid), + "Expected %s, got %s\n", algIDToOID[i].oid, oid); + } +} + static void test_oidFunctionSet(void) { HCRYPTOIDFUNCSET set1, set2; @@ -215,6 +316,8 @@ static void test_registerOIDFunction(void) START_TEST(oid) { + testOIDToAlgID(); + testAlgIDToOID(); test_oidFunctionSet(); test_installOIDFunctionAddress(); test_registerOIDFunction();