/
ReconnectProof.h
70 lines (57 loc) · 1.84 KB
/
ReconnectProof.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* Copyright (c) 2015 - 2021 Ember
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "../Opcodes.h"
#include "../Packet.h"
#include "../Exceptions.h"
#include "../KeyData.h"
#include <boost/assert.hpp>
#include <botan/bigint.h>
#include <botan/secmem.h>
#include <array>
#include <cstdint>
#include <cstddef>
namespace ember::grunt::client {
class ReconnectProof final : public Packet {
static const std::size_t WIRE_LENGTH = 58;
State state_ = State::INITIAL;
public:
ReconnectProof() : Packet(Opcode::CMD_AUTH_RECONNECT_PROOF) {}
std::array<std::uint8_t, 16> salt;
std::array<std::uint8_t, 20> proof;
std::array<std::uint8_t, 20> client_checksum;
std::uint8_t key_count = 0;
std::vector<KeyData> keys;
State read_from_stream(spark::BinaryStream& stream) override {
BOOST_ASSERT_MSG(state_ != State::DONE, "Packet already complete - check your logic!");
if(state_ == State::INITIAL && stream.size() < WIRE_LENGTH) {
return State::CALL_AGAIN;
}
stream >> opcode;
stream.get(salt.data(), salt.size());
stream.get(proof.data(), proof.size());
stream.get(client_checksum.data(), client_checksum.size());
stream >> key_count;
// todo, read key data here
return (state_ = State::DONE);
}
void write_to_stream(spark::BinaryStream& stream) const override {
stream << opcode;
stream.put(salt.data(), salt.size());
stream.put(proof.data(), proof.size());
stream.put(client_checksum.data(), client_checksum.size());
stream << key_count;
for (auto& key : keys) {
stream << key.len;
stream << key.pub_value;
stream.put(key.product.data(), key.product.size());
stream.put(key.hash.data(), key.hash.size());
}
}
};
} // client, grunt, ember