diff options
author | aunsane <aunsane@gmail.com> | 2018-04-27 21:33:17 +0300 |
---|---|---|
committer | aunsane <aunsane@gmail.com> | 2018-04-27 21:33:17 +0300 |
commit | e1ec72eab6d00b3ba38e5932bc88920f103b6e4a (patch) | |
tree | 999de2725a83e30fbbf6576200525d4ef0c5fe38 /protocols/Telegram/tdlib/td/td/telegram/net/PublicRsaKeyShared.h | |
parent | b9ce1d4d98525490ca1a38e2d9fd4f3369adb3e0 (diff) |
Telegram: initial commit
- tdlib moved to telegram dir
Diffstat (limited to 'protocols/Telegram/tdlib/td/td/telegram/net/PublicRsaKeyShared.h')
-rw-r--r-- | protocols/Telegram/tdlib/td/td/telegram/net/PublicRsaKeyShared.h | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/protocols/Telegram/tdlib/td/td/telegram/net/PublicRsaKeyShared.h b/protocols/Telegram/tdlib/td/td/telegram/net/PublicRsaKeyShared.h new file mode 100644 index 0000000000..453bb7bda1 --- /dev/null +++ b/protocols/Telegram/tdlib/td/td/telegram/net/PublicRsaKeyShared.h @@ -0,0 +1,62 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018 +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +#pragma once + +#include "td/telegram/net/DcId.h" + +#include "td/mtproto/crypto.h" + +#include "td/utils/common.h" +#include "td/utils/port/RwMutex.h" +#include "td/utils/Status.h" + +#include <utility> + +namespace td { + +class PublicRsaKeyShared : public PublicRsaKeyInterface { + public: + explicit PublicRsaKeyShared(DcId dc_id); + + class Listener { + public: + Listener() = default; + Listener(const Listener &) = delete; + Listener &operator=(const Listener &) = delete; + Listener(Listener &&) = delete; + Listener &operator=(Listener &&) = delete; + virtual ~Listener() = default; + virtual bool notify() = 0; + }; + + void add_rsa(RSA rsa); + Result<std::pair<RSA, int64>> get_rsa(const vector<int64> &fingerprints) override; + void drop_keys() override; + bool has_keys(); + + void add_listener(std::unique_ptr<Listener> listener); + + DcId dc_id() const { + return dc_id_; + } + + private: + DcId dc_id_; + struct RsaOption { + int64 fingerprint; + RSA rsa; + }; + std::vector<RsaOption> options_; + std::vector<std::unique_ptr<Listener>> listeners_; + RwMutex rw_mutex_; + + RSA *get_rsa_locked(int64 fingerprint); + + void notify(); +}; + +} // namespace td |