summaryrefslogtreecommitdiffstats
path: root/libkpgp/kpgp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libkpgp/kpgp.cpp')
-rw-r--r--libkpgp/kpgp.cpp64
1 files changed, 22 insertions, 42 deletions
diff --git a/libkpgp/kpgp.cpp b/libkpgp/kpgp.cpp
index 07edfa3a..e535abe3 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(TQString::null), havePassPhrase(false)
{
if (!kpgpObject) {
kdDebug(5100) << "creating new pgp object" << endl;
@@ -73,7 +73,7 @@ Module::~Module()
writeAddressData();
if (kpgpObject == this) kpgpObject = kpgpod.setObject( Module::kpgpObject, 0, false );
- clear(TRUE);
+ clear(true);
delete config;
delete pgp;
}
@@ -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.truncate(0);
}
havePassPhrase = false;
}
@@ -275,7 +268,7 @@ Module::decrypt( Block& block )
// loop as long as the user enters a wrong passphrase and doesn't abort
// everything ready
if( prepare( true, &block ) != 1 )
- return FALSE;
+ return false;
// ok now try to decrypt the message.
retval = pgp->decrypt( block, passphrase );
// loop on bad passphrase
@@ -685,7 +678,7 @@ Module::signKey(const KeyID& keyId)
if (0 == pgp) assignPGPBase();
if( prepare( true ) != 1 )
- return FALSE;
+ return false;
if(pgp->signKey(keyId, passphrase) & ERROR)
{
errMsg = pgp->lastErrorMessage();
@@ -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.isEmpty())
{
- 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;
@@ -875,7 +855,7 @@ Module::changePassPhrase()
{
//FIXME...
KMessageBox::information(0,i18n("This feature is\nstill missing"));
- return FALSE;
+ return false;
}
void
@@ -1330,7 +1310,7 @@ Module::checkForPGP(void)
int index = 0;
int lastindex = -1;
- havePgp=FALSE;
+ havePgp=false;
path = getenv("PATH");
while((index = path.find(":",lastindex+1)) != -1)
@@ -1343,7 +1323,7 @@ Module::checkForPGP(void)
TQStrListIterator it(pSearchPaths);
- haveGpg=FALSE;
+ haveGpg=false;
// lets try gpg
for ( it.toFirst() ; it.current() ; ++it )
@@ -1353,14 +1333,14 @@ Module::checkForPGP(void)
if ( !access( path, X_OK ) )
{
kdDebug(5100) << "Kpgp: gpg found" << endl;
- havePgp=TRUE;
- haveGpg=TRUE;
+ havePgp=true;
+ haveGpg=true;
break;
}
}
// search for pgp5.0
- havePGP5=FALSE;
+ havePGP5=false;
for ( it.toFirst() ; it.current() ; ++it )
{
path = (*it);
@@ -1368,8 +1348,8 @@ Module::checkForPGP(void)
if ( !access( path, X_OK ) )
{
kdDebug(5100) << "Kpgp: pgp 5 found" << endl;
- havePgp=TRUE;
- havePGP5=TRUE;
+ havePgp=true;
+ havePGP5=true;
break;
}
}
@@ -1383,7 +1363,7 @@ Module::checkForPGP(void)
if ( !access( path, X_OK ) )
{
kdDebug(5100) << "Kpgp: pgp 2 or 6 found" << endl;
- havePgp=TRUE;
+ havePgp=true;
break;
}
}