* Prepares the packet so it can be read * @return True when the packet was valid, otherwise false. */
| 276 | * @return True when the packet was valid, otherwise false. |
| 277 | */ |
| 278 | bool Packet::PrepareToRead() |
| 279 | { |
| 280 | /* Put the position on the right place */ |
| 281 | this->pos = static_cast<PacketSize>(EncodedLengthOfPacketSize()); |
| 282 | |
| 283 | if (cs == nullptr || cs->receive_encryption_handler == nullptr) return true; |
| 284 | |
| 285 | size_t mac_size = cs->receive_encryption_handler->MACSize(); |
| 286 | if (this->buffer.size() <= pos + mac_size) return false; |
| 287 | |
| 288 | bool valid = cs->receive_encryption_handler->Decrypt(std::span(&this->buffer[pos], mac_size), std::span(&this->buffer[pos + mac_size], this->buffer.size() - pos - mac_size)); |
| 289 | this->pos += static_cast<PacketSize>(mac_size); |
| 290 | return valid; |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * Get the \c PacketType from this packet. |