Get rid of cryptopp dependency
Plus various code cleanups:
* More 'auto' usage
* Use 'nullptr' instead of 0
* Rename NewApp class to ChronoChatApp
* Print exception info with boost::diagnostic_information()
* Disable -Wdeprecated-copy and -Wredundant-tags, they trigger
too many warnings in Qt headers with gcc 9 and later
Change-Id: I2ea16c19be634f957b59280c704a956f083891f0
diff --git a/src/chat-dialog-backend.cpp b/src/chat-dialog-backend.cpp
index 53bfdb3..ff0a600 100644
--- a/src/chat-dialog-backend.cpp
+++ b/src/chat-dialog-backend.cpp
@@ -15,18 +15,16 @@
#ifndef Q_MOC_RUN
#include <boost/iostreams/stream.hpp>
-#include <ndn-cxx/util/io.hpp>
-#include "cryptopp.hpp"
-#endif
-using namespace CryptoPP;
+#include <ndn-cxx/util/io.hpp>
+#include <ndn-cxx/util/string-helper.hpp>
+#endif
namespace chronochat {
static const time::milliseconds FRESHNESS_PERIOD(60000);
static const time::seconds HELLO_INTERVAL(60);
-static const ndn::Name::Component ROUTING_HINT_SEPARATOR =
- ndn::name::Component::fromEscapedString("%F0%2E");
+static const Name::Component ROUTING_HINT_SEPARATOR = Name::Component::fromEscapedString("%F0%2E");
static const int IDENTITY_OFFSET = -3;
static const int CONNECTION_RETRY_TIMER = 3;
@@ -49,10 +47,7 @@
updatePrefixes();
}
-
-ChatDialogBackend::~ChatDialogBackend()
-{
-}
+ChatDialogBackend::~ChatDialogBackend() = default;
// protected methods:
void
@@ -101,8 +96,6 @@
close();
} while (shouldResume);
-
- std::cerr << "Bye!" << std::endl;
}
// private methods:
@@ -183,7 +176,6 @@
std::vector<NodeInfo> nodeInfos;
-
for (size_t i = 0; i < updates.size(); i++) {
// update roster
if (m_roster.find(updates[i].session) == m_roster.end()) {
@@ -214,13 +206,11 @@
// reflect the changes on GUI
emit syncTreeUpdated(nodeInfos,
- QString::fromStdString(getHexEncodedDigest(m_sock->getRootDigest())));
+ QString::fromStdString(ndn::toHex(*m_sock->getRootDigest(), false)));
}
void
-ChatDialogBackend::processChatData(const ndn::Data& data,
- bool needDisplay,
- bool isValidated)
+ChatDialogBackend::processChatData(const ndn::Data& data, bool needDisplay, bool isValidated)
{
ChatMessage msg;
@@ -344,7 +334,7 @@
nodeInfos.push_back(nodeInfo);
emit syncTreeUpdated(nodeInfos,
- QString::fromStdString(getHexEncodedDigest(m_sock->getRootDigest())));
+ QString::fromStdString(ndn::toHex(*m_sock->getRootDigest(), false)));
emit messageReceived(QString::fromStdString(sessionName.toUri()),
QString::fromStdString(msg.getNick()),
@@ -432,16 +422,6 @@
emit chatPrefixChanged(m_routableUserChatPrefix);
}
-std::string
-ChatDialogBackend::getHexEncodedDigest(ndn::ConstBufferPtr digest)
-{
- std::stringstream os;
-
- CryptoPP::StringSource(digest->data(), digest->size(), true,
- new CryptoPP::HexEncoder(new CryptoPP::FileSink(os), false));
- return os.str();
-}
-
// public slots:
void
diff --git a/src/chat-dialog-backend.hpp b/src/chat-dialog-backend.hpp
index 0c417c3..e0c8b0c 100644
--- a/src/chat-dialog-backend.hpp
+++ b/src/chat-dialog-backend.hpp
@@ -105,9 +105,6 @@
void
updatePrefixes();
- std::string
- getHexEncodedDigest(ndn::ConstBufferPtr digest);
-
signals:
void
syncTreeUpdated(std::vector<chronochat::NodeInfo> updates, QString digest);
diff --git a/src/chatroom-discovery-backend.cpp b/src/chatroom-discovery-backend.cpp
index 3f92e01..8e2ad21 100644
--- a/src/chatroom-discovery-backend.cpp
+++ b/src/chatroom-discovery-backend.cpp
@@ -9,19 +9,15 @@
*/
#include "chatroom-discovery-backend.hpp"
+
#include <QStringList>
-#ifndef Q_MOC_RUN
-
-#endif
-
namespace chronochat {
static const time::milliseconds FRESHNESS_PERIOD(60000);
static const time::seconds REFRESH_INTERVAL(60);
static const time::seconds HELLO_INTERVAL(60);
-static const ndn::Name::Component ROUTING_HINT_SEPARATOR =
- ndn::name::Component::fromEscapedString("%F0%2E");
+static const Name::Component ROUTING_HINT_SEPARATOR = Name::Component::fromEscapedString("%F0%2E");
// a count enforced when a manager himself find another one publish chatroom data
static const int MAXIMUM_COUNT = 3;
static const int IDENTITY_OFFSET = -1;
@@ -93,8 +89,6 @@
close();
} while (shouldResume);
-
- std::cerr << "DiscoveryBackend: Bye!" << std::endl;
}
void
diff --git a/src/contact-manager.cpp b/src/contact-manager.cpp
index 5a5f5bb..5a6b4b9 100644
--- a/src/contact-manager.cpp
+++ b/src/contact-manager.cpp
@@ -10,20 +10,24 @@
*/
#include "contact-manager.hpp"
+
#include <QStringList>
#include <QFile>
#ifndef Q_MOC_RUN
#include <ndn-cxx/encoding/buffer-stream.hpp>
#include <ndn-cxx/face.hpp>
+#include <ndn-cxx/security/signing-helpers.hpp>
+#include <ndn-cxx/security/transform/buffer-source.hpp>
+#include <ndn-cxx/security/transform/digest-filter.hpp>
+#include <ndn-cxx/security/transform/stream-sink.hpp>
#include <ndn-cxx/security/validator.hpp>
#include <ndn-cxx/security/validator-null.hpp>
-#include <ndn-cxx/security/signing-helpers.hpp>
#include <ndn-cxx/security/verification-helpers.hpp>
-#include "cryptopp.hpp"
+
#include <boost/asio.hpp>
-#include <boost/tokenizer.hpp>
#include <boost/filesystem.hpp>
+#include <boost/tokenizer.hpp>
#endif
namespace fs = boost::filesystem;
@@ -82,10 +86,9 @@
void
ContactManager::fetchEndorseCertificateInternal(const Name& identity, size_t certIndex)
{
- shared_ptr<EndorseCollection> endorseCollection =
- m_bufferedContacts[identity].m_endorseCollection;
+ auto endorseCollection = m_bufferedContacts[identity].m_endorseCollection;
- if(certIndex >= endorseCollection->getCollectionEntries().size())
+ if (certIndex >= endorseCollection->getCollectionEntries().size())
return prepareEndorseInfo(identity);
Name interestName(endorseCollection->getCollectionEntries()[certIndex].certName);
@@ -114,15 +117,13 @@
m_bufferedContacts[identity].m_endorseInfo = endorseInfo;
map<string, size_t> endorseCount;
- for (Profile::const_iterator pIt = profile.begin(); pIt != profile.end(); pIt++)
+ for (auto pIt = profile.begin(); pIt != profile.end(); pIt++)
endorseCount[pIt->first] = 0;
size_t endorseCertCount = 0;
- vector<shared_ptr<EndorseCertificate> >::const_iterator cIt =
- m_bufferedContacts[identity].m_endorseCertList.begin();
- vector<shared_ptr<EndorseCertificate> >::const_iterator cEnd =
- m_bufferedContacts[identity].m_endorseCertList.end();
+ auto cIt = m_bufferedContacts[identity].m_endorseCertList.cbegin();
+ auto cEnd = m_bufferedContacts[identity].m_endorseCertList.cend();
for (; cIt != cEnd; cIt++, endorseCertCount++) {
shared_ptr<Contact> contact = getContact((*cIt)->getSigner());
@@ -140,13 +141,13 @@
continue;
const Profile& tmpProfile = (*cIt)->getProfile();
- const vector<string>& endorseList = (*cIt)->getEndorseList();
- for (vector<string>::const_iterator eIt = endorseList.begin(); eIt != endorseList.end(); eIt++)
+ const auto& endorseList = (*cIt)->getEndorseList();
+ for (auto eIt = endorseList.begin(); eIt != endorseList.end(); eIt++)
if (tmpProfile.get(*eIt) == profile.get(*eIt))
endorseCount[*eIt] += 1;
}
- for (Profile::const_iterator pIt = profile.begin(); pIt != profile.end(); pIt++) {
+ for (auto pIt = profile.begin(); pIt != profile.end(); pIt++) {
std::stringstream ss;
ss << endorseCount[pIt->first] << "/" << endorseCertCount;
endorseInfo->addEndorsement(pIt->first, pIt->second, ss.str());
@@ -232,23 +233,20 @@
}
void
-ContactManager::onEndorseCertificateInternal(const Interest& interest, const Data& data,
- const Name& identity, size_t certIndex,
- string hash)
+ContactManager::onEndorseCertificateInternal(const Interest&, const Data& data,
+ const Name& identity, size_t certIndex, string hash)
{
- std::stringstream ss;
+ std::ostringstream ss;
{
- using namespace CryptoPP;
-
- SHA256 hash;
- StringSource(data.wireEncode().wire(), data.wireEncode().size(), true,
- new HashFilter(hash, new FileSink(ss)));
+ using namespace ndn::security::transform;
+ bufferSource(data.wireEncode().wire(), data.wireEncode().size())
+ >> digestFilter(ndn::DigestAlgorithm::SHA256)
+ >> streamSink(ss);
}
if (ss.str() == hash) {
- shared_ptr<EndorseCertificate> endorseCertificate =
- make_shared<EndorseCertificate>(boost::cref(data));
- m_bufferedContacts[identity].m_endorseCertList.push_back(endorseCertificate);
+ auto endorseCertificate = make_shared<EndorseCertificate>(data);
+ m_bufferedContacts[identity].m_endorseCertList.push_back(std::move(endorseCertificate));
}
fetchEndorseCertificateInternal(identity, certIndex+1);
@@ -269,7 +267,7 @@
boost::recursive_mutex::scoped_lock lock(m_collectCountMutex);
m_collectCount = m_contactList.size();
- for (ContactList::iterator it = m_contactList.begin(); it != m_contactList.end(); it++) {
+ for (auto it = m_contactList.begin(); it != m_contactList.end(); it++) {
Name interestName = (*it)->getNameSpace();
interestName.append("DNS").append(m_identity.wireEncode()).append("ENDORSEE");
@@ -384,8 +382,7 @@
QStringList certNameList;
QStringList nameList;
- for(BufferedIdCerts::const_iterator it = m_bufferedIdCerts.begin();
- it != m_bufferedIdCerts.end(); it++) {
+ for (auto it = m_bufferedIdCerts.begin(); it != m_bufferedIdCerts.end(); it++) {
certNameList << QString::fromStdString(it->second->getName().toUri());
Profile profile(*(it->second));
nameList << QString::fromStdString(profile.get("name"));
@@ -402,7 +399,7 @@
auto signCert = m_keyChain.getPib().getIdentity(m_identity)
.getDefaultKey().getDefaultCertificate();
vector<string> endorseList;
- for (Profile::const_iterator it = profile.begin(); it != profile.end(); it++)
+ for (auto it = profile.begin(); it != profile.end(); it++)
endorseList.push_back(it->first);
shared_ptr<EndorseCertificate> selfEndorseCertificate =
@@ -639,7 +636,7 @@
{
Name identityName(identity.toStdString());
- BufferedContacts::const_iterator it = m_bufferedContacts.find(identityName);
+ auto it = m_bufferedContacts.find(identityName);
if (it != m_bufferedContacts.end()) {
Contact contact(*(it->second.m_selfEndorseCert));
@@ -750,8 +747,7 @@
}
m_bufferedIdCerts.clear();
- for (vector<string>::const_iterator it = bufferedIdCertNames.begin();
- it != bufferedIdCertNames.end(); it++) {
+ for (auto it = bufferedIdCertNames.begin(); it != bufferedIdCertNames.end(); it++) {
Name certName(*it);
Interest interest(certName);
@@ -785,7 +781,7 @@
Name certName(qCertName.toStdString());
Name identity = certName.getPrefix(-1);
- BufferedIdCerts::const_iterator it = m_bufferedIdCerts.find(certName);
+ auto it = m_bufferedIdCerts.find(certName);
if (it != m_bufferedIdCerts.end()) {
Contact contact(*it->second);
try {
@@ -811,7 +807,7 @@
{
QStringList aliasList;
QStringList idList;
- for (ContactList::const_iterator it = m_contactList.begin(); it != m_contactList.end(); it++) {
+ for (auto it = m_contactList.begin(); it != m_contactList.end(); it++) {
aliasList << QString((*it)->getAlias().c_str());
idList << QString((*it)->getNameSpace().toUri().c_str());
}
@@ -823,7 +819,7 @@
void
ContactManager::onWaitForContactInfo(const QString& identity)
{
- for (ContactList::const_iterator it = m_contactList.begin(); it != m_contactList.end(); it++)
+ for (auto it = m_contactList.begin(); it != m_contactList.end(); it++)
if ((*it)->getNameSpace().toUri() == identity.toStdString())
emit contactInfoReady(QString((*it)->getNameSpace().toUri().c_str()),
QString((*it)->getName().c_str()),
diff --git a/src/contact-storage.cpp b/src/contact-storage.cpp
index 76ae31d..6703f41 100644
--- a/src/contact-storage.cpp
+++ b/src/contact-storage.cpp
@@ -10,7 +10,11 @@
*/
#include "contact-storage.hpp"
-#include "cryptopp.hpp"
+
+#include <ndn-cxx/security/transform/buffer-source.hpp>
+#include <ndn-cxx/security/transform/digest-filter.hpp>
+#include <ndn-cxx/security/transform/hex-encode.hpp>
+#include <ndn-cxx/security/transform/stream-sink.hpp>
#include <boost/filesystem.hpp>
@@ -184,13 +188,13 @@
{
string dbName("chronos-");
- std::stringstream ss;
+ std::ostringstream ss;
{
- using namespace CryptoPP;
-
- SHA256 hash;
- StringSource(m_identity.wireEncode().wire(), m_identity.wireEncode().size(), true,
- new HashFilter(hash, new HexEncoder(new FileSink(ss), false)));
+ using namespace ndn::security::transform;
+ bufferSource(m_identity.wireEncode().wire(), m_identity.wireEncode().size())
+ >> digestFilter(ndn::DigestAlgorithm::SHA256)
+ >> hexEncode(false)
+ >> streamSink(ss);
}
dbName.append(ss.str()).append(".db");
@@ -203,7 +207,7 @@
sqlite3_stmt *stmt;
sqlite3_prepare_v2(m_db,
"SELECT name FROM sqlite_master WHERE type='table' And name=?",
- -1, &stmt, 0);
+ -1, &stmt, nullptr);
sqlite3_bind_string(stmt, 1, tableName, SQLITE_TRANSIENT);
int res = sqlite3_step(stmt);
@@ -213,9 +217,9 @@
sqlite3_finalize(stmt);
if (!tableExist) {
- char *errmsg = 0;
+ char *errmsg = nullptr;
res = sqlite3_exec(m_db, sqlCreateStmt.c_str (), nullptr, nullptr, &errmsg);
- if (res != SQLITE_OK && errmsg != 0)
+ if (res != SQLITE_OK && errmsg != nullptr)
NDN_THROW(Error("Init \"error\" in " + tableName));
}
}
@@ -225,7 +229,8 @@
{
shared_ptr<Profile> profile = make_shared<Profile>(m_identity);
sqlite3_stmt *stmt;
- sqlite3_prepare_v2(m_db, "SELECT profile_type, profile_value FROM SelfProfile", -1, &stmt, 0);
+ sqlite3_prepare_v2(m_db, "SELECT profile_type, profile_value FROM SelfProfile",
+ -1, &stmt, nullptr);
while (sqlite3_step(stmt) == SQLITE_ROW) {
string profileType = sqlite3_column_string(stmt, 0);
@@ -243,7 +248,7 @@
sqlite3_stmt *stmt;
sqlite3_prepare_v2(m_db,
"INSERT OR REPLACE INTO SelfEndorse (identity, endorse_data) values (?, ?)",
- -1, &stmt, 0);
+ -1, &stmt, nullptr);
sqlite3_bind_string(stmt, 1, m_identity.toUri(), SQLITE_TRANSIENT);
sqlite3_bind_block(stmt, 2, newEndorseCertificate.wireEncode(), SQLITE_TRANSIENT);
sqlite3_step(stmt);
@@ -259,7 +264,7 @@
sqlite3_stmt *stmt;
sqlite3_prepare_v2(m_db,
"SELECT endorse_data FROM SelfEndorse where identity=?",
- -1, &stmt, 0);
+ -1, &stmt, nullptr);
sqlite3_bind_string(stmt, 1, m_identity.toUri(), SQLITE_TRANSIENT);
if (sqlite3_step(stmt) == SQLITE_ROW) {
@@ -280,7 +285,7 @@
sqlite3_prepare_v2(m_db,
"INSERT OR REPLACE INTO ProfileEndorse \
(identity, endorse_data) values (?, ?)",
- -1, &stmt, 0);
+ -1, &stmt, nullptr);
sqlite3_bind_string(stmt, 1, identity.toUri(), SQLITE_TRANSIENT);
sqlite3_bind_block(stmt, 2, endorseCertificate.wireEncode(), SQLITE_TRANSIENT);
sqlite3_step(stmt);
@@ -299,7 +304,7 @@
"INSERT OR REPLACE INTO CollectEndorse \
(endorser, endorse_name, endorse_data) \
VALUES (?, ?, ?)",
- -1, &stmt, 0);
+ -1, &stmt, nullptr);
sqlite3_bind_string(stmt, 1, endorserName.toUri(), SQLITE_TRANSIENT);
sqlite3_bind_string(stmt, 2, certName.toUri(), SQLITE_TRANSIENT);
sqlite3_bind_block(stmt, 3, endorseCertificate.wireEncode(), SQLITE_TRANSIENT);
@@ -312,17 +317,17 @@
ContactStorage::getCollectEndorse(EndorseCollection& endorseCollection)
{
sqlite3_stmt *stmt;
- sqlite3_prepare_v2(m_db, "SELECT endorse_name, endorse_data FROM CollectEndorse", -1, &stmt, 0);
+ sqlite3_prepare_v2(m_db, "SELECT endorse_name, endorse_data FROM CollectEndorse",
+ -1, &stmt, nullptr);
while (sqlite3_step(stmt) == SQLITE_ROW) {
string certName = sqlite3_column_string(stmt, 0);
- std::stringstream ss;
+ std::ostringstream ss;
{
- using namespace CryptoPP;
- SHA256 hash;
-
- StringSource(sqlite3_column_text(stmt, 1), sqlite3_column_bytes (stmt, 1), true,
- new HashFilter(hash, new FileSink(ss)));
+ using namespace ndn::security::transform;
+ bufferSource(sqlite3_column_text(stmt, 1), sqlite3_column_bytes(stmt, 1))
+ >> digestFilter(ndn::DigestAlgorithm::SHA256)
+ >> streamSink(ss);
}
endorseCollection.addCollectionEntry(Name(certName), ss.str());
}
@@ -338,7 +343,7 @@
sqlite3_stmt *stmt;
sqlite3_prepare_v2(m_db,
"SELECT endorse_name, endorse_data FROM CollectEndorse where endorse_name=?",
- -1, &stmt, 0);
+ -1, &stmt, nullptr);
sqlite3_bind_string(stmt, 1, name.toUri(), SQLITE_TRANSIENT);
if (sqlite3_step(stmt) == SQLITE_ROW) {
@@ -358,7 +363,7 @@
sqlite3_prepare_v2(m_db,
"SELECT profile_type FROM ContactProfile \
WHERE profile_identity=? AND endorse=1 ORDER BY profile_type",
- -1, &stmt, 0);
+ -1, &stmt, nullptr);
sqlite3_bind_string(stmt, 1, identity.toUri(), SQLITE_TRANSIENT);
while (sqlite3_step(stmt) == SQLITE_ROW) {
@@ -375,17 +380,17 @@
string identity = identityName.toUri();
sqlite3_stmt *stmt;
- sqlite3_prepare_v2(m_db, "DELETE FROM Contact WHERE contact_namespace=?", -1, &stmt, 0);
+ sqlite3_prepare_v2(m_db, "DELETE FROM Contact WHERE contact_namespace=?", -1, &stmt, nullptr);
sqlite3_bind_string(stmt, 1, identity, SQLITE_TRANSIENT);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
- sqlite3_prepare_v2(m_db, "DELETE FROM ContactProfile WHERE profile_identity=?", -1, &stmt, 0);
+ sqlite3_prepare_v2(m_db, "DELETE FROM ContactProfile WHERE profile_identity=?", -1, &stmt, nullptr);
sqlite3_bind_string(stmt, 1, identity, SQLITE_TRANSIENT);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
- sqlite3_prepare_v2(m_db, "DELETE FROM TrustScope WHERE contact_namespace=?", -1, &stmt, 0);
+ sqlite3_prepare_v2(m_db, "DELETE FROM TrustScope WHERE contact_namespace=?", -1, &stmt, nullptr);
sqlite3_bind_string(stmt, 1, identity, SQLITE_TRANSIENT);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
@@ -405,7 +410,7 @@
"INSERT INTO Contact (contact_namespace, contact_alias, contact_keyName, \
contact_key, notBefore, notAfter, is_introducer) \
values (?, ?, ?, ?, ?, ?, ?)",
- -1, &stmt, 0);
+ -1, &stmt, nullptr);
sqlite3_bind_string(stmt, 1, identity, SQLITE_TRANSIENT);
sqlite3_bind_string(stmt, 2, contact.getAlias(), SQLITE_TRANSIENT);
@@ -422,12 +427,12 @@
sqlite3_finalize(stmt);
const Profile& profile = contact.getProfile();
- for (Profile::const_iterator it = profile.begin(); it != profile.end(); it++) {
+ for (auto it = profile.begin(); it != profile.end(); it++) {
sqlite3_prepare_v2(m_db,
"INSERT INTO ContactProfile \
(profile_identity, profile_type, profile_value, endorse) \
values (?, ?, ?, 0)",
- -1, &stmt, 0);
+ -1, &stmt, nullptr);
sqlite3_bind_string(stmt, 1, identity, SQLITE_TRANSIENT);
sqlite3_bind_string(stmt, 2, it->first, SQLITE_TRANSIENT);
sqlite3_bind_string(stmt, 3, it->second, SQLITE_TRANSIENT);
@@ -436,13 +441,13 @@
}
if (isIntroducer) {
- Contact::const_iterator it = contact.trustScopeBegin();
- Contact::const_iterator end = contact.trustScopeEnd();
+ auto it = contact.trustScopeBegin();
+ auto end = contact.trustScopeEnd();
while (it != end) {
sqlite3_prepare_v2(m_db,
"INSERT INTO TrustScope (contact_namespace, trust_scope) values (?, ?)",
- -1, &stmt, 0);
+ -1, &stmt, nullptr);
sqlite3_bind_string(stmt, 1, identity, SQLITE_TRANSIENT);
sqlite3_bind_string(stmt, 2, it->first.toUri(), SQLITE_TRANSIENT);
sqlite3_step(stmt);
@@ -463,7 +468,7 @@
sqlite3_prepare_v2(m_db,
"SELECT contact_alias, contact_keyName, contact_key, notBefore, notAfter, \
is_introducer FROM Contact where contact_namespace=?",
- -1, &stmt, 0);
+ -1, &stmt, nullptr);
sqlite3_bind_string(stmt, 1, identity.toUri(), SQLITE_TRANSIENT);
if (sqlite3_step(stmt) == SQLITE_ROW) {
@@ -487,7 +492,7 @@
sqlite3_prepare_v2(m_db,
"SELECT profile_type, profile_value FROM ContactProfile \
where profile_identity=?",
- -1, &stmt, 0);
+ -1, &stmt, nullptr);
sqlite3_bind_string(stmt, 1, identity.toUri(), SQLITE_TRANSIENT);
while (sqlite3_step(stmt) == SQLITE_ROW) {
@@ -501,7 +506,7 @@
if (contact->isIntroducer()) {
sqlite3_prepare_v2(m_db,
"SELECT trust_scope FROM TrustScope WHERE contact_namespace=?",
- -1, &stmt, 0);
+ -1, &stmt, nullptr);
sqlite3_bind_string(stmt, 1, identity.toUri(), SQLITE_TRANSIENT);
while (sqlite3_step(stmt) == SQLITE_ROW) {
@@ -520,7 +525,7 @@
{
sqlite3_stmt *stmt;
sqlite3_prepare_v2(m_db, "UPDATE Contact SET is_introducer=? WHERE contact_namespace=?",
- -1, &stmt, 0);
+ -1, &stmt, nullptr);
sqlite3_bind_int(stmt, 1, (isIntroducer ? 1 : 0));
sqlite3_bind_string(stmt, 2, identity.toUri(), SQLITE_TRANSIENT);
sqlite3_step(stmt);
@@ -533,7 +538,7 @@
{
sqlite3_stmt *stmt;
sqlite3_prepare_v2(m_db, "UPDATE Contact SET contact_alias=? WHERE contact_namespace=?",
- -1, &stmt, 0);
+ -1, &stmt, nullptr);
sqlite3_bind_string(stmt, 1, alias, SQLITE_TRANSIENT);
sqlite3_bind_string(stmt, 2, identity.toUri(), SQLITE_TRANSIENT);
sqlite3_step(stmt);
@@ -547,13 +552,14 @@
bool result = false;
sqlite3_stmt *stmt;
- sqlite3_prepare_v2(m_db, "SELECT count(*) FROM Contact WHERE contact_namespace=?", -1, &stmt, 0);
+ sqlite3_prepare_v2(m_db, "SELECT count(*) FROM Contact WHERE contact_namespace=?",
+ -1, &stmt, nullptr);
sqlite3_bind_string(stmt, 1, name.toUri(), SQLITE_TRANSIENT);
int res = sqlite3_step(stmt);
if (res == SQLITE_ROW) {
- int countAll = sqlite3_column_int (stmt, 0);
+ int countAll = sqlite3_column_int(stmt, 0);
if (countAll > 0)
result = true;
}
@@ -568,7 +574,7 @@
vector<Name> contactNames;
sqlite3_stmt *stmt;
- sqlite3_prepare_v2(m_db, "SELECT contact_namespace FROM Contact", -1, &stmt, 0);
+ sqlite3_prepare_v2(m_db, "SELECT contact_namespace FROM Contact", -1, &stmt, nullptr);
while (sqlite3_step(stmt) == SQLITE_ROW) {
string identity = sqlite3_column_string(stmt, 0);
@@ -576,7 +582,7 @@
}
sqlite3_finalize(stmt);
- for (vector<Name>::iterator it = contactNames.begin(); it != contactNames.end(); it++) {
+ for (auto it = contactNames.begin(); it != contactNames.end(); it++) {
shared_ptr<Contact> contact = getContact(*it);
if (static_cast<bool>(contact))
contacts.push_back(contact);
@@ -591,7 +597,7 @@
sqlite3_prepare_v2(m_db,
"INSERT OR REPLACE INTO DnsData (dns_name, dns_type, dns_value, data_name) \
VALUES (?, ?, ?, ?)",
- -1, &stmt, 0);
+ -1, &stmt, nullptr);
sqlite3_bind_string(stmt, 1, name, SQLITE_TRANSIENT);
sqlite3_bind_string(stmt, 2, type, SQLITE_TRANSIENT);
sqlite3_bind_block(stmt, 3, data, SQLITE_TRANSIENT);
@@ -607,7 +613,7 @@
shared_ptr<Data> data;
sqlite3_stmt *stmt;
- sqlite3_prepare_v2(m_db, "SELECT dns_value FROM DnsData where data_name=?", -1, &stmt, 0);
+ sqlite3_prepare_v2(m_db, "SELECT dns_value FROM DnsData where data_name=?", -1, &stmt, nullptr);
sqlite3_bind_string(stmt, 1, dataName.toUri(), SQLITE_TRANSIENT);
if (sqlite3_step(stmt) == SQLITE_ROW) {
@@ -626,7 +632,7 @@
sqlite3_stmt *stmt;
sqlite3_prepare_v2(m_db, "SELECT dns_value FROM DnsData where dns_name=? and dns_type=?",
- -1, &stmt, 0);
+ -1, &stmt, nullptr);
sqlite3_bind_string(stmt, 1, name, SQLITE_TRANSIENT);
sqlite3_bind_string(stmt, 2, type, SQLITE_TRANSIENT);
diff --git a/src/controller.cpp b/src/controller.cpp
index b8b2c97..9e794b9 100644
--- a/src/controller.cpp
+++ b/src/controller.cpp
@@ -10,7 +10,6 @@
*/
#include "controller.hpp"
-#include "cryptopp.hpp"
#include "conf.hpp"
#include "endorse-info.hpp"
@@ -19,9 +18,14 @@
#include <QDir>
#include <QTimer>
-#include <boost/filesystem.hpp>
+#include <ndn-cxx/security/transform/buffer-source.hpp>
+#include <ndn-cxx/security/transform/digest-filter.hpp>
+#include <ndn-cxx/security/transform/hex-encode.hpp>
+#include <ndn-cxx/security/transform/stream-sink.hpp>
#include <ndn-cxx/util/random.hpp>
+#include <boost/filesystem.hpp>
+
Q_DECLARE_METATYPE(ndn::Name)
Q_DECLARE_METATYPE(ndn::security::Certificate)
Q_DECLARE_METATYPE(chronochat::EndorseInfo)
@@ -247,7 +251,19 @@
saveConf();
}
-// public methods
+static string
+getRandomString()
+{
+ uint32_t r = ndn::random::generateWord32();
+ std::ostringstream ss;
+ {
+ using namespace ndn::security::transform;
+ bufferSource(reinterpret_cast<const uint8_t*>(&r), sizeof(r))
+ >> hexEncode(false)
+ >> streamSink(ss);
+ }
+ return ss.str();
+}
// private methods
@@ -256,13 +272,13 @@
{
string dbName("chronos-");
- std::stringstream ss;
+ std::ostringstream ss;
{
- using namespace CryptoPP;
-
- SHA256 hash;
- StringSource(m_identity.wireEncode().wire(), m_identity.wireEncode().size(), true,
- new HashFilter(hash, new HexEncoder(new FileSink(ss), false)));
+ using namespace ndn::security::transform;
+ bufferSource(m_identity.wireEncode().wire(), m_identity.wireEncode().size())
+ >> digestFilter(ndn::DigestAlgorithm::SHA256)
+ >> hexEncode(false)
+ >> streamSink(ss);
}
dbName.append(ss.str()).append(".db");
@@ -429,8 +445,8 @@
menu->addAction(m_addContactAction);
menu->addSeparator();
{
- ChatActionList::const_iterator it = m_chatActionList.begin();
- ChatActionList::const_iterator end = m_chatActionList.end();
+ auto it = m_chatActionList.begin();
+ auto end = m_chatActionList.end();
if (it != end) {
for (; it != end; it++)
menu->addAction(it->second);
@@ -442,8 +458,8 @@
menu->addAction(m_minimizeAction);
m_closeMenu = menu->addMenu("Close chatroom");
{
- ChatActionList::const_iterator it = m_closeActionList.begin();
- ChatActionList::const_iterator end = m_closeActionList.end();
+ auto it = m_closeActionList.begin();
+ auto end = m_closeActionList.end();
if (it == end)
m_closeMenu->setEnabled(false);
else
@@ -454,30 +470,6 @@
menu->addAction(m_quitAction);
}
-string
-Controller::getRandomString()
-{
- uint32_t r = ndn::random::generateWord32();
- std::stringstream ss;
- {
- using namespace CryptoPP;
- StringSource(reinterpret_cast<uint8_t*>(&r), 4, true,
- new HexEncoder(new FileSink(ss), false));
-
- }
- // for (int i = 0; i < 8; i++)
- // {
- // uint32_t t = r & mask;
- // if (t < 10)
- // ss << static_cast<char>(t + 0x30);
- // else
- // ss << static_cast<char>(t + 0x57);
- // r = r >> 4;
- // }
-
- return ss.str();
-}
-
void
Controller::addChatDialog(const QString& chatroomName, ChatDialog* chatDialog)
{
@@ -529,7 +521,7 @@
Controller::onIdentityUpdated(const QString& identity)
{
while (!m_chatDialogList.empty()) {
- ChatDialogList::const_iterator it = m_chatDialogList.begin();
+ auto it = m_chatDialogList.begin();
it->second->shutdown();
}
@@ -646,8 +638,8 @@
m_addContactPanel->hide();
m_discoveryPanel->hide();
- ChatDialogList::iterator it = m_chatDialogList.begin();
- ChatDialogList::iterator end = m_chatDialogList.end();
+ auto it = m_chatDialogList.begin();
+ auto end = m_chatDialogList.end();
for (; it != end; it++)
it->second->hide();
}
@@ -656,7 +648,7 @@
Controller::onQuitAction()
{
while (!m_chatDialogList.empty()) {
- ChatDialogList::const_iterator it = m_chatDialogList.begin();
+ auto it = m_chatDialogList.begin();
it->second->shutdown();
}
@@ -732,8 +724,7 @@
QString chatroomName = QString::fromStdString(invitation.getChatroom());
onStartChatroom(chatroomName, secured);
- ChatDialogList::iterator it = m_chatDialogList.find(chatroomName.toStdString());
-
+ auto it = m_chatDialogList.find(chatroomName.toStdString());
BOOST_ASSERT(it != m_chatDialogList.end());
it->second->addSyncAnchor(invitation);
}
@@ -759,7 +750,7 @@
{
emit removeChatroom(chatroomName);
- ChatDialogList::iterator it = m_chatDialogList.find(chatroomName.toStdString());
+ auto it = m_chatDialogList.find(chatroomName.toStdString());
if (it != m_chatDialogList.end()) {
ChatDialog* deletedChat = it->second;
if (deletedChat)
diff --git a/src/controller.hpp b/src/controller.hpp
index ca92c82..d0635bb 100644
--- a/src/controller.hpp
+++ b/src/controller.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
/*
- * Copyright (c) 2013, Regents of the University of California
+ * Copyright (c) 2020, Regents of the University of California
* Yingdi Yu
*
* BSD license, See the LICENSE file for more information
@@ -73,9 +73,6 @@
void
updateMenu();
- std::string
- getRandomString();
-
void
addChatDialog(const QString& chatroomName, ChatDialog* chatDialog);
diff --git a/src/cryptopp.hpp b/src/cryptopp.hpp
deleted file mode 100644
index 01fbfc2..0000000
--- a/src/cryptopp.hpp
+++ /dev/null
@@ -1,23 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013, Regents of the University of California
- *
- * BSD license, See the LICENSE file for more information
- *
- * Author: Yingdi Yu <yingdi@cs.ucla.edu>
- */
-
-#ifndef CHRONOCHAT_CRYPTOPP_HPP
-#define CHRONOCHAT_CRYPTOPP_HPP
-
-// suppress CryptoPP warnings
-#pragma GCC system_header
-#pragma clang system_header
-
-#include <cryptopp/hex.h>
-#include <cryptopp/files.h>
-#include <cryptopp/base64.h>
-#include <cryptopp/sha.h>
-#include <cryptopp/filters.h>
-
-#endif // CHRONOCHAT_CRYPTOPP_HPP
diff --git a/src/invitation.cpp b/src/invitation.cpp
index 9af3c4d..8ca4b06 100644
--- a/src/invitation.cpp
+++ b/src/invitation.cpp
@@ -10,12 +10,9 @@
#include "invitation.hpp"
-#include <ndn-cxx/security/signature-sha256-with-rsa.hpp>
-
namespace chronochat {
using std::string;
-
using ndn::security::Certificate;
const size_t Invitation::NAME_SIZE_MIN = 7;
diff --git a/src/main.cpp b/src/main.cpp
index 039fa42..a9b4c38 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -11,40 +11,33 @@
#include "controller.hpp"
#include <QApplication>
-#include <QTextCodec>
+#include <boost/exception/diagnostic_information.hpp>
#include <iostream>
-#include <ndn-cxx/face.hpp>
-#include <boost/thread/thread.hpp>
-class NewApp : public QApplication
+class ChronoChatApp : public QApplication
{
public:
- NewApp(int& argc, char** argv)
- : QApplication(argc, argv)
- {
- }
+ using QApplication::QApplication;
bool
- notify(QObject* receiver, QEvent* event)
+ notify(QObject* receiver, QEvent* event) final
{
try {
return QApplication::notify(receiver, event);
}
catch (const std::exception& e) {
- std::cerr << "Exception thrown:" << e.what() << std::endl;
+ std::cerr << boost::diagnostic_information(e) << std::endl;
return false;
}
-
}
};
-int main(int argc, char *argv[])
+int
+main(int argc, char *argv[])
{
- NewApp app(argc, argv);
-
+ ChronoChatApp app(argc, argv);
chronochat::Controller controller;
-
app.setQuitOnLastWindowClosed(false);
return app.exec();