2019-06-26 15:51:48 +02:00
|
|
|
//
|
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019
|
|
|
|
//
|
|
|
|
// 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)
|
|
|
|
//
|
|
|
|
#include "td/mtproto/TlsReaderByteFlow.h"
|
|
|
|
|
|
|
|
#include "td/utils/Status.h"
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
|
|
|
void TlsReaderByteFlow::loop() {
|
|
|
|
while (true) {
|
|
|
|
if (input_->size() < 5) {
|
|
|
|
set_need_size(5);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto it = input_->clone();
|
|
|
|
uint8 buf[5];
|
|
|
|
it.advance(5, MutableSlice(buf, 5));
|
|
|
|
if (Slice(buf, 3) != Slice("\x17\x03\x03")) {
|
2019-07-01 15:18:28 +02:00
|
|
|
close_input(Status::Error("Invalid bytes at the beginning of a packet (emulated tls)"));
|
2019-06-26 15:51:48 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
size_t len = (buf[3] << 8) | buf[4];
|
|
|
|
if (it.size() < len) {
|
|
|
|
set_need_size(5 + len);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
output_.append(it.cut_head(len));
|
|
|
|
*input_ = std::move(it);
|
2019-07-01 16:37:31 +02:00
|
|
|
on_output_updated();
|
2019-06-26 15:51:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace td
|