2018-12-31 20:04:05 +01:00
|
|
|
//
|
2018-01-02 14:42:31 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// 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
|
2018-07-03 21:29:04 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/mtproto/PacketStorer.h"
|
|
|
|
|
2018-06-15 17:11:48 +02:00
|
|
|
#include "td/utils/Random.h"
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
namespace td {
|
|
|
|
namespace mtproto {
|
2018-06-16 02:03:14 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
class NoCryptoImpl {
|
|
|
|
public:
|
2018-06-16 02:03:14 +02:00
|
|
|
NoCryptoImpl(uint64 message_id, const Storer &data, bool need_pad = true) : message_id_(message_id), data_(data) {
|
2018-06-15 17:11:48 +02:00
|
|
|
if (need_pad) {
|
2018-06-24 18:50:09 +02:00
|
|
|
size_t pad_size = -static_cast<int>(data_.size()) & 15;
|
2018-06-15 17:11:48 +02:00
|
|
|
pad_size += 16 * (static_cast<size_t>(Random::secure_int32()) % 16);
|
|
|
|
pad_.resize(pad_size);
|
|
|
|
Random::secure_bytes(pad_);
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
template <class T>
|
|
|
|
void do_store(T &storer) const {
|
2018-06-16 02:03:14 +02:00
|
|
|
storer.store_binary(message_id_);
|
|
|
|
storer.store_binary(static_cast<int32>(data_.size() + pad_.size()));
|
|
|
|
storer.store_storer(data_);
|
2018-06-15 17:11:48 +02:00
|
|
|
storer.store_slice(pad_);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-06-16 02:03:14 +02:00
|
|
|
uint64 message_id_;
|
|
|
|
const Storer &data_;
|
2018-06-15 17:11:48 +02:00
|
|
|
std::string pad_;
|
2018-12-31 20:04:05 +01:00
|
|
|
};
|
2018-06-16 02:03:14 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
} // namespace mtproto
|
|
|
|
} // namespace td
|