OK, it turns out that when you reset(), you have

to put the keys/certs back in. With that, it stops
asserting. Then it just fails to compare the messages.
If you encrypt the same data, with the same certs,
twice, you don't get the same result each time.

So I added the decrypt part, including re-use, and
checked that if you encrypt the same data twice, then
each decrypt produces the same result, and that result
is exactly what you started with. The test now passes.

svn path=/trunk/kdesupport/qca/; revision=529009
This commit is contained in:
Brad Hards 2006-04-12 11:48:19 +00:00
parent 76c1cff1b2
commit 51a2ef6a3e

View File

@ -82,19 +82,51 @@ void CMSut::xcrypt()
msg.waitForFinished(-1);
QByteArray result1 = msg.read();
QCOMPARE( result1.isEmpty(), false );
QByteArray encryptedResult1 = msg.read();
QCOMPARE( encryptedResult1.isEmpty(), false );
msg.reset();
msg.setRecipient(secMsgKey);
msg.startEncrypt();
msg.update( testText );
msg.end();
msg.waitForFinished(-1);
QByteArray result2 = msg.read();
QVERIFY( msg.success() );
QCOMPARE( result1, result2 );
QByteArray encryptedResult2 = msg.read();
QCOMPARE( encryptedResult2.isEmpty(), false );
QCA::ConvertResult res;
QSecureArray passPhrase = "start";
QCA::PrivateKey privKey = QCA::PrivateKey::fromPEMFile( "Userkey.pem", passPhrase, &res );
QCOMPARE( res, QCA::ConvertGood );
secMsgKey.setX509PrivateKey( privKey );
QCA::SecureMessageKeyList privKeyList;
privKeyList += secMsgKey;
QCA::CMS cms2;
cms2.setPrivateKeys( privKeyList );
QCA::SecureMessage msg2( &cms2 );
msg2.startDecrypt();
msg2.update( encryptedResult1 );
msg2.end();
msg2.waitForFinished(-1);
QVERIFY( msg2.success() );
QByteArray decryptedResult1 = msg2.read();
QCOMPARE( decryptedResult1, testText );
msg2.reset();
msg2.startDecrypt();
msg2.update( encryptedResult1 );
msg2.end();
msg2.waitForFinished(-1);
QVERIFY( msg2.success() );
QByteArray decryptedResult2 = msg2.read();
QCOMPARE( decryptedResult1, decryptedResult2 );
}
}
};