abstract password generation service

This commit is contained in:
Kyle Spearrin 2018-01-29 17:59:57 -05:00
parent e160b97497
commit 15f254879f
4 changed files with 15 additions and 18 deletions

View File

@ -1,12 +1,10 @@
import { PasswordHistory } from '../models/domain/passwordHistory'; import { PasswordHistory } from '../models/domain/passwordHistory';
export interface PasswordGenerationService { export abstract class PasswordGenerationService {
optionsCache: any; generatePassword: (options: any) => string;
history: PasswordHistory[]; getOptions: () => any;
generatePassword(options: any): string; saveOptions: (options: any) => Promise<any>;
getOptions(): any; getHistory: () => Promise<PasswordHistory[]>;
saveOptions(options: any): Promise<any>; addHistory: (password: string) => Promise<any>;
getHistory(): Promise<PasswordHistory[]>; clear: () => Promise<any>;
addHistory(password: string): Promise<any>;
clear(): Promise<any>;
} }

View File

@ -3,7 +3,7 @@ import { View } from './view';
import { Folder } from '../domain/folder'; import { Folder } from '../domain/folder';
export class FolderView implements View { export class FolderView implements View {
id: string; id: string = null;
name: string; name: string;
constructor(f?: Folder) { constructor(f?: Folder) {

View File

@ -67,10 +67,9 @@ export class FolderService implements FolderServiceAbstraction {
return this.decryptedFolderCache; return this.decryptedFolderCache;
} }
const decFolders: FolderView[] = [{ const noneFolder = new FolderView();
id: null, noneFolder.name = this.noneFolder();
name: this.noneFolder(), const decFolders: FolderView[] = [noneFolder];
}];
const key = await this.cryptoService.getKey(); const key = await this.cryptoService.getKey();
if (key == null) { if (key == null) {

View File

@ -5,7 +5,7 @@ import { UtilsService } from './utils.service';
import { CryptoService } from '../abstractions/crypto.service'; import { CryptoService } from '../abstractions/crypto.service';
import { import {
PasswordGenerationService as PasswordGenerationServiceInterface, PasswordGenerationService as PasswordGenerationServiceAbstraction,
} from '../abstractions/passwordGeneration.service'; } from '../abstractions/passwordGeneration.service';
import { StorageService } from '../abstractions/storage.service'; import { StorageService } from '../abstractions/storage.service';
@ -29,7 +29,7 @@ const Keys = {
const MaxPasswordsInHistory = 100; const MaxPasswordsInHistory = 100;
export class PasswordGenerationService implements PasswordGenerationServiceInterface { export class PasswordGenerationService implements PasswordGenerationServiceAbstraction {
static generatePassword(options: any): string { static generatePassword(options: any): string {
// overload defaults with given options // overload defaults with given options
const o = Object.assign({}, DefaultOptions, options); const o = Object.assign({}, DefaultOptions, options);
@ -147,8 +147,8 @@ export class PasswordGenerationService implements PasswordGenerationServiceInter
return password; return password;
} }
optionsCache: any; private optionsCache: any;
history: PasswordHistory[] = []; private history: PasswordHistory[] = [];
constructor(private cryptoService: CryptoService, private storageService: StorageService) { constructor(private cryptoService: CryptoService, private storageService: StorageService) {
} }