QByteArray NLPacket::hashForPacketAndSecret(const udt::Packet& packet, const QUuid& connectionSecret) { QCryptographicHash hash(QCryptographicHash::Md5); int offset = Packet::totalHeaderSize(packet.isPartOfMessage()) + sizeof(PacketType) + sizeof(PacketVersion) + NUM_BYTES_RFC4122_UUID + NUM_BYTES_MD5_HASH; // add the packet payload and the connection UUID hash.addData(packet.getData() + offset, packet.getDataSize() - offset); hash.addData(connectionSecret.toRfc4122()); // return the hash return hash.result(); }
QByteArray NLPacket::verificationHashInHeader(const udt::Packet& packet) { int offset = Packet::totalHeaderSize(packet.isPartOfMessage()) + sizeof(PacketType) + sizeof(PacketVersion) + NUM_BYTES_RFC4122_UUID; return QByteArray(packet.getData() + offset, NUM_BYTES_MD5_HASH); }
PacketVersion NLPacket::versionInHeader(const udt::Packet& packet) { auto headerOffset = Packet::totalHeaderSize(packet.isPartOfMessage()); return *reinterpret_cast<const PacketVersion*>(packet.getData() + headerOffset + sizeof(PacketType)); }
QUuid NLPacket::sourceIDInHeader(const udt::Packet& packet) { int offset = Packet::totalHeaderSize(packet.isPartOfMessage()) + sizeof(PacketType) + sizeof(PacketVersion); return QUuid::fromRfc4122(QByteArray::fromRawData(packet.getData() + offset, NUM_BYTES_RFC4122_UUID)); }
PacketType NLPacket::typeInHeader(const udt::Packet& packet) { auto headerOffset = Packet::totalHeaderSize(packet.isPartOfMessage()); return *reinterpret_cast<const PacketType*>(packet.getData() + headerOffset); }