QByteArray SshPacketParser::asString(const QByteArray &data, quint32 *offset) { const quint32 length = asUint32(data, offset); if (size(data) < *offset + length) throw SshPacketParseException(); const QByteArray &string = data.mid(*offset, length); *offset += length; return string; }
Botan::BigInt SshPacketParser::asBigInt(const QByteArray &data, quint32 *offset) { const quint32 length = asUint32(data, offset); if (length == 0) return Botan::BigInt(); const Botan::byte *numberStart = reinterpret_cast<const Botan::byte *>(data.constData() + *offset); *offset += length; return Botan::BigInt::decode(numberStart, length); }
SshNameList SshPacketParser::asNameList(const QByteArray &data, quint32 *offset) { const quint32 length = asUint32(data, offset); const int listEndPos = *offset + length; if (data.size() < listEndPos) throw SshPacketParseException(); SshNameList names(length + 4); int nextNameOffset = *offset; int nextCommaOffset = data.indexOf(',', nextNameOffset); while (nextNameOffset > 0 && nextNameOffset < listEndPos) { const int stringEndPos = nextCommaOffset == -1 || nextCommaOffset > listEndPos ? listEndPos : nextCommaOffset; names.names << QByteArray(data.constData() + nextNameOffset, stringEndPos - nextNameOffset); nextNameOffset = nextCommaOffset + 1; nextCommaOffset = data.indexOf(',', nextNameOffset); } *offset += length; return names; }
quint32 SshPacketParser::asUint32(const QByteArray &data, quint32 *offset) { const quint32 v = asUint32(data, *offset); *offset += 4; return v; }
Variant::operator uint32_t() const { return asUint32(); }