formatting cleanup

This commit is contained in:
Kyle Spearrin 2018-02-28 11:09:10 -05:00
parent e1041e9b5b
commit e3b3e444db
2 changed files with 5 additions and 12 deletions

View File

@ -453,13 +453,8 @@ export class CryptoService implements CryptoServiceAbstraction {
} }
async sha1(password: string): Promise<string> { async sha1(password: string): Promise<string> {
const hash = await Crypto.subtle.digest( const passwordArr = UtilsService.fromUtf8ToArray(password);
{ const hash = await Crypto.subtle.digest({ name: 'SHA-1' }, passwordArr);
name: 'SHA-1',
},
UtilsService.fromUtf8ToArray(password),
);
return UtilsService.fromBufferToHex(hash); return UtilsService.fromBufferToHex(hash);
} }

View File

@ -125,12 +125,10 @@ export class UtilsService implements UtilsServiceAbstraction {
return decodeURIComponent(escape(encodedString)); 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 { static fromBufferToHex(buffer: ArrayBuffer): string {
return Array.prototype.map.call( const bytes = new Uint8Array(buffer);
new Uint8Array(buffer), return Array.prototype.map.call(bytes, (x: number) => ('00' + x.toString(16)).slice(-2)).join('');
(x: number) => ('00' + x.toString(16)).slice(-2),
).join('');
} }
static getHostname(uriString: string): string { static getHostname(uriString: string): string {