Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

810 lines
18 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1999
  5. //
  6. // File: crldist.cpp
  7. //
  8. // Contents: Cert Server Extension Encoding/Decoding implementation
  9. //
  10. //---------------------------------------------------------------------------
  11. #include "pch.cpp"
  12. #pragma hdrstop
  13. #include <assert.h>
  14. #include "resource.h"
  15. #include "crldist.h"
  16. #include "celib.h"
  17. //+--------------------------------------------------------------------------
  18. // CCertEncodeCRLDistInfo::~CCertEncodeCRLDistInfo -- destructor
  19. //
  20. // free memory associated with this instance
  21. //+--------------------------------------------------------------------------
  22. CCertEncodeCRLDistInfo::~CCertEncodeCRLDistInfo()
  23. {
  24. _Cleanup();
  25. }
  26. //+--------------------------------------------------------------------------
  27. // CCertEncodeCRLDistInfo::_Cleanup -- release all resources
  28. //
  29. // free memory associated with this instance
  30. //+--------------------------------------------------------------------------
  31. VOID
  32. CCertEncodeCRLDistInfo::_Cleanup()
  33. {
  34. if (NULL != m_aValue)
  35. {
  36. if (!m_fConstructing)
  37. {
  38. if (NULL != m_DecodeInfo)
  39. {
  40. LocalFree(m_DecodeInfo);
  41. m_DecodeInfo = NULL;
  42. }
  43. }
  44. else
  45. {
  46. CRL_DIST_POINT *pDistPoint;
  47. CRL_DIST_POINT *pDistPointEnd;
  48. for (pDistPoint = m_aValue, pDistPointEnd = &m_aValue[m_cValue];
  49. pDistPoint < pDistPointEnd;
  50. pDistPoint++)
  51. {
  52. CERT_ALT_NAME_ENTRY *pName;
  53. CERT_ALT_NAME_ENTRY *pNameEnd;
  54. pName = pDistPoint->DistPointName.FullName.rgAltEntry;
  55. if (NULL != pName)
  56. {
  57. for (pNameEnd = &pName[pDistPoint->DistPointName.FullName.cAltEntry];
  58. pName < pNameEnd;
  59. pName++)
  60. {
  61. if (NULL != pName->pwszURL) // test arbitrary union arm
  62. {
  63. LocalFree(pName->pwszURL);
  64. }
  65. }
  66. LocalFree(pDistPoint->DistPointName.FullName.rgAltEntry);
  67. }
  68. }
  69. LocalFree(m_aValue);
  70. }
  71. m_aValue = NULL;
  72. }
  73. assert(NULL == m_DecodeInfo);
  74. m_fConstructing = FALSE;
  75. }
  76. //+--------------------------------------------------------------------------
  77. // CCertEncodeCRLDistInfo::_MapDistPoint -- map a distribution point
  78. //
  79. //+--------------------------------------------------------------------------
  80. HRESULT
  81. CCertEncodeCRLDistInfo::_MapDistPoint(
  82. IN BOOL fEncode,
  83. IN LONG DistPointIndex,
  84. OUT LONG **ppNameCount,
  85. OUT CERT_ALT_NAME_ENTRY ***ppaName)
  86. {
  87. HRESULT hr = S_OK;
  88. CRL_DIST_POINT *pDistPoint;
  89. if (fEncode)
  90. {
  91. pDistPoint = m_fConstructing? m_aValue : NULL;
  92. }
  93. else
  94. {
  95. pDistPoint = m_aValue;
  96. }
  97. if (NULL == pDistPoint)
  98. {
  99. hr = E_INVALIDARG;
  100. ceERRORPRINTLINE("bad parameter", hr);
  101. goto error;
  102. }
  103. if (m_cValue <= DistPointIndex)
  104. {
  105. ceERRORPRINTLINE("bad DistPointIndex parameter", hr);
  106. hr = E_INVALIDARG;
  107. goto error;
  108. }
  109. *ppNameCount =
  110. (LONG *) &pDistPoint[DistPointIndex].DistPointName.FullName.cAltEntry;
  111. *ppaName = &pDistPoint[DistPointIndex].DistPointName.FullName.rgAltEntry;
  112. error:
  113. return(hr);
  114. }
  115. //+--------------------------------------------------------------------------
  116. // CCertEncodeCRLDistInfo::_MapName -- map a name
  117. //
  118. //+--------------------------------------------------------------------------
  119. HRESULT
  120. CCertEncodeCRLDistInfo::_MapName(
  121. IN BOOL fEncode,
  122. IN LONG DistPointIndex,
  123. IN LONG NameIndex,
  124. OUT CERT_ALT_NAME_ENTRY **ppName)
  125. {
  126. HRESULT hr;
  127. LONG *pNameCount;
  128. CERT_ALT_NAME_ENTRY **paName;
  129. if (NULL == ppName)
  130. {
  131. hr = E_POINTER;
  132. ceERRORPRINTLINE("NULL parm", hr);
  133. goto error;
  134. }
  135. hr = _MapDistPoint(fEncode, DistPointIndex, &pNameCount, &paName);
  136. if (S_OK != hr)
  137. {
  138. ceERRORPRINTLINE("_MapDistPoint", hr);
  139. goto error;
  140. }
  141. if (*pNameCount <= NameIndex)
  142. {
  143. ceERRORPRINTLINE("bad NameIndex parameter", hr);
  144. hr = E_INVALIDARG;
  145. goto error;
  146. }
  147. *ppName = &(*paName)[NameIndex];
  148. error:
  149. return(hr);
  150. }
  151. //+--------------------------------------------------------------------------
  152. // CCertEncodeCRLDistInfo::Decode -- Decode CRLDistInfo
  153. //
  154. // Returns S_OK on success.
  155. //+--------------------------------------------------------------------------
  156. STDMETHODIMP
  157. CCertEncodeCRLDistInfo::Decode(
  158. /* [in] */ BSTR const strBinary)
  159. {
  160. HRESULT hr = S_OK;
  161. DWORD cbCRLDist;
  162. _Cleanup();
  163. if (NULL == strBinary)
  164. {
  165. hr = E_POINTER;
  166. ceERRORPRINTLINE("NULL parm", hr);
  167. goto error;
  168. }
  169. // Decode CRL_DIST_POINTS_INFO:
  170. if (!ceDecodeObject(
  171. X509_ASN_ENCODING,
  172. X509_CRL_DIST_POINTS,
  173. (BYTE *) strBinary,
  174. SysStringByteLen(strBinary),
  175. FALSE,
  176. (VOID **) &m_DecodeInfo,
  177. &cbCRLDist))
  178. {
  179. hr = ceHLastError();
  180. ceERRORPRINTLINE("ceDecodeObject", hr);
  181. goto error;
  182. }
  183. m_aValue = m_DecodeInfo->rgDistPoint;
  184. m_cValue = m_DecodeInfo->cDistPoint;
  185. error:
  186. if (S_OK != hr)
  187. {
  188. _Cleanup();
  189. }
  190. return(_SetErrorInfo(hr, L"CCertEncodeCRLDistInfo::Decode"));
  191. }
  192. //+--------------------------------------------------------------------------
  193. // CCertEncodeCRLDistInfo::GetDistPointCount -- Get the Distribution Name Count
  194. //
  195. // Returns S_OK on success.
  196. //+--------------------------------------------------------------------------
  197. STDMETHODIMP
  198. CCertEncodeCRLDistInfo::GetDistPointCount(
  199. /* [out, retval] */ LONG __RPC_FAR *pDistPointCount)
  200. {
  201. HRESULT hr = E_INVALIDARG;
  202. if (NULL == m_aValue)
  203. {
  204. ceERRORPRINTLINE("bad parameter", hr);
  205. goto error;
  206. }
  207. if (NULL == pDistPointCount)
  208. {
  209. hr = E_POINTER;
  210. ceERRORPRINTLINE("NULL parm", hr);
  211. goto error;
  212. }
  213. *pDistPointCount = m_cValue;
  214. hr = S_OK;
  215. error:
  216. return(_SetErrorInfo(hr, L"CCertEncodeCRLDistInfo::GetDistPointCount"));
  217. }
  218. //+--------------------------------------------------------------------------
  219. // CCertEncodeCRLDistInfo::GetNameCount -- Get a Name Count
  220. //
  221. // Returns S_OK on success.
  222. //+--------------------------------------------------------------------------
  223. STDMETHODIMP
  224. CCertEncodeCRLDistInfo::GetNameCount(
  225. /* [in] */ LONG DistPointIndex,
  226. /* [out, retval] */ LONG __RPC_FAR *pNameCount)
  227. {
  228. HRESULT hr;
  229. LONG *pCount;
  230. CERT_ALT_NAME_ENTRY **paName;
  231. if (NULL == pNameCount)
  232. {
  233. hr = E_POINTER;
  234. ceERRORPRINTLINE("NULL parm", hr);
  235. goto error;
  236. }
  237. hr = _MapDistPoint(FALSE, DistPointIndex, &pCount, &paName);
  238. if (S_OK != hr)
  239. {
  240. ceERRORPRINTLINE("_MapDistPoint", hr);
  241. goto error;
  242. }
  243. if (NULL == *paName)
  244. {
  245. hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
  246. ceERRORPRINTLINE("uninitialized", hr);
  247. goto error;
  248. }
  249. *pNameCount = *pCount;
  250. error:
  251. return(_SetErrorInfo(hr, L"CCertEncodeCRLDistInfo::GetNameCount"));
  252. }
  253. //+--------------------------------------------------------------------------
  254. // CCertEncodeCRLDistInfo::GetNameChoice -- Get a Name Choice
  255. //
  256. // Returns S_OK on success.
  257. //+--------------------------------------------------------------------------
  258. STDMETHODIMP
  259. CCertEncodeCRLDistInfo::GetNameChoice(
  260. /* [in] */ LONG DistPointIndex,
  261. /* [in] */ LONG NameIndex,
  262. /* [out, retval] */ LONG __RPC_FAR *pNameChoice)
  263. {
  264. HRESULT hr;
  265. CERT_ALT_NAME_ENTRY *pName;
  266. if (NULL == pNameChoice)
  267. {
  268. hr = E_POINTER;
  269. ceERRORPRINTLINE("NULL parm", hr);
  270. goto error;
  271. }
  272. hr = _MapName(FALSE, DistPointIndex, NameIndex, &pName);
  273. if (S_OK != hr)
  274. {
  275. ceERRORPRINTLINE("_MapName", hr);
  276. goto error;
  277. }
  278. *pNameChoice = pName->dwAltNameChoice;
  279. if (0 == pName->dwAltNameChoice)
  280. {
  281. hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
  282. ceERRORPRINTLINE("uninitialized", hr);
  283. goto error;
  284. }
  285. error:
  286. return(_SetErrorInfo(hr, L"CCertEncodeCRLDistInfo::GetNameChoice"));
  287. }
  288. //+--------------------------------------------------------------------------
  289. // CCertEncodeCRLDistInfo::GetName -- Get a Name
  290. //
  291. // Returns S_OK on success.
  292. //+--------------------------------------------------------------------------
  293. STDMETHODIMP
  294. CCertEncodeCRLDistInfo::GetName(
  295. /* [in] */ LONG DistPointIndex,
  296. /* [in] */ LONG NameIndex,
  297. /* [out, retval] */ BSTR __RPC_FAR *pstrName)
  298. {
  299. HRESULT hr;
  300. CERT_ALT_NAME_ENTRY *pName;
  301. WCHAR const *pwsz = NULL;
  302. char const *psz = NULL;
  303. if (NULL == pstrName)
  304. {
  305. hr = E_POINTER;
  306. ceERRORPRINTLINE("NULL parm", hr);
  307. goto error;
  308. }
  309. ceFreeBstr(pstrName);
  310. hr = _MapName(FALSE, DistPointIndex, NameIndex, &pName);
  311. if (S_OK != hr)
  312. {
  313. ceERRORPRINTLINE("_MapName", hr);
  314. goto error;
  315. }
  316. switch (pName->dwAltNameChoice)
  317. {
  318. case CERT_ALT_NAME_RFC822_NAME:
  319. pwsz = pName->pwszRfc822Name;
  320. break;
  321. case CERT_ALT_NAME_DNS_NAME:
  322. pwsz = pName->pwszDNSName;
  323. break;
  324. case CERT_ALT_NAME_URL:
  325. pwsz = pName->pwszURL;
  326. break;
  327. case CERT_ALT_NAME_REGISTERED_ID:
  328. psz = pName->pszRegisteredID;
  329. break;
  330. //case CERT_ALT_NAME_DIRECTORY_NAME:
  331. //case CERT_ALT_NAME_OTHER_NAME:
  332. //case CERT_ALT_NAME_X400_ADDRESS:
  333. //case CERT_ALT_NAME_EDI_PARTY_NAME:
  334. //case CERT_ALT_NAME_IP_ADDRESS:
  335. default:
  336. assert(0 == pName->dwAltNameChoice);
  337. hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
  338. ceERRORPRINTLINE("uninitialized", hr);
  339. goto error;
  340. }
  341. // we'd better assure 1 and only 1 of these is non null
  342. if ((NULL != pwsz) ^ (NULL == psz))
  343. {
  344. hr = E_UNEXPECTED;
  345. _JumpError(hr, error, "((NULL != pwsz) ^ (NULL == psz))");
  346. }
  347. hr = E_OUTOFMEMORY;
  348. if (NULL != pwsz)
  349. {
  350. if (!ceConvertWszToBstr(pstrName, pwsz, -1))
  351. {
  352. ceERRORPRINTLINE("no memory", hr);
  353. goto error;
  354. }
  355. }
  356. else
  357. {
  358. assert(NULL != psz);
  359. if (!ceConvertSzToBstr(pstrName, psz, -1))
  360. {
  361. ceERRORPRINTLINE("no memory", hr);
  362. goto error;
  363. }
  364. }
  365. hr = S_OK;
  366. error:
  367. return(_SetErrorInfo(hr, L"CCertEncodeCRLDistInfo::GetName"));
  368. }
  369. //+--------------------------------------------------------------------------
  370. // CCertEncodeCRLDistInfo::Reset -- clear out data
  371. //
  372. // Returns S_OK on success.
  373. //+--------------------------------------------------------------------------
  374. STDMETHODIMP
  375. CCertEncodeCRLDistInfo::Reset(
  376. /* [in] */ LONG DistPointCount)
  377. {
  378. HRESULT hr = S_OK;
  379. _Cleanup();
  380. m_fConstructing = TRUE;
  381. if (CENCODEMAX < DistPointCount || 0 > DistPointCount)
  382. {
  383. hr = E_INVALIDARG;
  384. ceERRORPRINTLINE("bad count parameter", hr);
  385. goto error;
  386. }
  387. m_aValue = (CRL_DIST_POINT *) LocalAlloc(
  388. LMEM_FIXED | LMEM_ZEROINIT,
  389. DistPointCount * sizeof(m_aValue[0]));
  390. if (NULL == m_aValue)
  391. {
  392. hr = E_OUTOFMEMORY;
  393. ceERRORPRINTLINE("LocalAlloc", hr);
  394. goto error;
  395. }
  396. m_cValue = DistPointCount;
  397. error:
  398. if (S_OK != hr)
  399. {
  400. _Cleanup();
  401. }
  402. return(_SetErrorInfo(hr, L"CCertEncodeCRLDistInfo::Reset"));
  403. }
  404. //+--------------------------------------------------------------------------
  405. // CCertEncodeCRLDistInfo::SetNameCount -- Set the Name Count
  406. //
  407. // Returns S_OK on success.
  408. //+--------------------------------------------------------------------------
  409. STDMETHODIMP
  410. CCertEncodeCRLDistInfo::SetNameCount(
  411. /* [in] */ LONG DistPointIndex,
  412. /* [in] */ LONG NameCount)
  413. {
  414. HRESULT hr;
  415. LONG *pNameCount;
  416. CERT_ALT_NAME_ENTRY **paName;
  417. hr = E_INVALIDARG;
  418. if (!m_fConstructing)
  419. {
  420. ceERRORPRINTLINE("bad parameter", hr);
  421. goto error;
  422. }
  423. if (CENCODEMAX < NameCount || 0 > NameCount)
  424. {
  425. ceERRORPRINTLINE("bad count parameter", hr);
  426. goto error;
  427. }
  428. hr = _MapDistPoint(FALSE, DistPointIndex, &pNameCount, &paName);
  429. if (S_OK != hr)
  430. {
  431. ceERRORPRINTLINE("_MapDistPoint", hr);
  432. goto error;
  433. }
  434. if (0 != *pNameCount || NULL != *paName)
  435. {
  436. hr = E_INVALIDARG;
  437. ceERRORPRINTLINE("bad parameter", hr);
  438. goto error;
  439. }
  440. *paName = (CERT_ALT_NAME_ENTRY *) LocalAlloc(
  441. LMEM_FIXED | LMEM_ZEROINIT,
  442. NameCount * sizeof(CERT_ALT_NAME_ENTRY));
  443. if (NULL == *paName)
  444. {
  445. hr = E_OUTOFMEMORY;
  446. ceERRORPRINTLINE("LocalAlloc", hr);
  447. goto error;
  448. }
  449. *pNameCount = NameCount;
  450. error:
  451. return(_SetErrorInfo(hr, L"CCertEncodeCRLDistInfo::SetNameCount"));
  452. }
  453. //+--------------------------------------------------------------------------
  454. // CCertEncodeCRLDistInfo::SetNameEntry -- Set a Name Netry
  455. //
  456. // Returns S_OK on success.
  457. //+--------------------------------------------------------------------------
  458. STDMETHODIMP
  459. CCertEncodeCRLDistInfo::SetNameEntry(
  460. /* [in] */ LONG DistPointIndex,
  461. /* [in] */ LONG NameIndex,
  462. /* [in] */ LONG NameChoice,
  463. /* [in] */ BSTR const strName)
  464. {
  465. HRESULT hr;
  466. CERT_ALT_NAME_ENTRY *pName;
  467. WCHAR **ppwsz = NULL;
  468. char **ppsz = NULL;
  469. if (NULL == strName)
  470. {
  471. hr = E_POINTER;
  472. ceERRORPRINTLINE("NULL parm", hr);
  473. goto error;
  474. }
  475. if (!m_fConstructing)
  476. {
  477. hr = E_INVALIDARG;
  478. ceERRORPRINTLINE("bad parameter", hr);
  479. goto error;
  480. }
  481. hr = _MapName(TRUE, DistPointIndex, NameIndex, &pName);
  482. if (S_OK != hr)
  483. {
  484. ceERRORPRINTLINE("_MapName", hr);
  485. goto error;
  486. }
  487. if (NULL != pName->pwszURL)
  488. {
  489. hr = E_INVALIDARG;
  490. ceERRORPRINTLINE("bad parameter", hr);
  491. goto error;
  492. }
  493. switch (NameChoice)
  494. {
  495. case CERT_ALT_NAME_RFC822_NAME:
  496. ppwsz = &pName->pwszRfc822Name;
  497. break;
  498. case CERT_ALT_NAME_DNS_NAME:
  499. ppwsz = &pName->pwszDNSName;
  500. break;
  501. case CERT_ALT_NAME_URL:
  502. ppwsz = &pName->pwszURL;
  503. break;
  504. case CERT_ALT_NAME_REGISTERED_ID:
  505. hr = ceVerifyObjId(strName);
  506. if (S_OK != hr)
  507. {
  508. ceERRORPRINTLINE("ceVerifyObjId", hr);
  509. goto error;
  510. }
  511. ppsz = &pName->pszRegisteredID;
  512. break;
  513. //case CERT_ALT_NAME_DIRECTORY_NAME:
  514. //case CERT_ALT_NAME_OTHER_NAME:
  515. //case CERT_ALT_NAME_X400_ADDRESS:
  516. //case CERT_ALT_NAME_EDI_PARTY_NAME:
  517. //case CERT_ALT_NAME_IP_ADDRESS:
  518. }
  519. if (NULL != ppwsz)
  520. {
  521. if (NULL != *ppwsz)
  522. {
  523. hr = E_INVALIDARG;
  524. ceERRORPRINTLINE("string already set", hr);
  525. goto error;
  526. }
  527. hr = ceVerifyAltNameString(NameChoice, strName);
  528. if (S_OK != hr)
  529. {
  530. ceERRORPRINTLINE("ceVerifyAltNameString", hr);
  531. goto error;
  532. }
  533. *ppwsz = ceDuplicateString(strName);
  534. if (NULL == *ppwsz)
  535. {
  536. hr = E_OUTOFMEMORY;
  537. ceERRORPRINTLINE("ceDuplicateString", hr);
  538. goto error;
  539. }
  540. }
  541. else if (NULL != ppsz)
  542. {
  543. if (NULL != *ppsz)
  544. {
  545. hr = E_INVALIDARG;
  546. ceERRORPRINTLINE("string already set", hr);
  547. goto error;
  548. }
  549. if (!ceConvertWszToSz(ppsz, strName, -1))
  550. {
  551. hr = E_OUTOFMEMORY;
  552. ceERRORPRINTLINE("ceConvertWszToSz", hr);
  553. goto error;
  554. }
  555. }
  556. else
  557. {
  558. hr = E_INVALIDARG;
  559. ceERRORPRINTLINE("bad NameChoice parameter", hr);
  560. goto error;
  561. }
  562. pName->dwAltNameChoice = NameChoice;
  563. error:
  564. return(_SetErrorInfo(hr, L"CCertEncodeCRLDistInfo::SetNameEntry"));
  565. }
  566. //+--------------------------------------------------------------------------
  567. // CCertEncodeCRLDistInfo::_VerifyNames -- Verify names
  568. //
  569. // Returns S_OK on success.
  570. //+--------------------------------------------------------------------------
  571. BOOL
  572. CCertEncodeCRLDistInfo::_VerifyNames(
  573. IN LONG DistPointIndex)
  574. {
  575. HRESULT hr;
  576. BOOL fOk = FALSE;
  577. LONG Count;
  578. LONG *pNameCount;
  579. LONG i;
  580. CERT_ALT_NAME_ENTRY **paName;
  581. assert(m_fConstructing);
  582. hr = _MapDistPoint(TRUE, DistPointIndex, &pNameCount, &paName);
  583. if (S_OK != hr)
  584. {
  585. ceERRORPRINTLINE("_MapDistPoint", hr);
  586. goto error;
  587. }
  588. Count = *pNameCount;
  589. if (0 != Count)
  590. {
  591. CERT_ALT_NAME_ENTRY *pName;
  592. pName = *paName;
  593. assert(NULL != pName);
  594. for (i = 0; i < Count; pName++, i++)
  595. {
  596. if (NULL == pName->pwszURL) // test arbitrary union arm
  597. {
  598. hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
  599. ceERRORPRINTLINE("uninitialized name", hr);
  600. goto error;
  601. }
  602. }
  603. }
  604. fOk = TRUE;
  605. error:
  606. return(fOk);
  607. }
  608. //+--------------------------------------------------------------------------
  609. // CCertEncodeCRLDistInfo::Encode -- Encode CRLDistInfo
  610. //
  611. // Returns S_OK on success.
  612. //+--------------------------------------------------------------------------
  613. STDMETHODIMP
  614. CCertEncodeCRLDistInfo::Encode(
  615. /* [out, retval] */ BSTR __RPC_FAR *pstrBinary)
  616. {
  617. HRESULT hr = S_OK;
  618. CRL_DIST_POINTS_INFO CRLDistInfo;
  619. BYTE *pbEncoded = NULL;
  620. DWORD cbEncoded;
  621. LONG i;
  622. CRLDistInfo.cDistPoint = m_cValue;
  623. CRLDistInfo.rgDistPoint = m_aValue;
  624. if (NULL == pstrBinary)
  625. {
  626. hr = E_POINTER;
  627. ceERRORPRINTLINE("NULL parm", hr);
  628. goto error;
  629. }
  630. ceFreeBstr(pstrBinary);
  631. if (!m_fConstructing || NULL == m_aValue)
  632. {
  633. hr = E_INVALIDARG;
  634. ceERRORPRINTLINE("bad parameter", hr);
  635. goto error;
  636. }
  637. for (i = 0; i < m_cValue; i++)
  638. {
  639. m_aValue[i].DistPointName.dwDistPointNameChoice =
  640. CRL_DIST_POINT_FULL_NAME;
  641. // Verify all entries are initialized:
  642. if (!_VerifyNames(i))
  643. {
  644. hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
  645. ceERRORPRINTLINE("uninitialized name", hr);
  646. goto error;
  647. }
  648. }
  649. // Encode CRL_DIST_POINTS_INFO:
  650. if (!ceEncodeObject(
  651. X509_ASN_ENCODING,
  652. X509_CRL_DIST_POINTS,
  653. &CRLDistInfo,
  654. 0,
  655. FALSE,
  656. &pbEncoded,
  657. &cbEncoded))
  658. {
  659. hr = ceHLastError();
  660. ceERRORPRINTLINE("ceEncodeObject", hr);
  661. goto error;
  662. }
  663. if (!ceConvertWszToBstr(pstrBinary, (WCHAR const *) pbEncoded, cbEncoded))
  664. {
  665. hr = E_OUTOFMEMORY;
  666. ceERRORPRINTLINE("ceConvertWszToBstr", hr);
  667. goto error;
  668. }
  669. error:
  670. if (NULL != pbEncoded)
  671. {
  672. LocalFree(pbEncoded);
  673. }
  674. return(_SetErrorInfo(hr, L"CCertEncodeCRLDistInfo::Encode"));
  675. }
  676. //+--------------------------------------------------------------------------
  677. // CCertEncodeCRLDistInfo::_SetErrorInfo -- set error object information
  678. //
  679. // Returns passed HRESULT
  680. //+--------------------------------------------------------------------------
  681. HRESULT
  682. CCertEncodeCRLDistInfo::_SetErrorInfo(
  683. IN HRESULT hrError,
  684. IN WCHAR const *pwszDescription)
  685. {
  686. assert(FAILED(hrError) || S_OK == hrError || S_FALSE == hrError);
  687. if (FAILED(hrError))
  688. {
  689. HRESULT hr;
  690. hr = ceDispatchSetErrorInfo(
  691. hrError,
  692. pwszDescription,
  693. wszCLASS_CERTENCODECRLDISTINFO,
  694. &IID_ICertEncodeCRLDistInfo);
  695. assert(hr == hrError);
  696. }
  697. return(hrError);
  698. }