Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

CryptMsg.h

Go to the documentation of this file.
00001 /*  CryptMsg.h - cryto API message wrapper
00002     Copyright (C) 2001-2004 Mark Weaver
00003     Written by Mark Weaver <mark@npsl.co.uk>
00004 
00005     Part of the Open-Win32 library.
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public
00017     License along with this library; if not, write to the
00018     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019     Boston, MA  02111-1307, USA.
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 } // namespace OW32
00103 
00104 #endif // OW32_CryptMsg_h

Generated on Sun Jun 5 01:29:17 2005 for OW32 by  doxygen 1.3.9.1