00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00026 #ifndef OW32_CryptMsg_h
00027 #define OW32_CryptMsg_h
00028
00029 #include <OW32/XHCRYPTMSG.h>
00030
00031 namespace OW32 {
00032
00034 class OW32_LIB_EXPORT CCryptMsg
00035 {
00036 XHCRYPTMSG m_hMsg;
00037
00038 CCryptMsg operator=(const CCryptMsg& );
00039 CCryptMsg(const CCryptMsg& );
00040
00041 public:
00042 CCryptMsg() {}
00043
00044 CCryptMsg(HCRYPTMSG hMsg) :
00045 m_hMsg(hMsg)
00046 {
00047 }
00048
00049 void Close() { m_hMsg.Close(); }
00050
00051 BOOL OpenToDecode(DWORD dwFlags = 0, DWORD dwMsgType = 0,
00052 HCRYPTPROV hCryptProv = 0, PCERT_INFO pRecipientInfo = 0,
00053 PCMSG_STREAM_INFO pStreamInfo = 0, DWORD dwMsgEncodingType = MY_ENCODING_TYPE)
00054 {
00055 Close();
00056 m_hMsg = CryptMsgOpenToDecode(dwMsgEncodingType, dwFlags, dwMsgType,
00057 hCryptProv, pRecipientInfo, pStreamInfo);
00058 if (!m_hMsg) return FALSE;
00059 return TRUE;
00060 }
00061
00062 BOOL Update(const BYTE* pbData, DWORD cbData, BOOL final = FALSE)
00063 {
00064 return CryptMsgUpdate(m_hMsg, pbData, cbData, final);
00065 }
00066
00067 BOOL GetParam(DWORD dwParamType, PVOID pvData, PDWORD pcbData, DWORD dwIndex=0)
00068 {
00069 return CryptMsgGetParam(m_hMsg, dwParamType, dwIndex, pvData, pcbData);
00070 }
00071
00072 BOOL GetParam(DWORD dwParamType, PVOID* pvData, PDWORD pcbData=NULL, DWORD dwIndex=0)
00073 {
00074 DWORD dwAllocSize=0;
00075 if (!CryptMsgGetParam(m_hMsg, dwParamType, dwIndex, NULL, &dwAllocSize))
00076 return FALSE;
00077 *pvData = LocalAlloc(0, dwAllocSize);
00078 if (!*pvData) return FALSE;
00079 if (!CryptMsgGetParam(m_hMsg, dwParamType, dwIndex, *pvData, &dwAllocSize)) {
00080 LocalFree(*pvData);
00081 *pvData = 0;
00082 return FALSE;
00083 }
00084 if (pcbData) *pcbData = dwAllocSize;
00085 return TRUE;
00086 }
00087
00088 BOOL GetCertCount(DWORD* pCertCount)
00089 {
00090 DWORD dwNumRead=sizeof(DWORD);
00091 return CryptMsgGetParam(m_hMsg, CMSG_CERT_COUNT_PARAM, 0, pCertCount, &dwNumRead);
00092 }
00093
00094 BOOL GetCert(PBYTE* ppbEncodedData, DWORD* pcbEncodedData, DWORD dwIndex=0)
00095 {
00096 return GetParam(CMSG_CERT_PARAM, (PVOID*)ppbEncodedData, pcbEncodedData, dwIndex);
00097 }
00098
00099 operator HCRYPTMSG() { return m_hMsg; }
00100 };
00101
00102 }
00103
00104 #endif // OW32_CryptMsg_h