this.isEdge member

This commit is contained in:
Kyle Spearrin 2018-04-17 18:32:08 -04:00
parent da473ee1a6
commit 719c8aa70c
1 changed files with 4 additions and 2 deletions

View File

@ -8,15 +8,17 @@ import { UtilsService } from '../services/utils.service';
export class WebCryptoFunctionService implements CryptoFunctionService { export class WebCryptoFunctionService implements CryptoFunctionService {
private crypto: Crypto; private crypto: Crypto;
private subtle: SubtleCrypto; private subtle: SubtleCrypto;
private isEdge: boolean;
constructor(private win: Window, private platformUtilsService: PlatformUtilsService) { constructor(private win: Window, private platformUtilsService: PlatformUtilsService) {
this.crypto = win.crypto; this.crypto = win.crypto;
this.subtle = win.crypto.subtle; this.subtle = win.crypto.subtle;
this.isEdge = platformUtilsService.isEdge();
} }
async pbkdf2(password: string | ArrayBuffer, salt: string | ArrayBuffer, algorithm: 'sha256' | 'sha512', async pbkdf2(password: string | ArrayBuffer, salt: string | ArrayBuffer, algorithm: 'sha256' | 'sha512',
iterations: number, length: number): Promise<ArrayBuffer> { iterations: number, length: number): Promise<ArrayBuffer> {
if (this.platformUtilsService.isEdge()) { if (this.isEdge) {
const passwordBytes = this.toForgeBytes(password); const passwordBytes = this.toForgeBytes(password);
const saltBytes = this.toForgeBytes(salt); const saltBytes = this.toForgeBytes(salt);
const derivedKeyBytes = (forge as any).pbkdf2(passwordBytes, saltBytes, iterations, length / 8, algorithm); const derivedKeyBytes = (forge as any).pbkdf2(passwordBytes, saltBytes, iterations, length / 8, algorithm);
@ -46,7 +48,7 @@ export class WebCryptoFunctionService implements CryptoFunctionService {
} }
async hash(value: string | ArrayBuffer, algorithm: 'sha1' | 'sha256' | 'sha512'): Promise<ArrayBuffer> { async hash(value: string | ArrayBuffer, algorithm: 'sha1' | 'sha256' | 'sha512'): Promise<ArrayBuffer> {
if (this.platformUtilsService.isEdge()) { if (this.isEdge) {
let md: forge.md.MessageDigest; let md: forge.md.MessageDigest;
if (algorithm === 'sha1') { if (algorithm === 'sha1') {
md = forge.md.sha1.create(); md = forge.md.sha1.create();