Skip to content
This repository has been archived by the owner on Jun 17, 2022. It is now read-only.

Commit

Permalink
formatting cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kspearrin committed Feb 28, 2018
1 parent e1041e9 commit e3b3e44
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
9 changes: 2 additions & 7 deletions src/services/crypto.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,13 +453,8 @@ export class CryptoService implements CryptoServiceAbstraction {
}

async sha1(password: string): Promise<string> {
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);
}

Expand Down
8 changes: 3 additions & 5 deletions src/services/utils.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e3b3e44

Please sign in to comment.