summaryrefslogtreecommitdiff
path: root/plugins/CryptoPP/src/cpp_pgpw.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/CryptoPP/src/cpp_pgpw.cpp')
-rw-r--r--plugins/CryptoPP/src/cpp_pgpw.cpp92
1 files changed, 37 insertions, 55 deletions
diff --git a/plugins/CryptoPP/src/cpp_pgpw.cpp b/plugins/CryptoPP/src/cpp_pgpw.cpp
index 96a6baece4..85de0513f0 100644
--- a/plugins/CryptoPP/src/cpp_pgpw.cpp
+++ b/plugins/CryptoPP/src/cpp_pgpw.cpp
@@ -6,7 +6,6 @@ UINT pgpVer;
HRSRC hRS_pgp;
PBYTE pRS_pgp;
-
int __cdecl _pgp_init(void);
int __cdecl _pgp_done(void);
int __cdecl _pgp_open_keyrings(LPSTR,LPSTR);
@@ -35,15 +34,14 @@ LPSTR (__cdecl *p_pgp_decrypt_keydb)(LPCSTR);
LPSTR (__cdecl *p_pgp_encrypt_key)(LPCSTR,LPCSTR);
LPSTR (__cdecl *p_pgp_decrypt_key)(LPCSTR,LPCSTR);
-
#define GPA(x) \
-{ \
+{ \
*((PVOID*)&p##x) = (PVOID)GetProcAddress(mod, TEXT(#x)); \
- if (!p##x) return 0; \
+ if (!p##x) return 0; \
}
-int load_pgpsdk_dll(HMODULE mod) {
-
+int load_pgpsdk_dll(HMODULE mod)
+{
GPA(_pgp_init);
GPA(_pgp_done);
GPA(_pgp_open_keyrings);
@@ -62,17 +60,16 @@ int load_pgpsdk_dll(HMODULE mod) {
#undef GPA
-
-#define GPA(x) \
-{ \
- *((PVOID*)&p##x) = (PVOID)MemGetProcAddress(mod, TEXT(#x)); \
- if (!p##x) { \
- return 0; \
- } \
+#define GPA(x) \
+{ \
+ *((PVOID*)&p##x) = (PVOID)GetProcAddress(mod, TEXT(#x)); \
+ if (!p##x) { \
+ return 0; \
+ } \
}
-int load_pgpsdk_mem(HMODULE mod) {
-
+int load_pgpsdk_mem(HMODULE mod)
+{
GPA(_pgp_init);
GPA(_pgp_done);
GPA(_pgp_open_keyrings);
@@ -85,28 +82,25 @@ int load_pgpsdk_mem(HMODULE mod) {
GPA(_pgp_decrypt_keydb);
GPA(_pgp_encrypt_key);
GPA(_pgp_decrypt_key);
-
return 1;
}
#undef GPA
-
int __cdecl pgp_init()
{
- if ( !hPGPPRIV ) {
+ if (!hPGPPRIV) {
// create context for private pgp keys
- hPGPPRIV = (HANDLE) cpp_create_context(MODE_PGP|MODE_PRIV_KEY);
- pCNTX tmp = (pCNTX) hPGPPRIV;
- tmp->pdata = (PBYTE) malloc(sizeof(PGPDATA));
- memset(tmp->pdata,0,sizeof(PGPDATA));
+ hPGPPRIV = (HANDLE)cpp_create_context(MODE_PGP | MODE_PRIV_KEY);
+ pCNTX tmp = (pCNTX)hPGPPRIV;
+ tmp->pdata = (PBYTE)malloc(sizeof(PGPDATA));
+ memset(tmp->pdata, 0, sizeof(PGPDATA));
}
hpgpsdk = g_hInst;
return 0;
}
-
int __cdecl pgp_done()
{
int r = 0;
@@ -118,19 +112,16 @@ int __cdecl pgp_done()
return r;
}
-
int __cdecl pgp_open_keyrings(LPSTR PubRingPath, LPSTR SecRingPath)
{
- return p_pgp_open_keyrings(PubRingPath,SecRingPath);
+ return p_pgp_open_keyrings(PubRingPath, SecRingPath);
}
-
int __cdecl pgp_close_keyrings()
{
return p_pgp_close_keyrings();
}
-
int __cdecl pgp_get_version()
{
return pgpVer;
@@ -144,13 +135,13 @@ LPSTR __cdecl pgp_get_error()
LPSTR __cdecl pgp_encrypt(pCNTX ptr, LPCSTR szPlainMsg)
{
ptr->error = ERROR_NONE;
- pPGPDATA p = (pPGPDATA) ptr->pdata;
+ pPGPDATA p = (pPGPDATA)ptr->pdata;
LPSTR szEncMsg;
- if (p->pgpKey)
- szEncMsg = p_pgp_encrypt_key(szPlainMsg,(LPCSTR)p->pgpKey);
+ if (p->pgpKey)
+ szEncMsg = p_pgp_encrypt_key(szPlainMsg, (LPCSTR)p->pgpKey);
else
- szEncMsg = p_pgp_encrypt_keydb(szPlainMsg,p->pgpKeyID);
+ szEncMsg = p_pgp_encrypt_keydb(szPlainMsg, p->pgpKeyID);
if (!szEncMsg) {
replaceStr(ptr->tmp, NULL);
return 0;
@@ -162,7 +153,6 @@ LPSTR __cdecl pgp_encrypt(pCNTX ptr, LPCSTR szPlainMsg)
return ptr->tmp;
}
-
LPSTR __cdecl pgp_decrypt(pCNTX ptr, LPCSTR szEncMsg)
{
ptr->error = ERROR_NONE;
@@ -171,9 +161,9 @@ LPSTR __cdecl pgp_decrypt(pCNTX ptr, LPCSTR szEncMsg)
if (!szPlainMsg) {
ptr = get_context_on_id(hPGPPRIV); // find private pgp keys
if (ptr) {
- pPGPDATA p = (pPGPDATA) ptr->pdata;
+ pPGPDATA p = (pPGPDATA)ptr->pdata;
if (p->pgpKey)
- szPlainMsg = p_pgp_decrypt_key(szEncMsg,(LPCSTR)p->pgpKey);
+ szPlainMsg = p_pgp_decrypt_key(szEncMsg, (LPCSTR)p->pgpKey);
}
if (!szPlainMsg) {
replaceStr(ptr->tmp, NULL);
@@ -186,12 +176,11 @@ LPSTR __cdecl pgp_decrypt(pCNTX ptr, LPCSTR szEncMsg)
return ptr->tmp;
}
-
LPSTR __cdecl pgp_encode(HANDLE context, LPCSTR szPlainMsg)
{
pCNTX ptr = get_context_on_id(context); if (!ptr) return NULL;
- pPGPDATA p = (pPGPDATA) cpp_alloc_pdata(ptr);
- if ( !p->pgpKeyID && !p->pgpKey ) {
+ pPGPDATA p = (pPGPDATA)cpp_alloc_pdata(ptr);
+ if (!p->pgpKeyID && !p->pgpKey) {
ptr->error = ERROR_NO_PGP_KEY;
return NULL;
}
@@ -200,7 +189,6 @@ LPSTR __cdecl pgp_encode(HANDLE context, LPCSTR szPlainMsg)
return pgp_encrypt(ptr, szPlainMsg);
}
-
LPSTR __cdecl pgp_decode(HANDLE context, LPCSTR szEncMsg)
{
pCNTX ptr = get_context_on_id(context);
@@ -210,9 +198,9 @@ LPSTR __cdecl pgp_decode(HANDLE context, LPCSTR szEncMsg)
LPSTR szOldMsg = pgp_decrypt(ptr, szEncMsg);
if (szOldMsg) {
- if ( !is_7bit_string(szOldMsg) && !is_utf8_string(szOldMsg) ) {
- int slen = (int)strlen(szOldMsg)+1;
- LPWSTR wszMsg = (LPWSTR) alloca(slen*sizeof(WCHAR));
+ if (!is_7bit_string(szOldMsg) && !is_utf8_string(szOldMsg)) {
+ int slen = (int)strlen(szOldMsg) + 1;
+ LPWSTR wszMsg = (LPWSTR)alloca(slen*sizeof(WCHAR));
MultiByteToWideChar(CP_ACP, 0, szOldMsg, -1, wszMsg, slen*sizeof(WCHAR));
szNewMsg = _strdup(utf8encode(wszMsg));
}
@@ -222,48 +210,42 @@ LPSTR __cdecl pgp_decode(HANDLE context, LPCSTR szEncMsg)
return szNewMsg;
}
-
int __cdecl pgp_set_priv_key(LPCSTR LocalKey)
{
- return pgp_set_key(hPGPPRIV,LocalKey);
+ return pgp_set_key(hPGPPRIV, LocalKey);
}
-
int __cdecl pgp_set_key(HANDLE context, LPCSTR RemoteKey)
{
pCNTX ptr = get_context_on_id(context); if (!ptr) return 0;
- pPGPDATA p = (pPGPDATA) cpp_alloc_pdata(ptr);
+ pPGPDATA p = (pPGPDATA)cpp_alloc_pdata(ptr);
ptr->error = ERROR_NONE;
SAFE_FREE(p->pgpKey);
- p->pgpKey = (PBYTE) _strdup(RemoteKey);
+ p->pgpKey = (PBYTE)_strdup(RemoteKey);
return 1;
}
-
int __cdecl pgp_set_keyid(HANDLE context, PVOID RemoteKeyID)
{
pCNTX ptr = get_context_on_id(context); if (!ptr) return 0;
- pPGPDATA p = (pPGPDATA) cpp_alloc_pdata(ptr);
+ pPGPDATA p = (pPGPDATA)cpp_alloc_pdata(ptr);
ptr->error = ERROR_NONE;
SAFE_FREE(p->pgpKeyID);
- p->pgpKeyID = (PBYTE) malloc(p_pgp_size_keyid());
- memcpy(p->pgpKeyID,RemoteKeyID,p_pgp_size_keyid());
+ p->pgpKeyID = (PBYTE)malloc(p_pgp_size_keyid());
+ memcpy(p->pgpKeyID, RemoteKeyID, p_pgp_size_keyid());
return 1;
}
-
int __cdecl pgp_size_keyid()
{
return p_pgp_size_keyid();
}
-
-PVOID __cdecl pgp_select_keyid(HWND hDlg,LPSTR szKeyID)
+PVOID __cdecl pgp_select_keyid(HWND hDlg, LPSTR szKeyID)
{
- return p_pgp_select_keyid(hDlg,szKeyID);
+ return p_pgp_select_keyid(hDlg, szKeyID);
}
-