use of org.whispersystems.libsignal.state.StorageProtos.SessionStructure in project Signal-Android by WhisperSystems.
the class TextSecureSessionStore method loadSession.
@Override
public SessionRecord loadSession(@NonNull SignalProtocolAddress address) {
synchronized (FILE_LOCK) {
try {
FileInputStream in = new FileInputStream(getSessionFile(address));
int versionMarker = readInteger(in);
if (versionMarker > CURRENT_VERSION) {
throw new AssertionError("Unknown version: " + versionMarker);
}
byte[] serialized = readBlob(in);
in.close();
if (versionMarker < PLAINTEXT_VERSION && masterSecret != null) {
serialized = new MasterCipher(masterSecret).decryptBytes(serialized);
} else if (versionMarker < PLAINTEXT_VERSION) {
throw new AssertionError("Session didn't get migrated: (" + versionMarker + "," + address + ")");
}
if (versionMarker == SINGLE_STATE_VERSION) {
SessionStructure sessionStructure = SessionStructure.parseFrom(serialized);
SessionState sessionState = new SessionState(sessionStructure);
return new SessionRecord(sessionState);
} else if (versionMarker >= ARCHIVE_STATES_VERSION) {
return new SessionRecord(serialized);
} else {
throw new AssertionError("Unknown version: " + versionMarker);
}
} catch (InvalidMessageException | IOException e) {
Log.w(TAG, "No existing session information found.");
return new SessionRecord();
}
}
}
Aggregations