SessionKey.fromDb constructor

SessionKey.fromDb(
  1. StoredInboundGroupSession dbEntry,
  2. String key
)

Implementation

SessionKey.fromDb(StoredInboundGroupSession dbEntry, this.key)
  : content = Event.getMapFromPayload(dbEntry.content),
    indexes = Event.getMapFromPayload(
      dbEntry.indexes,
    ).catchMap((k, v) => MapEntry<String, String>(k, v)),
    allowedAtIndex = Event.getMapFromPayload(
      dbEntry.allowedAtIndex,
    ).catchMap((k, v) => MapEntry(k, Map<String, int>.from(v))),
    roomId = dbEntry.roomId,
    sessionId = dbEntry.sessionId,
    senderKey = dbEntry.senderKey {
  final parsedSenderClaimedKeys = Event.getMapFromPayload(
    dbEntry.senderClaimedKeys,
  ).catchMap((k, v) => MapEntry<String, String>(k, v));
  // we need to try...catch as the map used to be <String, int> and that will throw an error.
  senderClaimedKeys = (parsedSenderClaimedKeys.isNotEmpty)
      ? parsedSenderClaimedKeys
      : (content
                .tryGetMap<String, dynamic>('sender_claimed_keys')
                ?.catchMap((k, v) => MapEntry<String, String>(k, v)) ??
            (content['sender_claimed_ed25519_key'] is String
                ? <String, String>{
                    'ed25519': content['sender_claimed_ed25519_key'],
                  }
                : <String, String>{}));

  try {
    inboundGroupSession = vod.InboundGroupSession.fromPickleEncrypted(
      pickle: dbEntry.pickle,
      pickleKey: key.toPickleKey(),
    );
  } catch (e, s) {
    try {
      Logs().d('Unable to unpickle inboundGroupSession. Try LibOlm format.');
      inboundGroupSession = vod.InboundGroupSession.fromOlmPickleEncrypted(
        pickle: dbEntry.pickle,
        pickleKey: utf8.encode(key),
      );
    } catch (_) {
      Logs().e('[Vodozemac] Unable to unpickle inboundGroupSession', e, s);
      rethrow;
    }
  }
}