void TcpConnection::start()
{
	auto command = std::make_shared<Commands>();
	auto self = shared_from_this();
	socket().async_read_some(asio::buffer(reinterpret_cast<uint8_t*>(command.get()), sizeof(Commands)), [self, command](const asio::error_code& error, std::size_t size) {
		if (error)
		{
			std::cerr << error.value() << " " << error.message() << "\n";
			return;
		}

		switch (*command)
		{
		case Commands::GET_PUBLIC_KEY:
			std::cout << "Command GET_PUBLIC_KEY\n";
			self->sendPublicKey();
			break;
		case Commands::GET_PRIVATE_KEY:
			std::cout << "Command GET_PRIVATE_KEY\n";
			self->sendPrivateKey();
			break;
		default:
			std::cerr << "Unknown Command " << command << "\n";
			break;
		}
	});
}
Exemple #2
0
void GnuPG::actionActivated()
{
    if (_menu) {
        delete _menu;
    }

    _menu = new QMenu();

    Model *model = new Model(_menu);
    model->listKeys();

    for (int i = 0; i < model->rowCount(); i++) {
        if (model->item(i, Model::Type)->text() != "sec") {
            continue;
        }

        QString str;
        // User name
        if (!model->item(i, Model::Name)->text().isEmpty()) {
            str += model->item(i, Model::Name)->text();
        }

        // Comment
        if (!model->item(i, Model::Comment)->text().isEmpty()) {
            if (!str.isEmpty()) {
                str += " ";
            }
            str += QString("(%1)").arg(model->item(i, Model::Comment)->text());
        }

        // Email
        if (!model->item(i, Model::Email)->text().isEmpty()) {
            if (!str.isEmpty()) {
                str += " ";
            }
            str += QString("<%1>").arg(model->item(i, Model::Email)->text());
        }

        // Short ID
        if (!str.isEmpty()) {
            str += " ";
        }
        str += model->item(i, Model::ShortId)->text();

        QAction *action = _menu->addAction(str);
        action->setData(model->item(i, Model::Fingerprint)->text());
        connect(action, SIGNAL(triggered()), SLOT(sendPublicKey()));
    }

    _menu->popup(QCursor::pos());
}