1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-12-01 04:43:29 +03:00

Much tedious linting

This commit is contained in:
David Baker
2017-12-06 22:36:24 +00:00
parent 0362e61f36
commit 0dd8ffa3a0

View File

@@ -774,17 +774,14 @@ OlmDevice.prototype.getOutboundGroupSessionKey = function(sessionId) {
* @param {function(Olm.InboundGroupSession, InboundGroupSessionData): T} func
* function to call.
*
* @return {null} the sessionId is unknown
*
* @return {T} result of func
*
* @private
* @template {T}
*/
OlmDevice.prototype._getInboundGroupSession = function(
roomId, senderKey, sessionId, txn, func,
) {
this._cryptoStore.getEndToEndInboundGroupSession(senderKey, sessionId, txn, (sessionData) => {
this._cryptoStore.getEndToEndInboundGroupSession(
senderKey, sessionId, txn, (sessionData) => {
if (sessionData === null) {
func(null);
return;
@@ -794,8 +791,8 @@ OlmDevice.prototype._getInboundGroupSession = function(
// the HS pretending a message was targeting a different room.
if (roomId !== sessionData.room_id) {
throw new Error(
"Mismatched room_id for inbound group session (expected " + sessionData.room_id +
", was " + roomId + ")",
"Mismatched room_id for inbound group session (expected " +
sessionData.room_id + ", was " + roomId + ")",
);
}
@@ -806,7 +803,8 @@ OlmDevice.prototype._getInboundGroupSession = function(
} finally {
session.free();
}
});
},
);
};
/**
@@ -827,12 +825,16 @@ OlmDevice.prototype.addInboundGroupSession = async function(
sessionId, sessionKey, keysClaimed,
exportFormat,
) {
await this._cryptoStore.doTxn('readwrite', [IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS], (txn) => {
await this._cryptoStore.doTxn(
'readwrite', [IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS], (txn) => {
/* if we already have this session, consider updating it */
this._getInboundGroupSession(
roomId, senderKey, sessionId, txn, (existingSession, existingSessionData) => {
roomId, senderKey, sessionId, txn,
(existingSession, existingSessionData) => {
if (existingSession) {
console.log("Update for megolm session " + senderKey + "/" + sessionId);
console.log(
"Update for megolm session " + senderKey + "/" + sessionId,
);
// for now we just ignore updates. TODO: implement something here
return;
}
@@ -847,7 +849,8 @@ OlmDevice.prototype.addInboundGroupSession = async function(
}
if (sessionId != session.session_id()) {
throw new Error(
"Mismatched group session ID from senderKey: " + senderKey,
"Mismatched group session ID from senderKey: " +
senderKey,
);
}
@@ -866,7 +869,8 @@ OlmDevice.prototype.addInboundGroupSession = async function(
}
},
);
});
},
);
};
/**
@@ -890,8 +894,10 @@ OlmDevice.prototype.decryptGroupMessage = async function(
) {
let result;
await this._cryptoStore.doTxn('readwrite', [IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS], (txn) => {
this._getInboundGroupSession(roomId, senderKey, sessionId, txn, (session, sessionData) => {
await this._cryptoStore.doTxn(
'readwrite', [IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS], (txn) => {
this._getInboundGroupSession(
roomId, senderKey, sessionId, txn, (session, sessionData) => {
if (session === null) {
result = null;
return;
@@ -907,10 +913,17 @@ OlmDevice.prototype.decryptGroupMessage = async function(
// If the event ID and timestamp are specified, and the match the event ID
// and timestamp from the last time we used this message index, then we
// don't consider it a replay attack.
const messageIndexKey = senderKey + "|" + sessionId + "|" + res.message_index;
const messageIndexKey = (
senderKey + "|" + sessionId + "|" + res.message_index
);
if (messageIndexKey in this._inboundGroupSessionMessageIndexes) {
const msgInfo = this._inboundGroupSessionMessageIndexes[messageIndexKey];
if (msgInfo.id !== eventId || msgInfo.timestamp !== timestamp) {
const msgInfo = (
this._inboundGroupSessionMessageIndexes[messageIndexKey]
);
if (
msgInfo.id !== eventId ||
msgInfo.timestamp !== timestamp
) {
throw new Error(
"Duplicate message index, possible replay attack: " +
messageIndexKey,
@@ -931,10 +944,14 @@ OlmDevice.prototype.decryptGroupMessage = async function(
result: plaintext,
keysClaimed: sessionData.keysClaimed || {},
senderKey: senderKey,
forwardingCurve25519KeyChain: sessionData.forwardingCurve25519KeyChain || [],
forwardingCurve25519KeyChain: (
sessionData.forwardingCurve25519KeyChain || []
),
};
});
});
},
);
},
);
return result;
};
@@ -950,7 +967,8 @@ OlmDevice.prototype.decryptGroupMessage = async function(
*/
OlmDevice.prototype.hasInboundSessionKeys = async function(roomId, senderKey, sessionId) {
let result;
await this._cryptoStore.doTxn('readonly', [IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS], (txn) => {
await this._cryptoStore.doTxn(
'readonly', [IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS], (txn) => {
this._cryptoStore.getEndToEndInboundGroupSession(
senderKey, sessionId, txn, (sessionData) => {
if (sessionData === null) {
@@ -961,7 +979,8 @@ OlmDevice.prototype.hasInboundSessionKeys = async function(roomId, senderKey, se
if (roomId !== sessionData.room_id) {
console.warn(
`requested keys for inbound group session ${senderKey}|` +
`${sessionId}, with incorrect room_id (expected ${sessionData.room_id}, ` +
`${sessionId}, with incorrect room_id ` +
`(expected ${sessionData.room_id}, ` +
`was ${roomId})`,
);
result = false;
@@ -970,7 +989,8 @@ OlmDevice.prototype.hasInboundSessionKeys = async function(roomId, senderKey, se
}
},
);
});
},
);
return result;
};
@@ -993,7 +1013,8 @@ OlmDevice.prototype.getInboundGroupSessionKey = async function(
roomId, senderKey, sessionId,
) {
let result;
await this._cryptoStore.doTxn('readonly', [IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS], (txn) => {
await this._cryptoStore.doTxn(
'readonly', [IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS], (txn) => {
this._getInboundGroupSession(
roomId, senderKey, sessionId, txn, (session, sessionData) => {
if (session === null) {
@@ -1014,7 +1035,8 @@ OlmDevice.prototype.getInboundGroupSessionKey = async function(
};
},
);
});
},
);
return result;
};
@@ -1028,12 +1050,14 @@ OlmDevice.prototype.getInboundGroupSessionKey = async function(
*/
OlmDevice.prototype.exportInboundGroupSession = async function(senderKey, sessionId) {
let result;
await this._cryptoStore.doTxn('readonly', [IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS], (txn) => {
await this._cryptoStore.doTxn(
'readonly', [IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS], (txn) => {
this._getInboundGroupSession(
roomId, senderKey, sessionId, txn, (session, sessionData) => {
if (session === null) {
throw new Error(
"Unknown inbound group session [" + senderKey + "," + sessionId + "]"
"Unknown inbound group session [" +
senderKey + "," + sessionId + "]",
);
const messageIndex = session.first_known_index();
@@ -1050,7 +1074,8 @@ OlmDevice.prototype.exportInboundGroupSession = async function(senderKey, sessio
}
},
);
});
},
);
return result;
};