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.

115 lines
2.9 KiB

  1. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Microsoft Windows, Copyright (C) Microsoft Corporation, 2000
  3. File: HashedData.h
  4. Content: Declaration of CHashedData.
  5. History: 11-12-2001 dsie created
  6. ------------------------------------------------------------------------------*/
  7. #ifndef __HASHEDDATA_H_
  8. #define __HASHEDDATA_H_
  9. #include "Resource.h"
  10. #include "Error.h"
  11. #include "Lock.h"
  12. #include "Debug.h"
  13. typedef enum
  14. {
  15. CAPICOM_HASH_INIT_STATE = 0,
  16. CAPICOM_HASH_DATA_STATE = 1,
  17. } CAPICOM_HASH_STATE;
  18. ////////////////////////////////////////////////////////////////////////////////
  19. //
  20. // CHashedData
  21. //
  22. class ATL_NO_VTABLE CHashedData :
  23. public CComObjectRootEx<CComMultiThreadModel>,
  24. public CComCoClass<CHashedData, &CLSID_HashedData>,
  25. public ICAPICOMError<CHashedData, &IID_IHashedData>,
  26. public IDispatchImpl<IHashedData, &IID_IHashedData, &LIBID_CAPICOM,
  27. CAPICOM_MAJOR_VERSION, CAPICOM_MINOR_VERSION>,
  28. public IObjectSafetyImpl<CHashedData, INTERFACESAFE_FOR_UNTRUSTED_CALLER |
  29. INTERFACESAFE_FOR_UNTRUSTED_DATA>
  30. {
  31. public:
  32. CHashedData()
  33. {
  34. }
  35. DECLARE_REGISTRY_RESOURCEID(IDR_HASHEDDATA)
  36. DECLARE_PROTECT_FINAL_CONSTRUCT()
  37. BEGIN_COM_MAP(CHashedData)
  38. COM_INTERFACE_ENTRY(IHashedData)
  39. COM_INTERFACE_ENTRY(IDispatch)
  40. COM_INTERFACE_ENTRY(IObjectSafety)
  41. COM_INTERFACE_ENTRY(ISupportErrorInfo)
  42. END_COM_MAP()
  43. BEGIN_CATEGORY_MAP(CHashedData)
  44. IMPLEMENTED_CATEGORY(CATID_SafeForScripting)
  45. IMPLEMENTED_CATEGORY(CATID_SafeForInitializing)
  46. END_CATEGORY_MAP()
  47. HRESULT FinalConstruct()
  48. {
  49. HRESULT hr;
  50. if (FAILED(hr = m_Lock.Initialized()))
  51. {
  52. DebugTrace("Error [%#x]: Critical section could not be created for Certificate object.\n", hr);
  53. return hr;
  54. }
  55. m_hCryptProv = NULL;
  56. m_hCryptHash = NULL;
  57. m_Algorithm = CAPICOM_HASH_ALGORITHM_SHA1;
  58. m_HashState = CAPICOM_HASH_INIT_STATE;
  59. return S_OK;
  60. }
  61. void FinalRelease()
  62. {
  63. if (m_hCryptHash)
  64. {
  65. ::CryptDestroyHash(m_hCryptHash);
  66. }
  67. if (m_hCryptProv)
  68. {
  69. ::CryptReleaseContext(m_hCryptProv, 0);
  70. }
  71. }
  72. //
  73. // IHashedData
  74. //
  75. public:
  76. STDMETHOD(get_Value)
  77. (/*[out, retval]*/ BSTR * pVal);
  78. STDMETHOD(get_Algorithm)
  79. (/*[out, retval]*/ CAPICOM_HASH_ALGORITHM * pVal);
  80. STDMETHOD(put_Algorithm)
  81. (/*[in]*/ CAPICOM_HASH_ALGORITHM newVal);
  82. STDMETHOD(Hash)
  83. (/*[in]*/ BSTR newVal);
  84. private:
  85. CLock m_Lock;
  86. HCRYPTPROV m_hCryptProv;
  87. HCRYPTHASH m_hCryptHash;
  88. CAPICOM_HASH_ALGORITHM m_Algorithm;
  89. CAPICOM_HASH_STATE m_HashState;
  90. };
  91. #endif //__HASHEDDATA_H_