From 69d9173dcd166b62dd1579411c1033b8062c3a6c Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 6 Nov 2018 23:25:09 +0300 Subject: [PATCH] Minor Slice usage improvements. GitOrigin-RevId: 44ceed78dfc3ec459a0c40b6863d1d6ffd863a64 --- td/mtproto/Handshake.cpp | 4 ++-- td/mtproto/TcpTransport.cpp | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/td/mtproto/Handshake.cpp b/td/mtproto/Handshake.cpp index f9062045..49e766e5 100644 --- a/td/mtproto/Handshake.cpp +++ b/td/mtproto/Handshake.cpp @@ -166,7 +166,7 @@ Status AuthKeyHandshake::on_server_dh_params(Slice message, Callback *connection size_t dh_inner_data_size = answer.size() - pad - 20; UInt<160> answer_real_sha1; - sha1(Slice(answer.ubegin() + 20, dh_inner_data_size), answer_real_sha1.raw); + sha1(answer.substr(20, dh_inner_data_size), answer_real_sha1.raw); if (answer_sha1 != answer_real_sha1) { return Status::Error("SHA1 mismatch"); } @@ -196,7 +196,7 @@ Status AuthKeyHandshake::on_server_dh_params(Slice message, Callback *connection as(encrypted_data.begin() + 20) = data.get_id(); auto real_size = tl_store_unsafe(data, encrypted_data.ubegin() + 20 + 4); CHECK(real_size + 4 == data_size); - sha1(Slice(encrypted_data.ubegin() + 20, data_size), encrypted_data.ubegin()); + sha1(encrypted_data.substr(20, data_size), encrypted_data.ubegin()); Random::secure_bytes(encrypted_data.ubegin() + encrypted_data_size, encrypted_data_size_with_pad - encrypted_data_size); tmp_KDF(server_nonce, new_nonce, &tmp_aes_key, &tmp_aes_iv); diff --git a/td/mtproto/TcpTransport.cpp b/td/mtproto/TcpTransport.cpp index 5de248cd..9eec19fe 100644 --- a/td/mtproto/TcpTransport.cpp +++ b/td/mtproto/TcpTransport.cpp @@ -130,8 +130,7 @@ void AbridgedTransport::write_prepare_inplace(BufferWriter *message, bool quick_ } void AbridgedTransport::init_output_stream(ChainBufferWriter *stream) { - const uint8 magic = 0xef; - stream->append(Slice(&magic, 1)); + stream->append("\xef"); } void ObfuscatedTransport::init(ChainBufferReader *input, ChainBufferWriter *output) {