drop.chapril.org-firefoxsend/frontend/src/utils.js

41 lines
819 B
JavaScript
Raw Normal View History

2017-06-02 05:59:27 +02:00
function ivToStr(iv) {
let hexStr = '';
2017-06-09 19:44:12 +02:00
for (const i in iv) {
2017-06-02 05:59:27 +02:00
if (iv[i] < 16) {
hexStr += '0' + iv[i].toString(16);
} else {
hexStr += iv[i].toString(16);
}
}
window.hexStr = hexStr;
return hexStr;
}
function strToIv(str) {
2017-06-09 19:44:12 +02:00
const iv = new Uint8Array(16);
2017-06-02 05:59:27 +02:00
for (let i = 0; i < str.length; i += 2) {
iv[i / 2] = parseInt(str.charAt(i) + str.charAt(i + 1), 16);
}
return iv;
}
2017-06-21 22:23:36 +02:00
function notify(str) {
if (!("Notification" in window)) {
return;
} else if (Notification.permission === 'granted') {
new Notification(str)
} else if (Notification.permission !== 'denied') {
Notification.requestPermission(function(permission) {
if (permission === 'granted')
new Notification(str);
})
}
}
2017-06-02 05:59:27 +02:00
module.exports = {
ivToStr,
2017-06-21 22:23:36 +02:00
strToIv,
notify
2017-06-02 05:59:27 +02:00
};