| 1507 | } |
| 1508 | |
| 1509 | void encrypt_json(nlohmann::json &v, const td::Bits256 &private_key, const td::Bits256 &public_key, |
| 1510 | bool client_to_worker) { |
| 1511 | v["is_encrypted"] = "v1"; |
| 1512 | |
| 1513 | td::Ed25519::PrivateKey pk(td::SecureString{private_key.as_slice()}); |
| 1514 | td::Bits256 pub; |
| 1515 | pub.as_slice().copy_from(pk.get_public_key().move_as_ok().as_octet_string().as_slice()); |
| 1516 | v["sender_public_key"] = td::hex_encode(pub.as_slice()); |
| 1517 | v["receiver_public_key"] = td::hex_encode(public_key.as_slice()); |
| 1518 | |
| 1519 | char buf[32]; |
| 1520 | td::Random::secure_bytes(td::MutableSlice(buf, 32)); |
| 1521 | auto encryption_nonce = td::base64_encode(td::Slice(buf, 32)); |
| 1522 | v["encryption_nonce"] = encryption_nonce; |
| 1523 | |
| 1524 | auto shared_secret = |
| 1525 | generate_shared_secret(private_key, public_key, pub, encryption_nonce, client_to_worker).move_as_ok(); |
| 1526 | encrypt_all_strings(v, shared_secret.as_slice()); |
| 1527 | } |
| 1528 | |
| 1529 | td::Status decrypt_json(nlohmann::json &v, const td::Bits256 &private_key, td::Bits256 &public_key, |
| 1530 | bool check_public_key, bool client_to_worker) { |
no test coverage detected