optional<InnerConfig> InnerConfig::deserialize(const Data &data) { Deserializer deserializer(&data); try { _checkHeader(&deserializer); string cipherName = deserializer.readString(); auto result = deserializer.readTailData(); deserializer.finished(); return InnerConfig {cipherName, std::move(result)}; } catch (const exception &e) { LOG(ERROR) << "Error deserializing inner configuration: " << e.what(); return none; // This can be caused by invalid input data and does not have to be a programming error. Don't throw exception. } }
optional<OuterConfig> OuterConfig::deserialize(const Data &data) { Deserializer deserializer(&data); try { #ifndef CRYFS_NO_COMPATIBILITY string header = deserializer.readString(); if (header == OLD_HEADER) { return _deserializeOldFormat(&deserializer); } else if (header == HEADER) { return _deserializeNewFormat(&deserializer); } else { throw std::runtime_error("Invalid header"); } #else _checkHeader(&deserializer); _deserializeNewFormat(&deserializer); #endif } catch (const exception &e) { LOG(ERROR, "Error deserializing outer configuration: {}", e.what()); return none; // This can be caused by invalid input data and does not have to be a programming error. Don't throw exception. } }