Add Tools::readFromDevice() and make FileKey use it.

This commit is contained in:
Felix Geyer
2012-05-10 19:00:36 +02:00
parent 6eebd95de1
commit cc6f524168
4 changed files with 38 additions and 7 deletions

View File

@@ -222,8 +222,14 @@ bool FileKey::loadBinary(QIODevice* device)
return false;
}
m_key = device->readAll();
return true;
QByteArray data;
if (!Tools::readAllFromDevice(device, data) || data.size() != 32) {
return false;
}
else {
m_key = data;
return true;
}
}
bool FileKey::loadHex(QIODevice* device)
@@ -232,7 +238,10 @@ bool FileKey::loadHex(QIODevice* device)
return false;
}
QByteArray data = device->readAll();
QByteArray data;
if (!Tools::readAllFromDevice(device, data) || data.size() != 64) {
return false;
}
if (!Tools::isHex(data)) {
return false;
@@ -253,11 +262,12 @@ bool FileKey::loadHashed(QIODevice* device)
CryptoHash cryptoHash(CryptoHash::Sha256);
QByteArray buffer;
while (!device->atEnd()) {
buffer = device->read(1024);
do {
if (!Tools::readFromDevice(device, buffer)) {
return false;
}
cryptoHash.addData(buffer);
}
} while (!buffer.isEmpty());
m_key = cryptoHash.result();