diff options
Diffstat (limited to 'src/dkim.cpp')
-rw-r--r-- | src/dkim.cpp | 42 |
1 files changed, 19 insertions, 23 deletions
diff --git a/src/dkim.cpp b/src/dkim.cpp index 8f07519..ff21423 100644 --- a/src/dkim.cpp +++ b/src/dkim.cpp @@ -27,8 +27,6 @@ #include "dkimverify.h" -#define DKIMID ('D' | 'K' << 8 | 'I' << 16 | 'M' << 24) - /* taken from removed file "ressource.h" */ #ifdef VERSION #define VERSION_STRING VERSION @@ -36,21 +34,19 @@ #define VERSION_STRING "1.4.0" #endif +struct DKIMContext { + CDKIMSign *signObject; + CDKIMVerify *verifyObject; +}; -static void InitContext(DKIMContext *pContext, bool bSign, void *pObject) +DKIMContext *DKIMContextNew() { - pContext->reserved1 = DKIMID; - pContext->reserved2 = bSign ? 1 : 0; - pContext->reserved3 = pObject; + return new DKIMContext; } -static void *ValidateContext(DKIMContext *pContext, bool bSign) +void DKIMContextFree(DKIMContext *ctx) { - if (pContext->reserved1 != DKIMID) return NULL; - - if (pContext->reserved2 != (unsigned int)(bSign ? 1 : 0)) return NULL; - - return pContext->reserved3; + delete ctx; } int DKIM_CALL DKIMSignInit(DKIMContext *pSignContext, DKIMSignOptions *pOptions) @@ -64,13 +60,13 @@ int DKIM_CALL DKIMSignInit(DKIMContext *pSignContext, DKIMSignOptions *pOptions) if (nRet != DKIM_SUCCESS) delete pSign; } - if (nRet == DKIM_SUCCESS) InitContext(pSignContext, true, pSign); + if (nRet == DKIM_SUCCESS) pSignContext->signObject = pSign; return nRet; } int DKIM_CALL DKIMSignProcess(DKIMContext *pSignContext, char *szBuffer, int nBufLength) { - CDKIMSign *pSign = (CDKIMSign *)ValidateContext(pSignContext, true); + CDKIMSign *pSign = pSignContext->signObject; if (pSign) return pSign->Process(szBuffer, nBufLength, false); return DKIM_INVALID_CONTEXT; @@ -79,7 +75,7 @@ int DKIM_CALL DKIMSignProcess(DKIMContext *pSignContext, char *szBuffer, int nBu int DKIM_CALL DKIMSignGetSig2( DKIMContext *pSignContext, char *szRSAPrivKey, char *szECCPrivKey, char **pszSignature) { - CDKIMSign *pSign = (CDKIMSign *)ValidateContext(pSignContext, true); + CDKIMSign *pSign = pSignContext->signObject; if (pSign) return pSign->GetSig2(szRSAPrivKey, szECCPrivKey, pszSignature); return DKIM_INVALID_CONTEXT; @@ -87,11 +83,11 @@ int DKIM_CALL DKIMSignGetSig2( void DKIM_CALL DKIMSignFree(DKIMContext *pSignContext) { - CDKIMSign *pSign = (CDKIMSign *)ValidateContext(pSignContext, true); + CDKIMSign *pSign = pSignContext->signObject; if (pSign) { delete pSign; - pSignContext->reserved3 = NULL; + pSignContext->signObject = NULL; } } @@ -106,7 +102,7 @@ int DKIM_CALL DKIMVerifyInit(DKIMContext *pVerifyContext, DKIMVerifyOptions *pOp if (nRet != DKIM_SUCCESS) delete pVerify; } - if (nRet == DKIM_SUCCESS) InitContext(pVerifyContext, false, pVerify); + if (nRet == DKIM_SUCCESS) pVerifyContext->verifyObject = pVerify; return nRet; } @@ -114,7 +110,7 @@ int DKIM_CALL DKIMVerifyInit(DKIMContext *pVerifyContext, DKIMVerifyOptions *pOp int DKIM_CALL DKIMVerifyProcess(DKIMContext *pVerifyContext, const char *const szBuffer, int nBufLength) { - CDKIMVerify *pVerify = (CDKIMVerify *)ValidateContext(pVerifyContext, false); + CDKIMVerify *pVerify = pVerifyContext->verifyObject; if (pVerify) return pVerify->Process(szBuffer, nBufLength, false); @@ -123,7 +119,7 @@ int DKIM_CALL DKIMVerifyProcess(DKIMContext *pVerifyContext, const char *const s int DKIM_CALL DKIMVerifyResults(DKIMContext *pVerifyContext) { - CDKIMVerify *pVerify = (CDKIMVerify *)ValidateContext(pVerifyContext, false); + CDKIMVerify *pVerify = pVerifyContext->verifyObject; if (pVerify) return pVerify->GetResults(); return DKIM_INVALID_CONTEXT; @@ -134,7 +130,7 @@ int DKIM_CALL DKIMVerifyGetDetails( { szPractices[0] = '\0'; - CDKIMVerify *pVerify = (CDKIMVerify *)ValidateContext(pVerifyContext, false); + CDKIMVerify *pVerify = pVerifyContext->verifyObject; if (pVerify) { strcpy(szPractices, pVerify->GetPractices()); @@ -147,11 +143,11 @@ int DKIM_CALL DKIMVerifyGetDetails( void DKIM_CALL DKIMVerifyFree(DKIMContext *pVerifyContext) { - CDKIMVerify *pVerify = (CDKIMVerify *)ValidateContext(pVerifyContext, false); + CDKIMVerify *pVerify = pVerifyContext->verifyObject; if (pVerify) { delete pVerify; - pVerifyContext->reserved3 = NULL; + pVerifyContext->verifyObject = NULL; } } |