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.

125 lines
3.2 KiB

  1. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Microsoft Windows, Copyright (C) Microsoft Corporation, 2000
  3. File: Utilities.h
  4. Content: Declaration of CUtilities.
  5. History: 11-15-99 dsie created
  6. ------------------------------------------------------------------------------*/
  7. #ifndef __UTILITIES_H_
  8. #define __UTILITIES_H_
  9. #include "Resource.h"
  10. #include "Error.h"
  11. #include "Lock.h"
  12. #include "Debug.h"
  13. ////////////////////////////////////////////////////////////////////////////////
  14. //
  15. // CUtilities
  16. //
  17. class ATL_NO_VTABLE CUtilities :
  18. public CComObjectRootEx<CComMultiThreadModel>,
  19. public CComCoClass<CUtilities, &CLSID_Utilities>,
  20. public ICAPICOMError<CUtilities, &IID_IUtilities>,
  21. public IDispatchImpl<IUtilities, &IID_IUtilities, &LIBID_CAPICOM,
  22. CAPICOM_MAJOR_VERSION, CAPICOM_MINOR_VERSION>,
  23. public IObjectSafetyImpl<CUtilities, INTERFACESAFE_FOR_UNTRUSTED_CALLER |
  24. INTERFACESAFE_FOR_UNTRUSTED_DATA>
  25. {
  26. public:
  27. CUtilities()
  28. {
  29. }
  30. HRESULT FinalConstruct()
  31. {
  32. HRESULT hr;
  33. if (FAILED(hr = m_Lock.Initialized()))
  34. {
  35. DebugTrace("Error [%#x]: Critical section could not be created for Certificate object.\n", hr);
  36. return hr;
  37. }
  38. m_hCryptProv = NULL;
  39. return S_OK;
  40. }
  41. void FinalRelease()
  42. {
  43. if (m_hCryptProv)
  44. {
  45. ::CryptReleaseContext(m_hCryptProv, 0);
  46. }
  47. }
  48. DECLARE_REGISTRY_RESOURCEID(IDR_UTILITIES)
  49. DECLARE_PROTECT_FINAL_CONSTRUCT()
  50. BEGIN_COM_MAP(CUtilities)
  51. COM_INTERFACE_ENTRY(IUtilities)
  52. COM_INTERFACE_ENTRY(IDispatch)
  53. COM_INTERFACE_ENTRY(IObjectSafety)
  54. COM_INTERFACE_ENTRY(ISupportErrorInfo)
  55. END_COM_MAP()
  56. BEGIN_CATEGORY_MAP(CUtilities)
  57. IMPLEMENTED_CATEGORY(CATID_SafeForScripting)
  58. IMPLEMENTED_CATEGORY(CATID_SafeForInitializing)
  59. END_CATEGORY_MAP()
  60. //
  61. // IUtilities
  62. //
  63. public:
  64. STDMETHOD(GetRandom)
  65. (/*[in, defaultvalue(8)]*/ long Length,
  66. /*[in, defaultvalue(CAPICOM_ENCODE_BINARY)]*/ CAPICOM_ENCODING_TYPE EncodingType,
  67. /*[out, retval]*/ BSTR * pVal);
  68. STDMETHOD(Base64Encode)
  69. (/*[in]*/ BSTR SrcString,
  70. /*[out, retval]*/ BSTR * pVal);
  71. STDMETHOD(Base64Decode)
  72. (/*[in]*/ BSTR EncodedString,
  73. /*[out, retval]*/ BSTR * pVal);
  74. STDMETHOD(BinaryToHex)
  75. (/*[in]*/ BSTR BinaryString,
  76. /*[out, retval]*/ BSTR * pVal);
  77. STDMETHOD(HexToBinary)
  78. (/*[in]*/ BSTR HexString,
  79. /*[out, retval]*/ BSTR * pVal);
  80. STDMETHOD(BinaryStringToByteArray)
  81. (/*[in]*/ BSTR BinaryString,
  82. /*[out,retval]*/ VARIANT * pVal);
  83. STDMETHOD(ByteArrayToBinaryString)
  84. (/*[in]*/ VARIANT varByteArray,
  85. /*[out, retval]*/ BSTR * pVal);
  86. STDMETHOD(LocalTimeToUTCTime)
  87. (/*[in]*/ DATE LocalTime,
  88. /*[out, retval] */ DATE * pVal);
  89. STDMETHOD(UTCTimeToLocalTime)
  90. (/*[in]*/ DATE UTCTime,
  91. /*[out, retval]*/ DATE * pVal);
  92. private:
  93. CLock m_Lock;
  94. HCRYPTPROV m_hCryptProv;
  95. };
  96. #endif //__UTILITIES_H_