MCPcopy Create free account
hub / github.com/TDesktop-x64/tdesktop / readMapWith

Method readMapWith

Telegram/SourceFiles/storage/storage_account.cpp:306–583  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

304}
305
306Account::ReadMapResult Account::readMapWith(
307 MTP::AuthKeyPtr localKey,
308 const QByteArray &legacyPasscode) {
309 auto ms = crl::now();
310
311 FileReadDescriptor mapData;
312 if (!ReadFile(mapData, u"map"_q, _basePath)) {
313 return ReadMapResult::Failed;
314 }
315 LOG(("App Info: reading map..."));
316
317 QByteArray legacySalt, legacyKeyEncrypted, mapEncrypted;
318 mapData.stream >> legacySalt >> legacyKeyEncrypted >> mapEncrypted;
319 if (!CheckStreamStatus(mapData.stream)) {
320 return ReadMapResult::Failed;
321 }
322 if (!localKey) {
323 if (legacySalt.size() != LocalEncryptSaltSize) {
324 LOG(("App Error: bad salt in map file, size: %1").arg(legacySalt.size()));
325 return ReadMapResult::Failed;
326 }
327 auto legacyPasscodeKey = CreateLegacyLocalKey(legacyPasscode, legacySalt);
328
329 EncryptedDescriptor keyData;
330 if (!DecryptLocal(keyData, legacyKeyEncrypted, legacyPasscodeKey)) {
331 LOG(("App Info: could not decrypt pass-protected key from map file, maybe bad password..."));
332 return ReadMapResult::IncorrectPasscode;
333 }
334 auto key = Serialize::read<MTP::AuthKey::Data>(keyData.stream);
335 if (keyData.stream.status() != QDataStream::Ok || !keyData.stream.atEnd()) {
336 LOG(("App Error: could not read pass-protected key from map file"));
337 return ReadMapResult::Failed;
338 }
339 localKey = std::make_shared<MTP::AuthKey>(key);
340 }
341
342 EncryptedDescriptor map;
343 if (!DecryptLocal(map, mapEncrypted, localKey)) {
344 LOG(("App Error: could not decrypt map."));
345 return ReadMapResult::Failed;
346 }
347 LOG(("App Info: reading encrypted map..."));
348
349 QByteArray selfSerialized;
350 base::flat_map<PeerId, FileKey> draftsMap;
351 base::flat_map<PeerId, FileKey> draftCursorsMap;
352 base::flat_map<PeerId, bool> draftsNotReadMap;
353 base::flat_map<PeerId, FileKey> botStoragesMap;
354 base::flat_map<PeerId, bool> botStoragesNotReadMap;
355 quint64 prefsKey = 0, locationsKey = 0, reportSpamStatusesKey = 0, trustedPeersKey = 0;
356 quint64 recentStickersKeyOld = 0;
357 quint64 installedStickersKey = 0, featuredStickersKey = 0, recentStickersKey = 0, favedStickersKey = 0, archivedStickersKey = 0;
358 quint64 installedMasksKey = 0, recentMasksKey = 0, archivedMasksKey = 0;
359 quint64 installedCustomEmojiKey = 0, featuredCustomEmojiKey = 0, archivedCustomEmojiKey = 0;
360 quint64 savedGifsKey = 0;
361 quint64 legacyBackgroundKeyDay = 0, legacyBackgroundKeyNight = 0;
362 quint64 userSettingsKey = 0, recentHashtagsAndBotsKey = 0, exportSettingsKey = 0;
363 quint64 searchSuggestionsKey = 0;

Callers

nothing calls this directly

Calls 13

CreateLegacyLocalKeyFunction · 0.85
DecryptLocalFunction · 0.85
DeserializePeerIdFunction · 0.85
ClearKeyFunction · 0.85
moveLegacyBackgroundFunction · 0.85
atEndMethod · 0.80
emplaceMethod · 0.80
setSessionFromStorageMethod · 0.80
CheckStreamStatusFunction · 0.70
ReadFileFunction · 0.50
IsNightModeFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected