1 // 2 // Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021 3 // 4 // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 // 7 #pragma once 8 9 #include "td/telegram/net/DcId.h" 10 11 #include "td/mtproto/RSA.h" 12 13 #include "td/utils/common.h" 14 #include "td/utils/port/RwMutex.h" 15 #include "td/utils/Status.h" 16 17 namespace td { 18 19 class PublicRsaKeyShared final : public mtproto::PublicRsaKeyInterface { 20 public: 21 PublicRsaKeyShared(DcId dc_id, bool is_test); 22 23 class Listener { 24 public: 25 Listener() = default; 26 Listener(const Listener &) = delete; 27 Listener &operator=(const Listener &) = delete; 28 Listener(Listener &&) = delete; 29 Listener &operator=(Listener &&) = delete; 30 virtual ~Listener() = default; 31 virtual bool notify() = 0; 32 }; 33 34 void add_rsa(mtproto::RSA rsa); 35 Result<RsaKey> get_rsa_key(const vector<int64> &fingerprints) final; 36 void drop_keys() final; 37 bool has_keys(); 38 39 void add_listener(unique_ptr<Listener> listener); 40 dc_id()41 DcId dc_id() const { 42 return dc_id_; 43 } 44 45 private: 46 DcId dc_id_; 47 std::vector<RsaKey> keys_; 48 std::vector<unique_ptr<Listener>> listeners_; 49 RwMutex rw_mutex_; 50 51 RsaKey *get_rsa_key_unsafe(int64 fingerprint); 52 53 void notify(); 54 }; 55 56 } // namespace td 57