2 * Unit test suite for crypt32.dll's CryptEncodeObjectEx
4 * Copyright 2005 Juan Lang
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "wine/test.h"
35 static void test_encodeint(void)
37 static const struct encodedInt ints
[] = {
39 { 127, { 2, 1, 0x7f } },
40 { 128, { 2, 2, 0x00, 0x80 } },
41 { 256, { 2, 2, 0x01, 0x00 } },
42 { -128, { 2, 1, 0x80 } },
43 { -129, { 2, 2, 0xff, 0x7f } },
44 { 0xbaddf00d, { 2, 4, 0xba, 0xdd, 0xf0, 0x0d } },
50 /* CryptEncodeObjectEx with NULL bufSize crashes..
51 ret = CryptEncodeObjectEx(3, X509_INTEGER, &ints[0].val, 0, NULL, NULL,
54 /* check bogus encoding */
55 ret
= CryptEncodeObjectEx(0, X509_INTEGER
, &ints
[0].val
, 0, NULL
, NULL
,
57 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
,
58 "Expected ERROR_FILE_NOT_FOUND, got %ld\n", GetLastError());
59 /* check with NULL integer buffer. Windows XP incorrectly returns an
62 ret
= CryptEncodeObjectEx(X509_ASN_ENCODING
, X509_INTEGER
, NULL
, 0, NULL
,
64 ok(!ret
&& (GetLastError() == ERROR_INVALID_PARAMETER
|| GetLastError() ==
65 STATUS_ACCESS_VIOLATION
), "Unexpected error code %ld\n", GetLastError());
66 for (i
= 0; i
< sizeof(ints
) / sizeof(ints
[0]); i
++)
70 ret
= CryptEncodeObjectEx(X509_ASN_ENCODING
| PKCS_7_ASN_ENCODING
,
71 X509_INTEGER
, &ints
[i
].val
, 0, NULL
, NULL
, &bufSize
);
72 ok(ret
|| GetLastError() == ERROR_MORE_DATA
,
73 "Expected success or ERROR_MORE_DATA, got %ld\n", GetLastError());
74 ret
= CryptEncodeObjectEx(X509_ASN_ENCODING
| PKCS_7_ASN_ENCODING
,
75 X509_INTEGER
, &ints
[i
].val
, CRYPT_ENCODE_ALLOC_FLAG
, NULL
,
76 (BYTE
*)&buf
, &bufSize
);
77 ok(ret
, "CryptEncodeObjectEx failed: %ld\n", GetLastError());
78 ok(buf
[0] == 2, "Got unexpected type %d for integer (expected 2)\n",
80 ok(!memcmp(buf
+ 1, ints
[i
].encoded
+ 1, ints
[i
].encoded
[1] + 1),
81 "Encoded value of 0x%08x didn't match expected\n", ints
[i
].val
);
86 static void test_registerOIDFunction(void)
88 static const WCHAR bogusDll
[] = { 'b','o','g','u','s','.','d','l','l',0 };
91 /* oddly, this succeeds under WinXP; the function name key is merely
92 * omitted. This may be a side effect of the registry code, I don't know.
93 * I don't check it because I doubt anyone would depend on it.
94 ret = CryptRegisterOIDFunction(X509_ASN_ENCODING, NULL,
95 "1.2.3.4.5.6.7.8.9.10", bogusDll, NULL);
97 /* On windows XP, GetLastError is incorrectly being set with an HRESULT,
98 * HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER)
100 ret
= CryptRegisterOIDFunction(X509_ASN_ENCODING
, "foo", NULL
, bogusDll
,
102 ok(!ret
&& (GetLastError() == ERROR_INVALID_PARAMETER
|| GetLastError() ==
103 HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER
)),
104 "Expected ERROR_INVALID_PARAMETER: %ld\n", GetLastError());
105 /* This has no effect, but "succeeds" on XP */
106 ret
= CryptRegisterOIDFunction(X509_ASN_ENCODING
, "foo",
107 "1.2.3.4.5.6.7.8.9.10", NULL
, NULL
);
108 ok(ret
, "Expected pseudo-success, got %ld\n", GetLastError());
109 ret
= CryptRegisterOIDFunction(X509_ASN_ENCODING
, "CryptDllEncodeObject",
110 "1.2.3.4.5.6.7.8.9.10", bogusDll
, NULL
);
111 ok(ret
, "CryptRegisterOIDFunction failed: %ld\n", GetLastError());
112 ret
= CryptUnregisterOIDFunction(X509_ASN_ENCODING
, "CryptDllEncodeObject",
113 "1.2.3.4.5.6.7.8.9.10");
114 ok(ret
, "CryptUnregisterOIDFunction failed: %ld\n", GetLastError());
115 ret
= CryptRegisterOIDFunction(X509_ASN_ENCODING
, "bogus",
116 "1.2.3.4.5.6.7.8.9.10", bogusDll
, NULL
);
117 ok(ret
, "CryptRegisterOIDFunction failed: %ld\n", GetLastError());
118 ret
= CryptUnregisterOIDFunction(X509_ASN_ENCODING
, "bogus",
119 "1.2.3.4.5.6.7.8.9.10");
120 ok(ret
, "CryptUnregisterOIDFunction failed: %ld\n", GetLastError());
121 /* This has no effect */
122 ret
= CryptRegisterOIDFunction(PKCS_7_ASN_ENCODING
, "CryptDllEncodeObject",
123 "1.2.3.4.5.6.7.8.9.10", bogusDll
, NULL
);
124 ok(ret
, "CryptRegisterOIDFunction failed: %ld\n", GetLastError());
125 /* Check with bogus encoding type: */
126 ret
= CryptRegisterOIDFunction(0, "CryptDllEncodeObject",
127 "1.2.3.4.5.6.7.8.9.10", bogusDll
, NULL
);
128 ok(ret
, "CryptRegisterOIDFunction failed: %ld\n", GetLastError());
129 /* This is written with value 3 verbatim. Thus, the encoding type isn't
130 * (for now) treated as a mask.
132 ret
= CryptRegisterOIDFunction(3, "CryptDllEncodeObject",
133 "1.2.3.4.5.6.7.8.9.10", bogusDll
, NULL
);
134 ok(ret
, "CryptRegisterOIDFunction failed: %ld\n", GetLastError());
135 ret
= CryptUnregisterOIDFunction(3, "CryptDllEncodeObject",
136 "1.2.3.4.5.6.7.8.9.10");
137 ok(ret
, "CryptUnregisterOIDFunction failed: %ld\n", GetLastError());
143 test_registerOIDFunction();