41#define NONAMELESSUNION
49#include "wine/unicode.h"
110 if (pEncodePara && pEncodePara->
pfnAlloc)
132 if (pEncodePara && pEncodePara->
pfnFree)
140 DWORD bytesNeeded, significantBytes = 0;
148 for (
temp =
len, significantBytes =
sizeof(
temp); !(
temp & 0xff000000);
149 temp <<= 8, significantBytes--)
151 bytesNeeded = significantBytes + 1;
170 for (
i = 0;
i < significantBytes;
i++)
187 TRACE(
"%p, %d, %08x, %p, %p, %d\n",
items, cItem,
dwFlags, pEncodePara,
201 DWORD lenBytes, bytesNeeded;
204 bytesNeeded = 1 + lenBytes + dataLen;
220 for (
i = 0;
ret &&
i < cItem;
i++)
250 DWORD dataLen, bytesNeeded;
253 bytesNeeded = 1 + dataLen +
len;
401 items[1].pvStructInfo = &nullBlob;
439 TRACE(
"Encoding public key with OID %s\n",
495 TRACE(
"Encoding public key with OID %s\n",
528 DWORD cItem = 7, cSwapped = 0;
530 if (
info->IssuerUniqueId.cbData)
535 items[cItem].pvStructInfo = &swapped[cSwapped];
540 if (
info->SubjectUniqueId.cbData)
545 items[cItem].pvStructInfo = &swapped[cSwapped];
550 if (
info->cExtension)
555 items[cItem].pvStructInfo = &constructed;
585 if (
entry->cExtension)
587 items[cItem].pvStructInfo = &
entry->cExtension;
603 DWORD bytesNeeded, dataLen, lenBytes,
i;
608 for (
i = 0, dataLen = 0;
ret &&
i <
info->cCRLEntry;
i++)
619 bytesNeeded = 1 + lenBytes + dataLen;
635 for (
i = 0;
i <
info->cCRLEntry;
i++)
691 DWORD cItem = 4, cConstructed = 0;
693 if (
info->NextUpdate.dwLowDateTime ||
info->NextUpdate.dwHighDateTime)
695 items[cItem].pvStructInfo = &
info->NextUpdate;
705 if (
info->cExtension)
707 constructed[cConstructed].
tag = 0;
710 items[cItem].pvStructInfo = &constructed[cConstructed];
743 items[cItem].pvStructInfo = &
ext->fCritical;
747 items[cItem].pvStructInfo = &
ext->Value;
765 DWORD bytesNeeded, dataLen, lenBytes,
i;
769 for (
i = 0, dataLen = 0;
ret &&
i <
exts->cExtension;
i++)
780 bytesNeeded = 1 + lenBytes + dataLen;
796 for (
i = 0;
i <
exts->cExtension;
i++)
825 DWORD bytesNeeded = 0, lenBytes;
837 if (
sscanf(pszObjId,
"%d.%d%n", &val1, &val2, &firstPos) != 2)
843 firstByte = val1 * 40 + val2;
844 ptr = pszObjId + firstPos;
857 if (val1 >= 0x10000000)
859 else if (val1 >= 0x200000)
861 else if (val1 >= 0x4000)
863 else if (val1 >= 0x80)
881 bytesNeeded += 1 + lenBytes;
900 ptr = pszObjId + firstPos;
905 unsigned char outBytes[5];
908 if (
val >= 0x10000000)
910 else if (
val >= 0x200000)
912 else if (
val >= 0x4000)
914 else if (
val >= 0x80)
918 for (
i = numBytes;
i > 0;
i--)
920 outBytes[
i - 1] =
val & 0x7f;
923 for (
i = 0;
i < numBytes - 1;
i++)
944 DWORD bytesNeeded, lenBytes, encodedLen;
948 bytesNeeded = 1 + lenBytes + encodedLen;
973 DWORD bytesNeeded, lenBytes, strLen;
977 else if (
value->Value.pbData)
982 bytesNeeded = 1 + lenBytes + strLen * 2;
997 for (
i = 0;
i < strLen;
i++)
1013 DWORD bytesNeeded, lenBytes, encodedLen, strLen;
1016 strLen =
value->Value.cbData /
sizeof(
WCHAR);
1024 bytesNeeded = 1 + lenBytes + encodedLen;
1038 bytesNeeded - lenBytes - 1,
NULL,
NULL);
1054 switch (
value->dwValueType)
1102 FIXME(
"CERT_RDN_UNIVERSAL_STRING: unimplemented\n");
1139 bytesNeeded +=
size;
1147 bytesNeeded +=
size;
1149 bytesNeeded += 1 + lenBytes;
1163 size = bytesNeeded - 1 - lenBytes;
1169 size = bytesNeeded - 1 - lenBytes -
size;
1195 ret =
a->cbData -
b->cbData;
1206 DWORD bytesNeeded = 0, lenBytes,
i;
1209 for (
i = 0;
i <
set->cBlob;
i++)
1210 bytesNeeded +=
set->rgBlob[
i].cbData;
1212 bytesNeeded += 1 + lenBytes;
1227 for (
i = 0;
i <
set->cBlob;
i++)
1287 DWORD bytesNeeded = 0, lenBytes;
1292 bytesNeeded += 1 + lenBytes;
1412 TRACE(
"encoding name with %d RDNs\n",
info->cRDN);
1419 bytesNeeded +=
size;
1424 bytesNeeded += 1 + lenBytes;
1451 bytesNeeded -=
size;
1475 const DWORD *ver = pvStructInfo;
1514 items[cItem].pvStructInfo = &nullBlob;
1548 DWORD bytesNeeded, dataLen, lenBytes,
i;
1549 const struct CTLEntries *entries = pvStructInfo;
1552 for (
i = 0, dataLen = 0;
ret &&
i < entries->
cEntry;
i++)
1563 bytesNeeded = 1 + lenBytes + dataLen;
1612 if (
info->ListIdentifier.cbData)
1614 items[cItem].pvStructInfo = &
info->ListIdentifier;
1618 if (
info->SequenceNumber.cbData)
1620 items[cItem].pvStructInfo = &
info->SequenceNumber;
1624 items[cItem].pvStructInfo = &
info->ThisUpdate;
1627 if (
info->NextUpdate.dwLowDateTime ||
info->NextUpdate.dwHighDateTime)
1629 items[cItem].pvStructInfo = &
info->NextUpdate;
1633 items[cItem].pvStructInfo = &
info->SubjectAlgorithm;
1636 if (
info->cCTLEntry)
1638 items[cItem].pvStructInfo = &
info->cCTLEntry;
1642 if (
info->cExtension)
1644 constructed.
tag = 0;
1647 items[cItem].pvStructInfo = &constructed;
1702 DWORD bytesNeeded, dataLen, lenBytes,
i;
1718 bytesNeeded = 1 + lenBytes + dataLen;
1763 DWORD bytesNeeded, dataLen, lenBytes,
i;
1778 bytesNeeded = 1 + lenBytes + dataLen;
1844 if (
notice->pNoticeReference)
1847 items[cItem].pvStructInfo =
notice->pNoticeReference;
1850 if (
notice->pszDisplayText)
1853 displayTextValue.Value.cbData = 0;
1854 displayTextValue.Value.pbData = (
LPBYTE)
notice->pszDisplayText;
1856 items[cItem].pvStructInfo = &displayTextValue;
1880 if (!
attr->pszObjId)
1939 if (
info->Content.cbData)
1941 constructed.
tag = 0;
1944 items[cItem].pvStructInfo = &constructed;
1976 if (!
info->pszObjId)
1997 DWORD bytesNeeded, lenBytes, encodedLen;
2000 encodedLen =
value->Value.cbData /
sizeof(
WCHAR);
2006 bytesNeeded = 1 + lenBytes + encodedLen;
2021 for (
i = 0;
i < encodedLen;
i++)
2034 DWORD bytesNeeded, lenBytes, encodedLen;
2037 encodedLen =
value->Value.cbData /
sizeof(
WCHAR);
2043 bytesNeeded = 1 + lenBytes + encodedLen;
2061 for (
i = 0;
ret &&
i < encodedLen;
i++)
2082 wc ==
')' || wc ==
'+' || wc ==
',' || wc ==
'-' || wc ==
'.' ||
2083 wc ==
'/' || wc ==
':' || wc ==
'=' || wc ==
'?';
2092 DWORD bytesNeeded, lenBytes, encodedLen;
2095 encodedLen =
value->Value.cbData /
sizeof(
WCHAR);
2101 bytesNeeded = 1 + lenBytes + encodedLen;
2119 for (
i = 0;
ret &&
i < encodedLen;
i++)
2143 DWORD bytesNeeded, lenBytes, encodedLen;
2146 encodedLen =
value->Value.cbData /
sizeof(
WCHAR);
2152 bytesNeeded = 1 + lenBytes + encodedLen;
2170 for (
i = 0;
ret &&
i < encodedLen;
i++)
2194 DWORD bytesNeeded, lenBytes, strLen;
2198 strLen =
value->Value.cbData /
sizeof(
WCHAR);
2204 bytesNeeded = 1 + lenBytes + strLen * 4;
2219 for (
i = 0;
i < strLen;
i++)
2241 switch (
value->dwValueType)
2315 TRACE(
"encoding name with %d RDNs\n",
info->cRDN);
2322 bytesNeeded +=
size;
2325 bytesNeeded += 1 + lenBytes;
2351 bytesNeeded -=
size;
2410 switch (
entry->dwAltNameChoice)
2416 if (
entry->u.pwszURL)
2422 for (
i = 0;
ret &&
i < dataLen;
i++)
2424 if (
entry->u.pwszURL[
i] > 0x7f)
2437 dataLen =
entry->u.DirectoryName.cbData;
2441 dataLen =
entry->u.IPAddress.cbData;
2453 FIXME(
"name type %d unimplemented\n",
entry->dwAltNameChoice);
2461 DWORD bytesNeeded, lenBytes;
2464 bytesNeeded = 1 + dataLen + lenBytes;
2478 switch (
entry->dwAltNameChoice)
2486 for (
i = 0;
i < dataLen;
i++)
2517 DWORD cItem = 0, cSwapped = 0;
2519 if (
info->KeyId.cbData)
2524 items[cItem].pvStructInfo = &swapped[cSwapped];
2529 if (
info->CertIssuer.cbData)
2531 constructed.
tag = 1;
2534 items[cItem].pvStructInfo = &constructed;
2538 if (
info->CertSerialNumber.cbData)
2543 items[cItem].pvStructInfo = &swapped[cSwapped];
2569 DWORD bytesNeeded, dataLen, lenBytes,
i;
2575 for (
i = 0, dataLen = 0;
ret &&
i <
info->cAltEntry;
i++)
2596 bytesNeeded = 1 + lenBytes + dataLen;
2653 DWORD cItem = 0, cSwapped = 0;
2655 if (
info->KeyId.cbData)
2660 items[cItem].pvStructInfo = &swapped[cSwapped];
2665 if (
info->AuthorityCertIssuer.cAltEntry)
2670 items[cItem].pvStructInfo = &swapped[cSwapped];
2675 if (
info->AuthorityCertSerialNumber.cbData)
2680 items[cItem].pvStructInfo = &swapped[cSwapped];
2705 if (!
descr->pszAccessMethod)
2721 DWORD bytesNeeded, dataLen, lenBytes,
i;
2725 for (
i = 0, dataLen = 0;
ret &&
i <
info->cAccDescr;
i++)
2737 bytesNeeded = 1 + lenBytes + dataLen;
2753 for (
i = 0;
i <
info->cAccDescr;
i++)
2792 if (
info->fPathLenConstraint)
2794 items[cItem].pvStructInfo = &
info->dwPathLenConstraint;
2798 if (
info->cSubtreesConstraint)
2800 items[cItem].pvStructInfo = &
info->cSubtreesConstraint;
2834 if (
info->fPathLenConstraint)
2836 items[cItem].pvStructInfo = &
info->dwPathLenConstraint;
2859 if (!
info->cPolicyQualifier)
2873 for (
i = 0;
ret &&
i <
info->cPolicyQualifier;
i++)
2875 items[0].pvStructInfo =
2876 info->rgPolicyQualifier[
i].pszPolicyQualifierId;
2877 items[1].pvStructInfo = &
info->rgPolicyQualifier[
i].Qualifier;
2881 bytesNeeded +=
size;
2884 bytesNeeded += 1 + lenBytes;
2902 for (
i = 0;
ret &&
i <
info->cPolicyQualifier;
i++)
2904 items[0].pvStructInfo =
2905 info->rgPolicyQualifier[
i].pszPolicyQualifierId;
2906 items[1].pvStructInfo =
2907 &
info->rgPolicyQualifier[
i].Qualifier;
2914 bytesNeeded -=
size;
2936 if (!
info->pszPolicyIdentifier)
2957 for (
i = 0;
ret &&
i <
info->cPolicyInfo;
i++)
2963 bytesNeeded +=
size;
2966 bytesNeeded += 1 + lenBytes;
2984 for (
i = 0;
ret &&
i <
info->cPolicyInfo;
i++)
2988 &
info->rgPolicyInfo[
i],
2993 bytesNeeded -=
size;
3019 if (!
mapping->pszIssuerDomainPolicy || !
mapping->pszSubjectDomainPolicy)
3039 for (
i = 0;
ret &&
i <
info->cPolicyMapping;
i++)
3045 bytesNeeded +=
size;
3048 bytesNeeded += 1 + lenBytes;
3066 for (
i = 0;
ret &&
i <
info->cPolicyMapping;
i++)
3075 bytesNeeded -=
size;
3104 DWORD cItem = 0, cSwapped = 0;
3106 if (
info->fRequireExplicitPolicy)
3110 &
info->dwRequireExplicitPolicySkipCerts;
3112 items[cItem].pvStructInfo = &swapped[cSwapped];
3117 if (
info->fInhibitPolicyMapping)
3121 &
info->dwInhibitPolicyMappingSkipCerts;
3123 items[cItem].pvStructInfo = &swapped[cSwapped];
3187 DWORD bytesNeeded, lenBytes;
3189 TRACE(
"(%d, %p), %08x, %p, %p, %d\n",
blob->cbData,
blob->pbData,
3193 bytesNeeded = 1 + lenBytes +
blob->cbData;
3233 DWORD bytesNeeded, lenBytes, dataBytes;
3237 if (!
blob->cUnusedBits)
3239 dataBytes =
blob->cbData;
3242 else if (
blob->cbData * 8 >
blob->cUnusedBits)
3244 dataBytes = (
blob->cbData * 8 -
blob->cUnusedBits) / 8 + 1;
3245 unusedBits =
blob->cUnusedBits >= 8 ?
blob->cUnusedBits / 8 :
3254 bytesNeeded = 1 + lenBytes + dataBytes + 1;
3351 DWORD significantBytes, lenBytes, bytesNeeded;
3356 significantBytes =
blob->cbData;
3357 if (significantBytes)
3359 if (
blob->pbData[significantBytes - 1] & 0x80)
3362 for (; significantBytes > 0 &&
3363 blob->pbData[significantBytes - 1] == 0xff; significantBytes--)
3365 if (
blob->pbData[significantBytes - 1] < 0x80)
3374 for (; significantBytes > 0 &&
3375 !
blob->pbData[significantBytes - 1]; significantBytes--)
3377 if (significantBytes == 0)
3378 significantBytes = 1;
3379 if (
blob->pbData[significantBytes - 1] > 0x7f)
3390 bytesNeeded = 1 + lenBytes + significantBytes;
3417 for (; significantBytes > 0; significantBytes--)
3439 DWORD significantBytes, lenBytes, bytesNeeded;
3443 significantBytes =
blob->cbData;
3444 if (significantBytes)
3447 for (; significantBytes > 0 && !
blob->pbData[significantBytes - 1];
3450 if (significantBytes == 0)
3451 significantBytes = 1;
3452 if (
blob->pbData[significantBytes - 1] > 0x7f)
3459 bytesNeeded = 1 + lenBytes + significantBytes;
3486 for (; significantBytes > 0; significantBytes--)