| 37 | }; |
| 38 | namespace { |
| 39 | void 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 |
no test coverage detected