From 84235ef58e245c6f2bdd45bf0a15422bc4b50280 Mon Sep 17 00:00:00 2001 From: lilia Date: Sun, 13 Mar 2016 14:15:16 -0700 Subject: [PATCH] Use forEach instead of loop // FREEBIE --- js/libtextsecure.js | 16 ++++++++-------- libtextsecure/api.js | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/js/libtextsecure.js b/js/libtextsecure.js index 150707e4..3daf5e9b 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -36605,16 +36605,16 @@ var TextSecureServer = (function() { throw new Error("Invalid response"); } res.identityKey = StringView.base64ToBytes(res.identityKey); - for (var i = 0; i < res.devices.length; i++) { - if ( !validateResponse(res.devices[i], {signedPreKey: 'object', preKey: 'object'}) || - !validateResponse(res.devices[i].signedPreKey, {publicKey: 'string', signature: 'string'}) || - !validateResponse(res.devices[i].preKey, {publicKey: 'string'})) { + res.devices.forEach(function(device) { + if ( !validateResponse(device, {signedPreKey: 'object', preKey: 'object'}) || + !validateResponse(device.signedPreKey, {publicKey: 'string', signature: 'string'}) || + !validateResponse(device.preKey, {publicKey: 'string'})) { throw new Error("Invalid response"); } - res.devices[i].signedPreKey.publicKey = StringView.base64ToBytes(res.devices[i].signedPreKey.publicKey); - res.devices[i].signedPreKey.signature = StringView.base64ToBytes(res.devices[i].signedPreKey.signature); - res.devices[i].preKey.publicKey = StringView.base64ToBytes(res.devices[i].preKey.publicKey); - } + device.signedPreKey.publicKey = StringView.base64ToBytes(device.signedPreKey.publicKey); + device.signedPreKey.signature = StringView.base64ToBytes(device.signedPreKey.signature); + device.preKey.publicKey = StringView.base64ToBytes(device.preKey.publicKey); + }); return res; }); }, diff --git a/libtextsecure/api.js b/libtextsecure/api.js index b6ad784c..32c727e1 100644 --- a/libtextsecure/api.js +++ b/libtextsecure/api.js @@ -285,16 +285,16 @@ var TextSecureServer = (function() { throw new Error("Invalid response"); } res.identityKey = StringView.base64ToBytes(res.identityKey); - for (var i = 0; i < res.devices.length; i++) { - if ( !validateResponse(res.devices[i], {signedPreKey: 'object', preKey: 'object'}) || - !validateResponse(res.devices[i].signedPreKey, {publicKey: 'string', signature: 'string'}) || - !validateResponse(res.devices[i].preKey, {publicKey: 'string'})) { + res.devices.forEach(function(device) { + if ( !validateResponse(device, {signedPreKey: 'object', preKey: 'object'}) || + !validateResponse(device.signedPreKey, {publicKey: 'string', signature: 'string'}) || + !validateResponse(device.preKey, {publicKey: 'string'})) { throw new Error("Invalid response"); } - res.devices[i].signedPreKey.publicKey = StringView.base64ToBytes(res.devices[i].signedPreKey.publicKey); - res.devices[i].signedPreKey.signature = StringView.base64ToBytes(res.devices[i].signedPreKey.signature); - res.devices[i].preKey.publicKey = StringView.base64ToBytes(res.devices[i].preKey.publicKey); - } + device.signedPreKey.publicKey = StringView.base64ToBytes(device.signedPreKey.publicKey); + device.signedPreKey.signature = StringView.base64ToBytes(device.signedPreKey.signature); + device.preKey.publicKey = StringView.base64ToBytes(device.preKey.publicKey); + }); return res; }); },