forked from mystiq/hydrogen-web
cleanup
This commit is contained in:
parent
45dc2162dc
commit
2ddb3fbf72
1 changed files with 7 additions and 18 deletions
|
@ -14,10 +14,15 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {SessionCache} from "./SessionCache";
|
|
||||||
import {IRoomKey, isBetterThan} from "./RoomKey";
|
import {IRoomKey, isBetterThan} from "./RoomKey";
|
||||||
import {BaseLRUCache} from "../../../../utils/LRUCache";
|
import {BaseLRUCache} from "../../../../utils/LRUCache";
|
||||||
|
|
||||||
|
|
||||||
|
export declare class OlmDecryptionResult {
|
||||||
|
readonly plaintext: string;
|
||||||
|
readonly message_index: number;
|
||||||
|
}
|
||||||
|
|
||||||
export declare class OlmInboundGroupSession {
|
export declare class OlmInboundGroupSession {
|
||||||
constructor();
|
constructor();
|
||||||
free(): void;
|
free(): void;
|
||||||
|
@ -25,34 +30,18 @@ export declare class OlmInboundGroupSession {
|
||||||
unpickle(key: string | Uint8Array, pickle: string);
|
unpickle(key: string | Uint8Array, pickle: string);
|
||||||
create(session_key: string): string;
|
create(session_key: string): string;
|
||||||
import_session(session_key: string): string;
|
import_session(session_key: string): string;
|
||||||
decrypt(message: string): object;
|
decrypt(message: string): OlmDecryptionResult;
|
||||||
session_id(): string;
|
session_id(): string;
|
||||||
first_known_index(): number;
|
first_known_index(): number;
|
||||||
export_session(message_index: number): string;
|
export_session(message_index: number): string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is what cache.get(...) should return
|
|
||||||
function findIndexBestForSession(ops: KeyOperation[], roomId: string, senderKey: string, sessionId: string): number {
|
|
||||||
return ops.reduce((bestIdx, op, i, arr) => {
|
|
||||||
const bestOp = bestIdx === -1 ? undefined : arr[bestIdx];
|
|
||||||
if (op.isForSameSession(roomId, senderKey, sessionId)) {
|
|
||||||
if (!bestOp || op.isBetter(bestOp)) {
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return bestIdx;
|
|
||||||
}, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Because Olm only has very limited memory available when compiled to wasm,
|
Because Olm only has very limited memory available when compiled to wasm,
|
||||||
we limit the amount of sessions held in memory.
|
we limit the amount of sessions held in memory.
|
||||||
*/
|
*/
|
||||||
export class KeyLoader extends BaseLRUCache<KeyOperation> {
|
export class KeyLoader extends BaseLRUCache<KeyOperation> {
|
||||||
|
|
||||||
private runningOps: Set<KeyOperation>;
|
|
||||||
private unusedOps: Set<KeyOperation>;
|
|
||||||
private pickleKey: string;
|
private pickleKey: string;
|
||||||
private olm: any;
|
private olm: any;
|
||||||
private resolveUnusedOperation?: () => void;
|
private resolveUnusedOperation?: () => void;
|
||||||
|
|
Loading…
Reference in a new issue