MCPcopy Create free account
hub / github.com/Segs/Segs / encode_buffer

Function encode_buffer

Projects/CoX/Common/AuthProtocol/AuthLink.cpp:39–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37};
38namespace {
39void encode_buffer(AuthLinkState &state,const AuthLinkEvent *ev)
40{
41 assert(ev);
42 if(ev==nullptr)
43 return;
44 // remember the location we'll put the packet size into
45 uint16_t *packet_size = reinterpret_cast<uint16_t *>(state.m_unsent_bytes_storage.write_ptr());
46 // put 0 as size for now
47 state.m_unsent_bytes_storage.uPut((uint16_t)0);
48 // remember start location
49 size_t actual_packet_start = state.m_unsent_bytes_storage.GetReadableDataSize();
50 // store bytes
51 ev->serializeto(state.m_unsent_bytes_storage);
52 // calculate the number of stored bytes, and set it in packet_size,
53 // -1 because opcode is not counted toward packet size
54 *packet_size = (state.m_unsent_bytes_storage.GetReadableDataSize() - actual_packet_start) - 1;
55
56 // additional encryption of login details
57 if(ev->type()==evLoginRequest)
58 state.m_codec.DesCode(state.m_unsent_bytes_storage.read_ptr()+actual_packet_start+1,30); //only part of packet is encrypted with des
59
60 // every packet, but the authorization protocol, is encrypted
61 if(ev->type()!=evAuthProtocolVersion)
62 state.m_codec.XorCodeBuf(state.m_unsent_bytes_storage.read_ptr()+actual_packet_start,state.m_unsent_bytes_storage.GetReadableDataSize()-actual_packet_start); // opcode gets encrypted
63
64}
65/**
66 \brief Convert opcode byte to corresponding packet type
67 \arg opcode packet opcode byte

Callers 1

handle_outputMethod · 0.85

Calls 8

write_ptrMethod · 0.80
uPutMethod · 0.80
GetReadableDataSizeMethod · 0.80
DesCodeMethod · 0.80
read_ptrMethod · 0.80
XorCodeBufMethod · 0.80
serializetoMethod · 0.45
typeMethod · 0.45

Tested by

no test coverage detected