summaryrefslogtreecommitdiffabout
path: root/pwmanager/pwmanager/pwmdoc.cpp
authorulf69 <ulf69>2004-10-15 22:47:12 (UTC)
committer ulf69 <ulf69>2004-10-15 22:47:12 (UTC)
commit1821dcc08c8f6f2bc0fdb991c335ed03262d1443 (patch) (side-by-side diff)
tree93249cb2cc3fbb57cc8cf6688afbc252629b62a4 /pwmanager/pwmanager/pwmdoc.cpp
parent71ee1be533cdbe7ce50c4f617254011fc640e88e (diff)
downloadkdepimpi-1821dcc08c8f6f2bc0fdb991c335ed03262d1443.zip
kdepimpi-1821dcc08c8f6f2bc0fdb991c335ed03262d1443.tar.gz
kdepimpi-1821dcc08c8f6f2bc0fdb991c335ed03262d1443.tar.bz2
*** empty log message ***
Diffstat (limited to 'pwmanager/pwmanager/pwmdoc.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/pwmdoc.cpp77
1 files changed, 16 insertions, 61 deletions
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp
index 4ad392e..a5df8f0 100644
--- a/pwmanager/pwmanager/pwmdoc.cpp
+++ b/pwmanager/pwmanager/pwmdoc.cpp
@@ -28,9 +28,8 @@
#include "compressbzip2.h"
#include "randomizer.h"
#include "pwminit.h"
-#ifndef PWM_EMBEDDED
-//US #include "libgryptif.h"
-#else
+#include "libgcryptif.h"
+#ifdef PWM_EMBEDDED
#include "pwmprefs.h"
#include "kglobal.h"
#endif
@@ -59,6 +58,18 @@
#include <unistd.h>
#include <stdint.h>
+
+#ifdef PWM_EMBEDDED
+#ifndef Q_LONG
+#define Q_LONG long
+#endif
+
+#ifndef Q_ULONG
+#define Q_ULONG unsigned long
+#endif
+#endif //PWM_EMBEDDED
+
+
//TODO: reset to its normal value.
#define META_CHECK_TIMER_INTERVAL 10/*300*/ /* sek */
@@ -352,13 +363,9 @@ PwMerror PwMDoc::saveDoc(char compress, const QString *file)
unsetDocStatFlag(DOC_STAT_USE_CHIPCARD);
}
}
-#ifndef PWM_EMBEDDED
+
int _cryptAlgo = conf()->confGlobCryptAlgo();
int _hashAlgo = conf()->confGlobHashAlgo();
-#else
- int _cryptAlgo = PWM_CRYPT_BLOWFISH;
- int _hashAlgo = PWM_HASH_SHA1;
-#endif
// sanity check for the selected algorithms
if (_cryptAlgo < PWM_CRYPT_BLOWFISH ||
@@ -599,7 +606,6 @@ PwMerror PwMDoc::writeFileHeader(char keyHash, char dataHash, char crypt, char c
PWM_ASSERT(pw);
PWM_ASSERT(f);
PWM_ASSERT(listView);
-#ifndef PWM_EMBEDDED
if (f->writeBlock(FILE_ID_HEADER, strlen(FILE_ID_HEADER)) !=
static_cast<Q_LONG>(strlen(FILE_ID_HEADER))) {
return e_writeFile;
@@ -614,21 +620,6 @@ PwMerror PwMDoc::writeFileHeader(char keyHash, char dataHash, char crypt, char c
return e_writeFile;
}
-#else
- if (f->writeBlock(FILE_ID_HEADER, strlen(FILE_ID_HEADER)) !=
- (long)(strlen(FILE_ID_HEADER))) {
- return e_writeFile;
- }
- if (f->putch(PWM_FILE_VER) == -1 ||
- f->putch(keyHash) == -1 ||
- f->putch(dataHash) == -1 ||
- f->putch(crypt) == -1 ||
- f->putch(compress) == -1 ||
- f->putch((getDocStatFlag(DOC_STAT_USE_CHIPCARD)) ?
- ((char)(0x01)) : ((char)(0x00))) == -1) {
- return e_writeFile;
- }
-#endif
// write bytes of NUL-data. These bytes are reserved for future-use.
const int bufSize = 64;
char tmp_buf[bufSize];
@@ -646,7 +637,6 @@ PwMerror PwMDoc::writeFileHeader(char keyHash, char dataHash, char crypt, char c
return e_writeFile;
break;
}
-#ifndef PWM_EMBEDDED
case PWM_HASH_SHA256:
/*... fall through */
case PWM_HASH_SHA384:
@@ -676,7 +666,6 @@ PwMerror PwMDoc::writeFileHeader(char keyHash, char dataHash, char crypt, char c
delete [] buf;
break;
}
-#endif
default: {
return e_hashNotImpl;
} }
@@ -762,7 +751,6 @@ PwMerror PwMDoc::checkHeader(char *cryptAlgo, QString *pw, char *compress,
return e_wrongPw; // hash doesn't match (wrong key)
break;
}
-#ifndef PWM_EMBEDDED
case PWM_HASH_SHA256:
/*... fall through */
case PWM_HASH_SHA384:
@@ -795,7 +783,6 @@ PwMerror PwMDoc::checkHeader(char *cryptAlgo, QString *pw, char *compress,
return e_wrongPw; // hash doesn't match (wrong key)
break;
}
-#endif
default: {
return e_hashNotImpl;
} }
@@ -805,7 +792,6 @@ PwMerror PwMDoc::checkHeader(char *cryptAlgo, QString *pw, char *compress,
case PWM_HASH_SHA1:
hashLen = SHA1_HASH_LEN_BYTE;
break;
-#ifndef PWM_EMBEDDED
case PWM_HASH_SHA256:
/*... fall through */
case PWM_HASH_SHA384:
@@ -821,7 +807,6 @@ PwMerror PwMDoc::checkHeader(char *cryptAlgo, QString *pw, char *compress,
return e_hashNotImpl;
break;
}
-#endif
default:
return e_hashNotImpl;
}
@@ -865,7 +850,6 @@ PwMerror PwMDoc::writeDataHash(char dataHash, string *d, QFile *f)
return e_writeFile;
break;
}
-#ifndef PWM_EMBEDDED
case PWM_HASH_SHA256:
/*... fall through */
case PWM_HASH_SHA384:
@@ -894,7 +878,6 @@ PwMerror PwMDoc::writeDataHash(char dataHash, string *d, QFile *f)
delete [] buf;
break;
}
-#endif
default: {
return e_hashNotImpl;
} }
@@ -935,31 +918,18 @@ bool PwMDoc::copyFile(const QString &src, const QString &dst)
}
const int tmpBuf_size = 512;
char tmpBuf[tmpBuf_size];
-#ifndef PWM_EMBEDDED
Q_LONG bytesRead, bytesWritten;
-#else
- long bytesRead, bytesWritten;
-#endif
+
while (!srcFd.atEnd()) {
-#ifndef PWM_EMBEDDED
bytesRead = srcFd.readBlock(tmpBuf,
static_cast<Q_ULONG>(tmpBuf_size));
-#else
- bytesRead = srcFd.readBlock(tmpBuf,
- (unsigned long)(tmpBuf_size));
-#endif
if (bytesRead == -1) {
srcFd.close();
dstFd.close();
return false;
}
-#ifndef PWM_EMBEDDED
bytesWritten = dstFd.writeBlock(tmpBuf,
static_cast<Q_ULONG>(bytesRead));
-#else
- bytesWritten = dstFd.writeBlock(tmpBuf,
- (unsigned long)(bytesRead));
-#endif
if (bytesWritten != bytesRead) {
srcFd.close();
dstFd.close();
@@ -1300,7 +1270,6 @@ PwMerror PwMDoc::encrypt(string *d, const QString *pw, QFile *f, char algo)
bf.bf_encrypt((byte *) encrypted, (byte *) d->c_str(), encSize);
break;
}
-#ifndef PWM_EMBEDDED
case PWM_CRYPT_AES128:
/*... fall through */
case PWM_CRYPT_AES192:
@@ -1326,28 +1295,18 @@ PwMerror PwMDoc::encrypt(string *d, const QString *pw, QFile *f, char algo)
return e_cryptNotImpl;
break;
}
-#endif
default: {
delete_ifnot_null_array(encrypted);
return e_cryptNotImpl;
} }
// write encrypted data to file
-#ifndef PWM_EMBEDDED
if (f->writeBlock(reinterpret_cast<const char *>(encrypted),
static_cast<Q_ULONG>(encSize))
!= static_cast<Q_LONG>(encSize)) {
delete_ifnot_null_array(encrypted);
return e_writeFile;
}
-#else
- if (f->writeBlock((const char *)(encrypted),
- (unsigned long)(encSize))
- != (long)(encSize)) {
- delete_ifnot_null_array(encrypted);
- return e_writeFile;
- }
-#endif
delete_ifnot_null_array(encrypted);
return e_success;
}
@@ -1388,7 +1347,6 @@ PwMerror PwMDoc::decrypt(string *d, unsigned int pos, const QString *pw,
bf.bf_decrypt(decrypted, encrypted, cryptLen);
break;
}
-#ifndef PWM_EMBEDDED
case PWM_CRYPT_AES128:
/*... fall through */
case PWM_CRYPT_AES192:
@@ -1414,7 +1372,6 @@ PwMerror PwMDoc::decrypt(string *d, unsigned int pos, const QString *pw,
}
break;
}
-#endif
default: {
delete [] encrypted;
delete [] decrypted;
@@ -1452,7 +1409,6 @@ PwMerror PwMDoc::checkDataHash(char dataHashType, const string *dataHash,
return e_fileCorrupt;
break;
}
-#ifndef PWM_EMBEDDED
case PWM_HASH_SHA256:
/*... fall through */
case PWM_HASH_SHA384:
@@ -1480,7 +1436,6 @@ PwMerror PwMDoc::checkDataHash(char dataHashType, const string *dataHash,
return e_fileCorrupt;
break;
}
-#endif
default:
return e_hashNotImpl;
}