From 1ea7a2994ec387618e447a7bbfa7a309d953c555 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Tue, 25 May 2021 13:58:56 -0400 Subject: [PATCH] value: use non-const PublicKey --- include/opendht/default_types.h | 2 +- include/opendht/securedht.h | 10 +++++----- include/opendht/value.h | 8 ++++---- src/securedht.cpp | 10 +++++----- src/value.cpp | 4 ++-- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/include/opendht/default_types.h b/include/opendht/default_types.h index f6469d8d..73547447 100644 --- a/include/opendht/default_types.h +++ b/include/opendht/default_types.h @@ -77,7 +77,7 @@ public: return [](const Value& v){ return v.isSigned(); }; } - Sp<const crypto::PublicKey> owner; + Sp<crypto::PublicKey> owner; dht::InfoHash from; }; diff --git a/include/opendht/securedht.h b/include/opendht/securedht.h index c944e568..237dfb50 100644 --- a/include/opendht/securedht.h +++ b/include/opendht/securedht.h @@ -126,13 +126,13 @@ public: Value decrypt(const Value& v); void findCertificate(const InfoHash& node, const std::function<void(const Sp<crypto::Certificate>)>& cb); - void findPublicKey(const InfoHash& node, const std::function<void(const Sp<const crypto::PublicKey>)>& cb); + void findPublicKey(const InfoHash& node, const std::function<void(const Sp<crypto::PublicKey>)>& cb); - const Sp<crypto::Certificate> registerCertificate(const InfoHash& node, const Blob& cert); + Sp<crypto::Certificate> registerCertificate(const InfoHash& node, const Blob& cert); void registerCertificate(Sp<crypto::Certificate>& cert); - const Sp<crypto::Certificate> getCertificate(const InfoHash& node) const; - const Sp<const crypto::PublicKey> getPublicKey(const InfoHash& node) const; + Sp<crypto::Certificate> getCertificate(const InfoHash& node) const; + Sp<crypto::PublicKey> getPublicKey(const InfoHash& node) const; /** * Allows to set a custom callback called by the library to find a locally-stored certificate. @@ -354,7 +354,7 @@ private: // our certificate cache std::map<InfoHash, Sp<crypto::Certificate>> nodesCertificates_ {}; - std::map<InfoHash, Sp<const crypto::PublicKey>> nodesPubKeys_ {}; + std::map<InfoHash, Sp<crypto::PublicKey>> nodesPubKeys_ {}; std::atomic_bool forward_all_ {false}; bool enableCache_ {false}; diff --git a/include/opendht/value.h b/include/opendht/value.h index 70539bb8..a9936370 100644 --- a/include/opendht/value.h +++ b/include/opendht/value.h @@ -356,7 +356,7 @@ struct OPENDHT_PUBLIC Value void sign(const crypto::PrivateKey& key) { if (isEncrypted()) throw DhtException("Can't sign encrypted data."); - owner = std::make_shared<const crypto::PublicKey>(key.getPublicKey()); + owner = std::make_shared<crypto::PublicKey>(key.getPublicKey()); signature = key.sign(getToSign()); } @@ -368,8 +368,8 @@ struct OPENDHT_PUBLIC Value return isSigned() and owner->checkSignature(getToSign(), signature); } - std::shared_ptr<const crypto::PublicKey> getOwner() const { - return std::static_pointer_cast<const crypto::PublicKey>(owner); + std::shared_ptr<crypto::PublicKey> getOwner() const { + return std::static_pointer_cast<crypto::PublicKey>(owner); } /** @@ -594,7 +594,7 @@ struct OPENDHT_PUBLIC Value /** * Public key of the signer. */ - std::shared_ptr<const crypto::PublicKey> owner {}; + std::shared_ptr<crypto::PublicKey> owner {}; /** * Hash of the recipient (optional). diff --git a/src/securedht.cpp b/src/securedht.cpp index bf471d5d..407c86b2 100644 --- a/src/securedht.cpp +++ b/src/securedht.cpp @@ -118,7 +118,7 @@ SecureDht::secureType(ValueType&& type) return type; } -const Sp<crypto::Certificate> +Sp<crypto::Certificate> SecureDht::getCertificate(const InfoHash& node) const { if (node == getId()) @@ -130,7 +130,7 @@ SecureDht::getCertificate(const InfoHash& node) const return it->second; } -const Sp<const crypto::PublicKey> +Sp<crypto::PublicKey> SecureDht::getPublicKey(const InfoHash& node) const { if (node == getId()) @@ -142,7 +142,7 @@ SecureDht::getPublicKey(const InfoHash& node) const return it->second; } -const Sp<crypto::Certificate> +Sp<crypto::Certificate> SecureDht::registerCertificate(const InfoHash& node, const Blob& data) { Sp<crypto::Certificate> crt; @@ -220,7 +220,7 @@ SecureDht::findCertificate(const InfoHash& node, const std::function<void(const } void -SecureDht::findPublicKey(const InfoHash& node, const std::function<void(const Sp<const crypto::PublicKey>)>& cb) +SecureDht::findPublicKey(const InfoHash& node, const std::function<void(const Sp<crypto::PublicKey>)>& cb) { auto pk = getPublicKey(node); if (pk && *pk) { @@ -405,7 +405,7 @@ SecureDht::putEncrypted(const InfoHash& hash, const InfoHash& to, Sp<Value> val, callback(false, {}); return; } - findPublicKey(to, [=](const Sp<const crypto::PublicKey>& pk) { + findPublicKey(to, [this, hash, val = std::move(val), callback = std::move(callback), permanent](const Sp<crypto::PublicKey>& pk) { if(!pk || !*pk) { if (callback) callback(false, {}); diff --git a/src/value.cpp b/src/value.cpp index f6e2b1a9..5ea34384 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -163,7 +163,7 @@ Value::msgpack_unpack_body(const msgpack::object& o) throw msgpack::type_error(); crypto::PublicKey new_owner; new_owner.msgpack_unpack(*rowner); - owner = std::make_shared<const crypto::PublicKey>(std::move(new_owner)); + owner = std::make_shared<crypto::PublicKey>(std::move(new_owner)); if (auto rrecipient = findMapValue(*rbody, VALUE_KEY_TO)) { recipient = rrecipient->as<InfoHash>(); } @@ -193,7 +193,7 @@ Value::Value(const Json::Value& json) if (jowner.isString()) { auto ownerStr = jowner.asString(); auto ownerBlob = std::vector<unsigned char>(ownerStr.begin(), ownerStr.end()); - owner = std::make_shared<const crypto::PublicKey>(ownerBlob); + owner = std::make_shared<crypto::PublicKey>(ownerBlob); } const auto& jto = json[VALUE_KEY_TO]; if (jto.isString()) -- GitLab