summaryrefslogtreecommitdiffstats
path: root/libkpgp/kpgp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libkpgp/kpgp.cpp')
-rw-r--r--libkpgp/kpgp.cpp40
1 files changed, 10 insertions, 30 deletions
diff --git a/libkpgp/kpgp.cpp b/libkpgp/kpgp.cpp
index 293b36811..a42429573 100644
--- a/libkpgp/kpgp.cpp
+++ b/libkpgp/kpgp.cpp
@@ -55,7 +55,7 @@ Module::Module()
mPublicKeysCached(false),
mSecretKeys(),
mSecretKeysCached(false),
- passphrase(0), passphrase_buffer_len(0), havePassPhrase(false)
+ passphrase(0), havePassPhrase(false)
{
if (!kpgpObject) {
kdDebug(5100) << "creating new pgp object" << endl;
@@ -209,7 +209,7 @@ Module::prepare( bool needPassPhrase, Block* block )
TQApplication::restoreOverrideCursor();
if (passdlgResult == TQDialog::Accepted) {
if (!setPassPhrase(passdlg.passphrase())) {
- if (strlen(passdlg.passphrase()) >= 1024)
+ if (passdlg.passphrase().length() >= 1024)
errMsg = i18n("Passphrase is too long, it must contain fewer than 1024 characters.");
else
errMsg = i18n("Out of memory.");
@@ -227,18 +227,11 @@ Module::prepare( bool needPassPhrase, Block* block )
void
Module::wipePassPhrase(bool freeMem)
{
- if ( passphrase ) {
- if ( passphrase_buffer_len )
- memset( passphrase, 0x00, passphrase_buffer_len );
- else {
- kdDebug(5100) << "wipePassPhrase: passphrase && !passphrase_buffer_len ???" << endl;
- passphrase = 0;
- }
+ if (!passphrase.isEmpty()) {
+ passphrase.fill(' ');
}
- if ( freeMem && passphrase ) {
- free( passphrase );
- passphrase = 0;
- passphrase_buffer_len = 0;
+ if (freeMem && !passphrase.isNull()) {
+ passphrase = TQString();
}
havePassPhrase = false;
}
@@ -837,34 +830,21 @@ Module::getAsciiPublicKey(const KeyID& keyID)
}
-bool Module::setPassPhrase(const char * aPass)
+bool Module::setPassPhrase(const TQString& aPass)
{
// null out old buffer before we touch the new string. So in case
// aPass isn't properly null-terminated, we don't leak secret data.
wipePassPhrase();
- if (aPass)
+ if (!aPass.isNull())
{
- size_t newlen = strlen( aPass );
- if ( newlen >= 1024 ) {
+ if (aPass.length() >= 1024) {
// rediculously long passphrase.
// Maybe someone wants to trick us in malloc()'ing
// huge buffers...
return false;
}
- if ( passphrase_buffer_len < newlen + 1 ) {
- // too little space in current buffer:
- // allocate a larger one.
- if ( passphrase )
- free( passphrase );
- passphrase_buffer_len = (newlen + 1 + 15) & ~0xF; // make it a multiple of 16.
- passphrase = (char*)malloc( passphrase_buffer_len );
- if (!passphrase) {
- passphrase_buffer_len = 0;
- return false;
- }
- }
- memcpy( passphrase, aPass, newlen + 1 );
+ passphrase = aPass;
havePassPhrase = true;
}
return true;