From e3b3e444dbff7e4541fa5367ee26bc7ed4d73b26 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 28 Feb 2018 11:09:10 -0500 Subject: [PATCH] formatting cleanup --- src/services/crypto.service.ts | 9 ++------- src/services/utils.service.ts | 8 +++----- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/services/crypto.service.ts b/src/services/crypto.service.ts index 93dbcd3b5c..243afb66aa 100644 --- a/src/services/crypto.service.ts +++ b/src/services/crypto.service.ts @@ -453,13 +453,8 @@ export class CryptoService implements CryptoServiceAbstraction { } async sha1(password: string): Promise { - const hash = await Crypto.subtle.digest( - { - name: 'SHA-1', - }, - UtilsService.fromUtf8ToArray(password), - ); - + const passwordArr = UtilsService.fromUtf8ToArray(password); + const hash = await Crypto.subtle.digest({ name: 'SHA-1' }, passwordArr); return UtilsService.fromBufferToHex(hash); } diff --git a/src/services/utils.service.ts b/src/services/utils.service.ts index a1e900e761..7f692ae191 100644 --- a/src/services/utils.service.ts +++ b/src/services/utils.service.ts @@ -125,12 +125,10 @@ export class UtilsService implements UtilsServiceAbstraction { return decodeURIComponent(escape(encodedString)); } - // Source: Frxstrem, https://stackoverflow.com/questions/40031688/javascript-arraybuffer-to-hex + // ref: https://stackoverflow.com/a/40031979/1090359 static fromBufferToHex(buffer: ArrayBuffer): string { - return Array.prototype.map.call( - new Uint8Array(buffer), - (x: number) => ('00' + x.toString(16)).slice(-2), - ).join(''); + const bytes = new Uint8Array(buffer); + return Array.prototype.map.call(bytes, (x: number) => ('00' + x.toString(16)).slice(-2)).join(''); } static getHostname(uriString: string): string {