mirror of
https://github.com/vector-im/element-desktop.git
synced 2024-09-09 22:05:10 +00:00
electron-main: Refactor out the randomArray method.
This commit is contained in:
parent
14415e2707
commit
50a4069893
1 changed files with 13 additions and 10 deletions
|
@ -262,6 +262,18 @@ const deleteContents = async (p) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async function randomArray(size) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
crypto.randomBytes(size, (err, buf) => {
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
} else {
|
||||||
|
resolve(buf.toString("base64").replace(/=+$/g, ''));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// handle uncaught errors otherwise it displays
|
// handle uncaught errors otherwise it displays
|
||||||
// stack traces in popup dialogs, which is terrible (which
|
// stack traces in popup dialogs, which is terrible (which
|
||||||
// it will do any time the auto update poke fails, and there's
|
// it will do any time the auto update poke fails, and there's
|
||||||
|
@ -439,16 +451,7 @@ ipcMain.on('ipcCall', async function(ev, payload) {
|
||||||
|
|
||||||
case 'createPickleKey':
|
case 'createPickleKey':
|
||||||
try {
|
try {
|
||||||
const randomArray = await new Promise((resolve, reject) => {
|
const pickleKey = await randomArray(32);
|
||||||
crypto.randomBytes(32, (err, buf) => {
|
|
||||||
if (err) {
|
|
||||||
reject(err);
|
|
||||||
} else {
|
|
||||||
resolve(buf);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
const pickleKey = randomArray.toString("base64").replace(/=+$/g, '');
|
|
||||||
await keytar.setPassword("element.io", `${args[0]}|${args[1]}`, pickleKey);
|
await keytar.setPassword("element.io", `${args[0]}|${args[1]}`, pickleKey);
|
||||||
ret = pickleKey;
|
ret = pickleKey;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Reference in a new issue