本文整理汇总了C++中CompositeKey类的典型用法代码示例。如果您正苦于以下问题:C++ CompositeKey类的具体用法?C++ CompositeKey怎么用?C++ CompositeKey使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CompositeKey类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QString
void TestKeePass2Reader::testFormat200()
{
QString filename = QString(KEEPASSX_TEST_DATA_DIR).append("/Format200.kdbx");
CompositeKey key;
key.addKey(PasswordKey("a"));
KeePass2Reader reader;
Database* db = reader.readDatabase(filename, key);
QVERIFY(db);
QVERIFY(!reader.hasError());
QCOMPARE(db->rootGroup()->name(), QString("Format200"));
QVERIFY(!db->metadata()->protectTitle());
QVERIFY(db->metadata()->protectUsername());
QVERIFY(!db->metadata()->protectPassword());
QVERIFY(db->metadata()->protectUrl());
QVERIFY(!db->metadata()->protectNotes());
QCOMPARE(db->rootGroup()->entries().size(), 1);
Entry* entry = db->rootGroup()->entries().at(0);
QCOMPARE(entry->title(), QString("Sample Entry"));
QCOMPARE(entry->username(), QString("User Name"));
QCOMPARE(entry->attachments()->keys().size(), 2);
QCOMPARE(entry->attachments()->value("myattach.txt"), QByteArray("abcdefghijk"));
QCOMPARE(entry->attachments()->value("test.txt"), QByteArray("this is a test"));
QCOMPARE(entry->historyItems().size(), 2);
QCOMPARE(entry->historyItems().at(0)->attachments()->keys().size(), 0);
QCOMPARE(entry->historyItems().at(1)->attachments()->keys().size(), 1);
QCOMPARE(entry->historyItems().at(1)->attachments()->value("myattach.txt"), QByteArray("abcdefghijk"));
delete db;
}
示例2: dbName
void TestKeys::testCreateFileKey()
{
const QString dbName("testCreateFileKey database");
QBuffer keyBuffer;
keyBuffer.open(QBuffer::ReadWrite);
FileKey::create(&keyBuffer);
keyBuffer.reset();
FileKey fileKey;
QVERIFY(fileKey.load(&keyBuffer));
CompositeKey compositeKey;
compositeKey.addKey(fileKey);
Database* dbOrg = new Database();
dbOrg->setKey(compositeKey);
dbOrg->metadata()->setName(dbName);
QBuffer dbBuffer;
dbBuffer.open(QBuffer::ReadWrite);
KeePass2Writer writer;
writer.writeDatabase(&dbBuffer, dbOrg);
dbBuffer.reset();
delete dbOrg;
KeePass2Reader reader;
Database* dbRead = reader.readDatabase(&dbBuffer, compositeKey);
QVERIFY(dbRead);
QVERIFY(!reader.hasError());
QCOMPARE(dbRead->metadata()->name(), dbName);
delete dbRead;
}
示例3: config
CompositeKey DatabaseOpenWidget::databaseKey()
{
CompositeKey masterKey;
if (m_ui->checkPassword->isChecked()) {
masterKey.addKey(PasswordKey(m_ui->editPassword->text()));
}
QHash<QString, QVariant> lastKeyFiles = config()->get("LastKeyFiles").toHash();
if (m_ui->checkKeyFile->isChecked()) {
FileKey key;
QString keyFilename = m_ui->comboKeyFile->currentText();
QString errorMsg;
if (!key.load(keyFilename, &errorMsg)) {
MessageBox::warning(this, tr("Error"), tr("Can't open key file").append(":\n").append(errorMsg));
return CompositeKey();
}
masterKey.addKey(key);
lastKeyFiles[m_filename] = keyFilename;
}
else {
lastKeyFiles.remove(m_filename);
}
if (config()->get("RememberLastKeyFiles").toBool()) {
config()->set("LastKeyFiles", lastKeyFiles);
}
return masterKey;
}
示例4: databaseKey
void DatabaseOpenWidget::openDatabase()
{
KeePass2Reader reader;
CompositeKey masterKey = databaseKey();
if (masterKey.isEmpty()) {
return;
}
QFile file(m_filename);
if (!file.open(QIODevice::ReadOnly)) {
// TODO: error message
return;
}
if (m_db) {
delete m_db;
}
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
m_db = reader.readDatabase(&file, masterKey);
QApplication::restoreOverrideCursor();
if (m_db) {
Q_EMIT editFinished(true);
}
else {
MessageBox::warning(this, tr("Error"), tr("Unable to open the database.").append("\n")
.append(reader.errorString()));
m_ui->editPassword->clear();
}
}
示例5: QVERIFY
void TestKeePass1Reader::reopenDatabase(Database* db, const QString& password, const QString& keyfileName)
{
QBuffer buffer;
buffer.open(QIODevice::ReadWrite);
KeePass2Writer writer;
writer.writeDatabase(&buffer, db);
QVERIFY(!writer.hasError());
QVERIFY(buffer.seek(0));
CompositeKey key;
if (!password.isNull()) {
key.addKey(PasswordKey(password));
}
if (!keyfileName.isEmpty()) {
FileKey fileKey;
QVERIFY(fileKey.load(keyfileName));
key.addKey(fileKey);
}
KeePass2Reader reader;
Database* newDb = reader.readDatabase(&buffer, key);
QVERIFY(newDb);
QVERIFY(!reader.hasError());
delete newDb;
}
示例6: databaseKey
void DatabaseOpenWidget::openDatabase()
{
KeePass2Reader reader;
CompositeKey masterKey = databaseKey();
if (masterKey.isEmpty()) {
return;
}
QFile file(m_filename);
if (!file.open(QIODevice::ReadOnly)) {
// TODO: error message
return;
}
if (m_db) {
delete m_db;
}
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
m_db = reader.readDatabase(&file, masterKey);
QApplication::restoreOverrideCursor();
if (m_db) {
Q_EMIT editFinished(true);
// this is a c++11 equivalent foreach construct
// if c++11 is not available another iteration loop style is needed!
for (auto widget : qApp->topLevelWidgets()) {
if(widget->inherits("QMainWindow"))
static_cast<MainWindow*>(widget)->configuredMinimizeWindow();
}
}
else {
MessageBox::warning(this, tr("Error"), tr("Unable to open the database.").append("\n")
.append(reader.errorString()));
m_ui->editPassword->clear();
}
}
示例7: databaseKey
void DatabaseOpenWidget::openDatabase()
{
CompositeKey masterKey = databaseKey();
if (masterKey.isEmpty()) {
return;
}
openDatabase(masterKey);
}
示例8: checkDatabase
void TestGui::checkDatabase()
{
CompositeKey key;
key.addKey(PasswordKey("a"));
KeePass2Reader reader;
QScopedPointer<Database> dbSaved(reader.readDatabase(m_tmpFileName, key));
QVERIFY(dbSaved);
QVERIFY(!reader.hasError());
QCOMPARE(dbSaved->metadata()->name(), m_db->metadata()->name());
}
示例9: openDatabase
void DatabaseRepairWidget::openDatabase()
{
CompositeKey masterKey;
if (m_ui->checkPassword->isChecked()) {
masterKey.addKey(PasswordKey(m_ui->editPassword->text()));
}
if (m_ui->checkKeyFile->isChecked()) {
FileKey key;
QString keyFilename = m_ui->comboKeyFile->currentText();
QString errorMsg;
if (!key.load(keyFilename, &errorMsg)) {
MessageBox::warning(this, tr("Error"), tr("Can't open key file").append(":\n").append(errorMsg));
Q_EMIT editFinished(false);
}
masterKey.addKey(key);
}
KeePass2Repair repair;
QFile file(m_filename);
if (!file.open(QIODevice::ReadOnly)) {
// TODO: error message
Q_EMIT editFinished(false);
return;
}
if (m_db) {
delete m_db;
}
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
KeePass2Repair::RepairResult repairResult = repair.repairDatabase(&file, masterKey);
QApplication::restoreOverrideCursor();
switch (repairResult) {
case KeePass2Repair::NothingTodo:
MessageBox::information(this, tr("Error"), tr("Database opened fine. Nothing to do."));
Q_EMIT editFinished(false);
return;
case KeePass2Repair::UnableToOpen:
MessageBox::warning(this, tr("Error"), tr("Unable to open the database.").append("\n")
.append(repair.errorString()));
Q_EMIT editFinished(false);
return;
case KeePass2Repair::RepairSuccess:
m_db = repair.database();
MessageBox::warning(this, tr("Success"), tr("The database has been successfully repaired\nYou can now save it."));
Q_EMIT editFinished(true);
return;
case KeePass2Repair::RepairFailed:
MessageBox::warning(this, tr("Error"), tr("Unable to repair the database."));
Q_EMIT editFinished(false);
return;
}
}
示例10: enterKey
void DatabaseOpenWidget::enterKey(const CompositeKey& masterKey)
{
if (masterKey.isEmpty()) {
return;
}
openDatabase(masterKey);
}
示例11: qgetenv
void TestKeys::benchmarkTransformKey()
{
QByteArray env = qgetenv("BENCHMARK");
if (env.isEmpty() || env == "0" || env == "no") {
QSKIP("Benchmark skipped. Set env variable BENCHMARK=1 to enable.", SkipAll);
}
PasswordKey pwKey;
pwKey.setPassword("password");
CompositeKey compositeKey;
compositeKey.addKey(pwKey);
QByteArray seed(32, '\x4B');
QBENCHMARK {
compositeKey.transform(seed, 1e6);
}
}
示例12: Database
void TestKeePass2Writer::initTestCase()
{
Crypto::init();
CompositeKey key;
key.addKey(PasswordKey("test"));
m_dbOrg = new Database();
m_dbOrg->setKey(key);
m_dbOrg->metadata()->setName("TESTDB");
Group* group = m_dbOrg->rootGroup();
group->setUuid(Uuid::random());
group->setNotes("I'm a note!");
Entry* entry = new Entry();
entry->setPassword(QString::fromUtf8("\xc3\xa4\xa3\xb6\xc3\xbc\xe9\x9b\xbb\xe7\xb4\x85"));
entry->setUuid(Uuid::random());
entry->attributes()->set("test", "protectedTest", true);
QVERIFY(entry->attributes()->isProtected("test"));
entry->attachments()->set("myattach.txt", QByteArray("this is an attachment"));
entry->attachments()->set("aaa.txt", QByteArray("also an attachment"));
entry->setGroup(group);
Group* groupNew = new Group();
groupNew->setUuid(Uuid::random());
groupNew->setName("TESTGROUP");
groupNew->setNotes("I'm a sub group note!");
groupNew->setParent(group);
QBuffer buffer;
buffer.open(QBuffer::ReadWrite);
KeePass2Writer writer;
writer.writeDatabase(&buffer, m_dbOrg);
QVERIFY(!writer.error());
buffer.seek(0);
KeePass2Reader reader;
m_dbTest = reader.readDatabase(&buffer, key);
QVERIFY(!reader.hasError());
QVERIFY(m_dbTest);
}
示例13: QFETCH
void TestKeys::testFileKey()
{
QFETCH(QString, type);
QString name = QString("FileKey").append(type);
KeePass2Reader reader;
QString dbFilename = QString("%1/%2.kdbx").arg(QString(KEEPASSX_TEST_DATA_DIR), name);
QString keyFilename = QString("%1/%2.key").arg(QString(KEEPASSX_TEST_DATA_DIR), name);
CompositeKey compositeKey;
FileKey fileKey;
QVERIFY(fileKey.load(keyFilename));
QCOMPARE(fileKey.rawKey().size(), 32);
compositeKey.addKey(fileKey);
Database* db = reader.readDatabase(dbFilename, compositeKey);
QVERIFY(db);
QVERIFY(!reader.hasError());
QCOMPARE(db->metadata()->name(), QString("%1 Database").arg(name));
delete db;
}
示例14: openDatabase
void DatabaseTabWidget::openDatabase(const QString& fileName, const QString& pw,
const QString& keyFile, const CompositeKey& key, int index)
{
QFileInfo fileInfo(fileName);
QString canonicalFilePath = fileInfo.canonicalFilePath();
if (canonicalFilePath.isEmpty()) {
QMessageBox::warning(this, tr("Warning"), tr("File not found!"));
return;
}
QHashIterator<Database*, DatabaseManagerStruct> i(m_dbList);
while (i.hasNext()) {
i.next();
if (i.value().canonicalFilePath == canonicalFilePath) {
setCurrentIndex(databaseIndex(i.key()));
return;
}
}
DatabaseManagerStruct dbStruct;
// test if we can read/write or read the file
QFile file(fileName);
// TODO: error handling
if (!file.open(QIODevice::ReadWrite)) {
if (!file.open(QIODevice::ReadOnly)) {
// can't open
// TODO: error message
return;
}
else {
// can only open read-only
dbStruct.readOnly = true;
}
}
file.close();
Database* db = new Database();
dbStruct.dbWidget = new DatabaseWidget(db, this);
dbStruct.saveToFilename = !dbStruct.readOnly;
dbStruct.filePath = fileInfo.absoluteFilePath();
dbStruct.canonicalFilePath = canonicalFilePath;
dbStruct.fileName = fileInfo.fileName();
dbStruct.lastModified = fileInfo.lastModified();
insertDatabase(db, dbStruct, index);
m_fileWatcher->addPath(dbStruct.filePath);
updateRecentDatabases(dbStruct.filePath);
if (!key.isEmpty()) {
dbStruct.dbWidget->switchToOpenDatabase(dbStruct.filePath, key);
}
else if (!pw.isNull() || !keyFile.isEmpty()) {
dbStruct.dbWidget->switchToOpenDatabase(dbStruct.filePath, pw, keyFile);
}
else {
dbStruct.dbWidget->switchToOpenDatabase(dbStruct.filePath);
}
}