mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-12-04 15:39:34 +01:00
Refactor Endian namespace
This commit is contained in:
committed by
Jonathan White
parent
3461cbfb06
commit
d1a19a1009
@@ -130,7 +130,7 @@ bool HashedBlockStream::readHashedBlock()
|
||||
{
|
||||
bool ok;
|
||||
|
||||
quint32 index = Endian::readUInt32(m_baseDevice, ByteOrder, &ok);
|
||||
quint32 index = Endian::readSizedInt<quint32>(m_baseDevice, ByteOrder, &ok);
|
||||
if (!ok || index != m_blockIndex) {
|
||||
m_error = true;
|
||||
setErrorString("Invalid block index.");
|
||||
@@ -144,7 +144,7 @@ bool HashedBlockStream::readHashedBlock()
|
||||
return false;
|
||||
}
|
||||
|
||||
m_blockSize = Endian::readInt32(m_baseDevice, ByteOrder, &ok);
|
||||
m_blockSize = Endian::readSizedInt<qint32>(m_baseDevice, ByteOrder, &ok);
|
||||
if (!ok || m_blockSize < 0) {
|
||||
m_error = true;
|
||||
setErrorString("Invalid block size.");
|
||||
@@ -217,7 +217,7 @@ qint64 HashedBlockStream::writeData(const char* data, qint64 maxSize)
|
||||
|
||||
bool HashedBlockStream::writeHashedBlock()
|
||||
{
|
||||
if (!Endian::writeInt32(m_blockIndex, m_baseDevice, ByteOrder)) {
|
||||
if (!Endian::writeSizedInt<qint32>(m_blockIndex, m_baseDevice, ByteOrder)) {
|
||||
m_error = true;
|
||||
setErrorString(m_baseDevice->errorString());
|
||||
return false;
|
||||
@@ -238,7 +238,7 @@ bool HashedBlockStream::writeHashedBlock()
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Endian::writeInt32(m_buffer.size(), m_baseDevice, ByteOrder)) {
|
||||
if (!Endian::writeSizedInt<qint32>(m_buffer.size(), m_baseDevice, ByteOrder)) {
|
||||
m_error = true;
|
||||
setErrorString(m_baseDevice->errorString());
|
||||
return false;
|
||||
|
||||
@@ -144,7 +144,7 @@ bool HmacBlockStream::readHashedBlock()
|
||||
setErrorString("Invalid block size size.");
|
||||
return false;
|
||||
}
|
||||
qint32 blockSize = Endian::bytesToInt32(blockSizeBytes, ByteOrder);
|
||||
qint32 blockSize = Endian::bytesToSizedInt<qint32>(blockSizeBytes, ByteOrder);
|
||||
if (blockSize < 0) {
|
||||
m_error = true;
|
||||
setErrorString("Invalid block size.");
|
||||
@@ -160,7 +160,7 @@ bool HmacBlockStream::readHashedBlock()
|
||||
|
||||
CryptoHash hasher(CryptoHash::Sha256, true);
|
||||
hasher.setKey(getCurrentHmacKey());
|
||||
hasher.addData(Endian::uint64ToBytes(m_blockIndex, ByteOrder));
|
||||
hasher.addData(Endian::sizedIntToBytes<quint64>(m_blockIndex, ByteOrder));
|
||||
hasher.addData(blockSizeBytes);
|
||||
hasher.addData(m_buffer);
|
||||
|
||||
@@ -219,8 +219,8 @@ bool HmacBlockStream::writeHashedBlock()
|
||||
{
|
||||
CryptoHash hasher(CryptoHash::Sha256, true);
|
||||
hasher.setKey(getCurrentHmacKey());
|
||||
hasher.addData(Endian::uint64ToBytes(m_blockIndex, ByteOrder));
|
||||
hasher.addData(Endian::int32ToBytes(m_buffer.size(), ByteOrder));
|
||||
hasher.addData(Endian::sizedIntToBytes<quint64>(m_blockIndex, ByteOrder));
|
||||
hasher.addData(Endian::sizedIntToBytes<qint32>(m_buffer.size(), ByteOrder));
|
||||
hasher.addData(m_buffer);
|
||||
QByteArray hash = hasher.result();
|
||||
|
||||
@@ -230,7 +230,7 @@ bool HmacBlockStream::writeHashedBlock()
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Endian::writeInt32(m_buffer.size(), m_baseDevice, ByteOrder)) {
|
||||
if (!Endian::writeSizedInt<qint32>(m_buffer.size(), m_baseDevice, ByteOrder)) {
|
||||
m_error = true;
|
||||
setErrorString(m_baseDevice->errorString());
|
||||
return false;
|
||||
@@ -255,7 +255,7 @@ QByteArray HmacBlockStream::getCurrentHmacKey() const {
|
||||
|
||||
QByteArray HmacBlockStream::getHmacKey(quint64 blockIndex, QByteArray key) {
|
||||
Q_ASSERT(key.size() == 64);
|
||||
QByteArray indexBytes = Endian::uint64ToBytes(blockIndex, ByteOrder);
|
||||
QByteArray indexBytes = Endian::sizedIntToBytes<quint64>(blockIndex, ByteOrder);
|
||||
CryptoHash hasher(CryptoHash::Sha512);
|
||||
hasher.addData(indexBytes);
|
||||
hasher.addData(key);
|
||||
|
||||
Reference in New Issue
Block a user