From 15f254879fe60253d6c76cc73a35aea3c4225546 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 29 Jan 2018 17:59:57 -0500 Subject: [PATCH] abstract password generation service --- src/abstractions/passwordGeneration.service.ts | 16 +++++++--------- src/models/view/folderView.ts | 2 +- src/services/folder.service.ts | 7 +++---- src/services/passwordGeneration.service.ts | 8 ++++---- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/abstractions/passwordGeneration.service.ts b/src/abstractions/passwordGeneration.service.ts index 1531eb176b..a8967db281 100644 --- a/src/abstractions/passwordGeneration.service.ts +++ b/src/abstractions/passwordGeneration.service.ts @@ -1,12 +1,10 @@ import { PasswordHistory } from '../models/domain/passwordHistory'; -export interface PasswordGenerationService { - optionsCache: any; - history: PasswordHistory[]; - generatePassword(options: any): string; - getOptions(): any; - saveOptions(options: any): Promise; - getHistory(): Promise; - addHistory(password: string): Promise; - clear(): Promise; +export abstract class PasswordGenerationService { + generatePassword: (options: any) => string; + getOptions: () => any; + saveOptions: (options: any) => Promise; + getHistory: () => Promise; + addHistory: (password: string) => Promise; + clear: () => Promise; } diff --git a/src/models/view/folderView.ts b/src/models/view/folderView.ts index fc4bb219b3..ebe8ea157a 100644 --- a/src/models/view/folderView.ts +++ b/src/models/view/folderView.ts @@ -3,7 +3,7 @@ import { View } from './view'; import { Folder } from '../domain/folder'; export class FolderView implements View { - id: string; + id: string = null; name: string; constructor(f?: Folder) { diff --git a/src/services/folder.service.ts b/src/services/folder.service.ts index acc9b39c17..81c03a15f5 100644 --- a/src/services/folder.service.ts +++ b/src/services/folder.service.ts @@ -67,10 +67,9 @@ export class FolderService implements FolderServiceAbstraction { return this.decryptedFolderCache; } - const decFolders: FolderView[] = [{ - id: null, - name: this.noneFolder(), - }]; + const noneFolder = new FolderView(); + noneFolder.name = this.noneFolder(); + const decFolders: FolderView[] = [noneFolder]; const key = await this.cryptoService.getKey(); if (key == null) { diff --git a/src/services/passwordGeneration.service.ts b/src/services/passwordGeneration.service.ts index 403bb104e2..33c3eea29a 100644 --- a/src/services/passwordGeneration.service.ts +++ b/src/services/passwordGeneration.service.ts @@ -5,7 +5,7 @@ import { UtilsService } from './utils.service'; import { CryptoService } from '../abstractions/crypto.service'; import { - PasswordGenerationService as PasswordGenerationServiceInterface, + PasswordGenerationService as PasswordGenerationServiceAbstraction, } from '../abstractions/passwordGeneration.service'; import { StorageService } from '../abstractions/storage.service'; @@ -29,7 +29,7 @@ const Keys = { const MaxPasswordsInHistory = 100; -export class PasswordGenerationService implements PasswordGenerationServiceInterface { +export class PasswordGenerationService implements PasswordGenerationServiceAbstraction { static generatePassword(options: any): string { // overload defaults with given options const o = Object.assign({}, DefaultOptions, options); @@ -147,8 +147,8 @@ export class PasswordGenerationService implements PasswordGenerationServiceInter return password; } - optionsCache: any; - history: PasswordHistory[] = []; + private optionsCache: any; + private history: PasswordHistory[] = []; constructor(private cryptoService: CryptoService, private storageService: StorageService) { }