MCPcopy Create free account
hub / github.com/blizzard4591/openMittsu / decrypt

Method decrypt

src/database/internal/ExternalMediaFileStorage.cpp:210–220  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

208 }
209
210 QByteArray ExternalMediaFileStorage::decrypt(QByteArray const& encryptedData, QByteArray const& key, QByteArray const& nonce) const {
211 QByteArray decryptedData(encryptedData.size() - cryptoGetHeaderSize(), '\0');
212 unsigned long long decrypted_len;
213 if (crypto_aead_xchacha20poly1305_ietf_decrypt(reinterpret_cast<unsigned char*>(decryptedData.data()), &decrypted_len, NULL, reinterpret_cast<unsigned char const*>(encryptedData.data()), encryptedData.size(), NULL, 0, reinterpret_cast<unsigned char const*>(nonce.data()), reinterpret_cast<unsigned char const*>(key.data())) != 0) {
214 throw openmittsu::exceptions::InternalErrorException() << "Could not decrypt blob, data corrupt!";
215 } else if (static_cast<int>(decrypted_len) != (encryptedData.size() - cryptoGetHeaderSize())) {
216 throw openmittsu::exceptions::InternalErrorException() << "Could not decrypt media item blob: Expected size was " << (encryptedData.size() - cryptoGetHeaderSize()) << " Bytes, but we got " << decrypted_len << " Bytes instead!";
217 }
218
219 return decryptedData;
220 }
221
222 QByteArray ExternalMediaFileStorage::generateKey() const {
223 QByteArray keyBytes(cryptoGetKeySize(), '\0');

Callers

nothing calls this directly

Calls 2

dataMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected