defining more abstractions

This commit is contained in:
Kyle Spearrin 2018-01-25 14:26:09 -05:00
parent e5c1adedff
commit 11755e409a
9 changed files with 111 additions and 45 deletions

View File

@ -3,31 +3,31 @@ import { SymmetricCryptoKey } from '../models/domain/symmetricCryptoKey';
import { ProfileOrganizationResponse } from '../models/response/profileOrganizationResponse'; import { ProfileOrganizationResponse } from '../models/response/profileOrganizationResponse';
export interface CryptoService { export abstract class CryptoService {
setKey(key: SymmetricCryptoKey): Promise<any>; setKey: (key: SymmetricCryptoKey) => Promise<any>;
setKeyHash(keyHash: string): Promise<{}>; setKeyHash: (keyHash: string) => Promise<{}>;
setEncKey(encKey: string): Promise<{}>; setEncKey: (encKey: string) => Promise<{}>;
setEncPrivateKey(encPrivateKey: string): Promise<{}>; setEncPrivateKey: (encPrivateKey: string) => Promise<{}>;
setOrgKeys(orgs: ProfileOrganizationResponse[]): Promise<{}>; setOrgKeys: (orgs: ProfileOrganizationResponse[]) => Promise<{}>;
getKey(): Promise<SymmetricCryptoKey>; getKey: () => Promise<SymmetricCryptoKey>;
getKeyHash(): Promise<string>; getKeyHash: () => Promise<string>;
getEncKey(): Promise<SymmetricCryptoKey>; getEncKey: () => Promise<SymmetricCryptoKey>;
getPrivateKey(): Promise<ArrayBuffer>; getPrivateKey: () => Promise<ArrayBuffer>;
getOrgKeys(): Promise<Map<string, SymmetricCryptoKey>>; getOrgKeys: () => Promise<Map<string, SymmetricCryptoKey>>;
getOrgKey(orgId: string): Promise<SymmetricCryptoKey>; getOrgKey: (orgId: string) => Promise<SymmetricCryptoKey>;
clearKey(): Promise<any>; clearKey: () => Promise<any>;
clearKeyHash(): Promise<any>; clearKeyHash: () => Promise<any>;
clearEncKey(memoryOnly?: boolean): Promise<any>; clearEncKey: (memoryOnly?: boolean) => Promise<any>;
clearPrivateKey(memoryOnly?: boolean): Promise<any>; clearPrivateKey: (memoryOnly?: boolean) => Promise<any>;
clearOrgKeys(memoryOnly?: boolean): Promise<any>; clearOrgKeys: (memoryOnly?: boolean) => Promise<any>;
clearKeys(): Promise<any>; clearKeys: () => Promise<any>;
toggleKey(): Promise<any>; toggleKey: () => Promise<any>;
makeKey(password: string, salt: string): SymmetricCryptoKey; makeKey: (password: string, salt: string) => SymmetricCryptoKey;
hashPassword(password: string, key: SymmetricCryptoKey): Promise<string>; hashPassword: (password: string, key: SymmetricCryptoKey) => Promise<string>;
makeEncKey(key: SymmetricCryptoKey): Promise<CipherString>; makeEncKey: (key: SymmetricCryptoKey) => Promise<CipherString>;
encrypt(plainValue: string | Uint8Array, key?: SymmetricCryptoKey, plainValueEncoding?: string): Promise<CipherString>; encrypt: (plainValue: string | Uint8Array, key?: SymmetricCryptoKey, plainValueEncoding?: string) => Promise<CipherString>;
encryptToBytes(plainValue: ArrayBuffer, key?: SymmetricCryptoKey): Promise<ArrayBuffer>; encryptToBytes: (plainValue: ArrayBuffer, key?: SymmetricCryptoKey) => Promise<ArrayBuffer>;
decrypt(cipherString: CipherString, key?: SymmetricCryptoKey, outputEncoding?: string): Promise<string>; decrypt: (cipherString: CipherString, key?: SymmetricCryptoKey, outputEncoding?: string) => Promise<string>;
decryptFromBytes(encBuf: ArrayBuffer, key: SymmetricCryptoKey): Promise<ArrayBuffer>; decryptFromBytes: (encBuf: ArrayBuffer, key: SymmetricCryptoKey) => Promise<ArrayBuffer>;
rsaDecrypt(encValue: string): Promise<string>; rsaDecrypt: (encValue: string) => Promise<string>;
} }

View File

@ -0,0 +1,4 @@
export abstract class I18nService {
t: (id: string) => string;
translate: (id: string) => string;
}

View File

@ -6,6 +6,7 @@ export { CollectionService } from './collection.service';
export { CryptoService } from './crypto.service'; export { CryptoService } from './crypto.service';
export { EnvironmentService } from './environment.service'; export { EnvironmentService } from './environment.service';
export { FolderService } from './folder.service'; export { FolderService } from './folder.service';
export { I18nService } from './i18n.service';
export { LockService } from './lock.service'; export { LockService } from './lock.service';
export { MessagingService } from './messaging.service'; export { MessagingService } from './messaging.service';
export { PasswordGenerationService } from './passwordGeneration.service'; export { PasswordGenerationService } from './passwordGeneration.service';

View File

@ -1,15 +1,18 @@
import { DeviceType } from '../enums/deviceType'; import { DeviceType } from '../enums/deviceType';
export interface PlatformUtilsService { export abstract class PlatformUtilsService {
getDevice(): DeviceType; getDevice: () => DeviceType;
getDeviceString(): string; getDeviceString: () => string;
isFirefox(): boolean; isFirefox: () => boolean;
isChrome(): boolean; isChrome: () => boolean;
isEdge(): boolean; isEdge: () => boolean;
isOpera(): boolean; isOpera: () => boolean;
isVivaldi(): boolean; isVivaldi: () => boolean;
isSafari(): boolean; isSafari: () => boolean;
analyticsId(): string; analyticsId: () => string;
getDomain(uriString: string): string; getDomain: (uriString: string) => string;
isViewOpen(): boolean; isViewOpen: () => boolean;
launchUri: (uri: string) => void;
saveFile: (win: Window, blobData: any, blobOptions: any, fileName: string) => void;
alertError: (title: string, message: string) => void;
} }

View File

@ -1,4 +1,4 @@
export interface UtilsService { export abstract class UtilsService {
copyToClipboard(text: string, doc?: Document): void; copyToClipboard: (text: string, doc?: Document) => void;
getHostname(uriString: string): string; getHostname: (uriString: string) => string;
} }

View File

@ -48,4 +48,18 @@ export class CardView implements View {
} }
return this._subTitle; return this._subTitle;
} }
get expiration(): string {
if (!this.expMonth && !this.expYear) {
return null;
}
let exp = this.expMonth != null ? ('0' + this.expMonth).slice(-2) : '__';
exp += (' / ' + (this.expYear != null ? this.formatYear(this.expYear) : '____'));
return exp;
}
private formatYear(year: string): string {
return year.length === 2 ? '20' + year : year;
}
} }

View File

@ -6,10 +6,33 @@ import { Field } from '../domain/field';
export class FieldView implements View { export class FieldView implements View {
name: string; name: string;
vault: string;
type: FieldType; type: FieldType;
// tslint:disable
private _value: string;
private _maskedValue: string;
// tslint:enable
constructor(f: Field) { constructor(f: Field) {
this.type = f.type; this.type = f.type;
} }
get value(): string {
return this._value;
}
set value(value: string) {
this._value = value;
this._maskedValue = null;
}
get maskedValue(): string {
if (this._maskedValue == null && this.value != null) {
this._maskedValue = '';
for (let i = 0; i < this.value.length; i++) {
this._maskedValue += '•';
}
}
return this._maskedValue;
}
} }

View File

@ -62,4 +62,25 @@ export class IdentityView implements View {
return this._subTitle; return this._subTitle;
} }
get fullName(): string {
if (this.title != null || this.firstName != null || this.middleName != null || this.lastName != null) {
let name = '';
if (this.title != null) {
name += (this.title + ' ');
}
if (this.firstName != null) {
name += (this.firstName + ' ');
}
if (this.middleName != null) {
name += (this.middleName + ' ');
}
if (this.lastName != null) {
name += this.lastName;
}
return name.trim();
}
return null;
}
} }

View File

@ -7,7 +7,7 @@ import { EncryptedObject } from '../models/domain/encryptedObject';
import { SymmetricCryptoKey } from '../models/domain/symmetricCryptoKey'; import { SymmetricCryptoKey } from '../models/domain/symmetricCryptoKey';
import { ProfileOrganizationResponse } from '../models/response/profileOrganizationResponse'; import { ProfileOrganizationResponse } from '../models/response/profileOrganizationResponse';
import { CryptoService as CryptoServiceInterface } from '../abstractions/crypto.service'; import { CryptoService as CryptoServiceAbstraction } from '../abstractions/crypto.service';
import { StorageService as StorageServiceInterface } from '../abstractions/storage.service'; import { StorageService as StorageServiceInterface } from '../abstractions/storage.service';
import { ConstantsService } from './constants.service'; import { ConstantsService } from './constants.service';
@ -33,7 +33,7 @@ const AesAlgorithm = {
const Crypto = window.crypto; const Crypto = window.crypto;
const Subtle = Crypto.subtle; const Subtle = Crypto.subtle;
export class CryptoService implements CryptoServiceInterface { export class CryptoService implements CryptoServiceAbstraction {
private key: SymmetricCryptoKey; private key: SymmetricCryptoKey;
private encKey: SymmetricCryptoKey; private encKey: SymmetricCryptoKey;
private legacyEtmKey: SymmetricCryptoKey; private legacyEtmKey: SymmetricCryptoKey;