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.

124 lines
3.2 KiB

  1. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Microsoft Windows, Copyright (C) Microsoft Corporation, 2000
  3. File: Decoder.cpp
  4. Contents: Implementation of decoder routines.
  5. Remarks:
  6. History: 11-15-2001 dsie created
  7. ------------------------------------------------------------------------------*/
  8. #include "StdAfx.h"
  9. #include "CAPICOM.h"
  10. #include "Decoder.h"
  11. #include "CertificatePolicies.h"
  12. typedef HRESULT (* PFNDECODERFACTORY) (LPSTR pszObjId,
  13. CRYPT_DATA_BLOB * pEncodedBlob,
  14. IDispatch ** ppIDispatch);
  15. typedef struct _tagDecoderEntry
  16. {
  17. LPCSTR pszObjId;
  18. PFNDECODERFACTORY pfnDecoderFactory;
  19. } DECODER_ENTRY;
  20. static DECODER_ENTRY g_DecoderEntries[] =
  21. {
  22. {szOID_CERT_POLICIES, CreateCertificatePoliciesObject},
  23. };
  24. ////////////////////////////////////////////////////////////////////////////////
  25. //
  26. // Exported functions.
  27. //
  28. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  29. Function : CreateDecoderObject
  30. Synopsis : Create a known decoder object and return the IDispatch.
  31. Parameter: LPSTR pszOid - OID string.
  32. CRYPT_DATA_BLOB * pEncodedBlob - Pointer to encoded data blob.
  33. IDispatch ** ppIDecoder - Pointer to pointer IDispatch
  34. to recieve the interface pointer.
  35. Remark :
  36. ------------------------------------------------------------------------------*/
  37. HRESULT CreateDecoderObject (LPSTR pszOid,
  38. CRYPT_DATA_BLOB * pEncodedBlob,
  39. IDispatch ** ppIDecoder)
  40. {
  41. HRESULT hr = S_OK;
  42. DebugTrace("Entering CreateDecoderObject().\n");
  43. //
  44. // Sanity check.
  45. //
  46. ATLASSERT(pszOid);
  47. ATLASSERT(pEncodedBlob);
  48. ATLASSERT(ppIDecoder);
  49. try
  50. {
  51. //
  52. // Initialize.
  53. //
  54. *ppIDecoder = NULL;
  55. //
  56. // Find the decoder, if available.
  57. //
  58. for (DWORD i = 0; i < ARRAYSIZE(g_DecoderEntries); i++)
  59. {
  60. if (0 == ::strcmp(pszOid, g_DecoderEntries[i].pszObjId))
  61. {
  62. DebugTrace("Info: found a decoder for OID = %s.\n", pszOid);
  63. //
  64. // Call the corresponding decoder factory to create the decoder object.
  65. //
  66. if (FAILED(hr = g_DecoderEntries[i].pfnDecoderFactory(pszOid, pEncodedBlob, ppIDecoder)))
  67. {
  68. DebugTrace("Error [%#x]: g_DecoderEntries[i].pfnDecoderFactory() failed.\n", hr);
  69. goto ErrorExit;
  70. }
  71. break;
  72. }
  73. }
  74. }
  75. catch(...)
  76. {
  77. hr = E_POINTER;
  78. DebugTrace("Exception: invalid parameter.\n");
  79. goto ErrorExit;
  80. }
  81. CommonExit:
  82. DebugTrace("Leaving CreateDecoderObject().\n");
  83. return hr;
  84. ErrorExit:
  85. //
  86. // Sanity check.
  87. //
  88. ATLASSERT(FAILED(hr));
  89. goto CommonExit;
  90. }