mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
Improve creating channels in adnl (#1108)
* Improve creating channels in adnl * Improve handling of cryptographic keys
This commit is contained in:
parent
0cff1c88f7
commit
77a816e461
9 changed files with 109 additions and 80 deletions
|
@ -21,6 +21,7 @@
|
|||
#include "td/utils/overloaded.h"
|
||||
#include "tl-utils/tl-utils.hpp"
|
||||
#include "encryptor.h"
|
||||
#include "encryptor.hpp"
|
||||
#include "crypto/Ed25519.h"
|
||||
|
||||
namespace ton {
|
||||
|
@ -63,12 +64,31 @@ td::Result<PublicKey> PublicKey::import(td::Slice s) {
|
|||
return PublicKey{x};
|
||||
}
|
||||
|
||||
td::Result<std::unique_ptr<Encryptor>> pubkeys::Ed25519::create_encryptor() const {
|
||||
return std::make_unique<EncryptorEd25519>(data_);
|
||||
}
|
||||
|
||||
td::Result<std::unique_ptr<Encryptor>> pubkeys::AES::create_encryptor() const {
|
||||
return std::make_unique<EncryptorAES>(data_);
|
||||
}
|
||||
|
||||
td::Result<std::unique_ptr<Encryptor>> pubkeys::Unenc::create_encryptor() const {
|
||||
return std::make_unique<EncryptorNone>();
|
||||
}
|
||||
|
||||
td::Result<std::unique_ptr<Encryptor>> pubkeys::Overlay::create_encryptor() const {
|
||||
return std::make_unique<EncryptorOverlay>();
|
||||
}
|
||||
|
||||
td::Result<std::unique_ptr<Encryptor>> PublicKey::create_encryptor() const {
|
||||
return Encryptor::create(tl().get());
|
||||
td::Result<std::unique_ptr<Encryptor>> res;
|
||||
pub_key_.visit([&](auto &obj) { res = obj.create_encryptor(); });
|
||||
return res;
|
||||
}
|
||||
|
||||
td::Result<td::actor::ActorOwn<EncryptorAsync>> PublicKey::create_encryptor_async() const {
|
||||
return EncryptorAsync::create(tl().get());
|
||||
TRY_RESULT(encryptor, create_encryptor());
|
||||
return td::actor::create_actor<EncryptorAsync>("encryptor", std::move(encryptor));
|
||||
}
|
||||
|
||||
bool PublicKey::empty() const {
|
||||
|
@ -109,6 +129,22 @@ privkeys::Ed25519::Ed25519(td::Ed25519::PrivateKey key) {
|
|||
data_.as_slice().copy_from(td::Slice(s));
|
||||
}
|
||||
|
||||
td::Result<std::unique_ptr<Decryptor>> privkeys::Ed25519::create_decryptor() const {
|
||||
return std::make_unique<DecryptorEd25519>(data_);
|
||||
}
|
||||
|
||||
td::Result<std::unique_ptr<Decryptor>> privkeys::AES::create_decryptor() const {
|
||||
return std::make_unique<DecryptorAES>(data_);
|
||||
}
|
||||
|
||||
td::Result<std::unique_ptr<Decryptor>> privkeys::Unenc::create_decryptor() const {
|
||||
return std::make_unique<DecryptorNone>();
|
||||
}
|
||||
|
||||
td::Result<std::unique_ptr<Decryptor>> privkeys::Overlay::create_decryptor() const {
|
||||
return std::make_unique<DecryptorFail>();
|
||||
}
|
||||
|
||||
pubkeys::Ed25519::Ed25519(td::Ed25519::PublicKey key) {
|
||||
auto s = key.as_octet_string();
|
||||
CHECK(s.length() == 32);
|
||||
|
@ -188,11 +224,14 @@ tl_object_ptr<ton_api::PrivateKey> PrivateKey::tl() const {
|
|||
}
|
||||
|
||||
td::Result<std::unique_ptr<Decryptor>> PrivateKey::create_decryptor() const {
|
||||
return Decryptor::create(tl().get());
|
||||
td::Result<std::unique_ptr<Decryptor>> res;
|
||||
priv_key_.visit([&](auto &obj) { res = obj.create_decryptor(); });
|
||||
return res;
|
||||
}
|
||||
|
||||
td::Result<td::actor::ActorOwn<DecryptorAsync>> PrivateKey::create_decryptor_async() const {
|
||||
return DecryptorAsync::create(tl().get());
|
||||
TRY_RESULT(decryptor, create_decryptor());
|
||||
return td::actor::create_actor<DecryptorAsync>("decryptor", std::move(decryptor));
|
||||
}
|
||||
|
||||
} // namespace ton
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue