1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 08:13:42 +00:00

Refactor for barrels. Utils service to jslib

This commit is contained in:
Kyle Spearrin
2018-01-06 22:13:48 -05:00
parent c018f096b4
commit 03258e50f7
56 changed files with 270 additions and 433 deletions

View File

@@ -1,4 +1,4 @@
import { CipherType } from '@bitwarden/jslib';
import { Enums } from '@bitwarden/jslib';
import { AttachmentData } from './attachmentData';
import { CardData } from './cardData';
@@ -18,7 +18,7 @@ class CipherData {
organizationUseTotp: boolean;
favorite: boolean;
revisionDate: string;
type: CipherType;
type: Enums.CipherType;
sizeName: string;
name: string;
notes: string;
@@ -51,16 +51,16 @@ class CipherData {
this.notes = response.data.Notes;
switch (this.type) {
case CipherType.Login:
case Enums.CipherType.Login:
this.login = new LoginData(response.data);
break;
case CipherType.SecureNote:
case Enums.CipherType.SecureNote:
this.secureNote = new SecureNoteData(response.data);
break;
case CipherType.Card:
case Enums.CipherType.Card:
this.card = new CardData(response.data);
break;
case CipherType.Identity:
case Enums.CipherType.Identity:
this.identity = new IdentityData(response.data);
break;
default:

View File

@@ -1,7 +1,7 @@
import { FieldType } from '@bitwarden/jslib';
import { Enums } from '@bitwarden/jslib';
class FieldData {
type: FieldType;
type: Enums.FieldType;
name: string;
value: string;

View File

@@ -1,7 +1,7 @@
import { SecureNoteType } from '@bitwarden/jslib';
import { Enums } from '@bitwarden/jslib';
class SecureNoteData {
type: SecureNoteType;
type: Enums.SecureNoteType;
constructor(data: any) {
this.type = data.Type;

View File

@@ -1,4 +1,4 @@
import { CipherType } from '@bitwarden/jslib';
import { Enums } from '@bitwarden/jslib';
import { CipherData } from '../data/cipherData';
@@ -19,7 +19,7 @@ class Cipher extends Domain {
folderId: string;
name: CipherString;
notes: CipherString;
type: CipherType;
type: Enums.CipherType;
favorite: boolean;
organizationUseTotp: boolean;
edit: boolean;
@@ -54,16 +54,16 @@ class Cipher extends Domain {
this.localData = localData;
switch (this.type) {
case CipherType.Login:
case Enums.CipherType.Login:
this.login = new Login(obj.login, alreadyEncrypted);
break;
case CipherType.SecureNote:
case Enums.CipherType.SecureNote:
this.secureNote = new SecureNote(obj.secureNote, alreadyEncrypted);
break;
case CipherType.Card:
case Enums.CipherType.Card:
this.card = new Card(obj.card, alreadyEncrypted);
break;
case CipherType.Identity:
case Enums.CipherType.Identity:
this.identity = new Identity(obj.identity, alreadyEncrypted);
break;
default:
@@ -113,18 +113,18 @@ class Cipher extends Domain {
}, this.organizationId);
switch (this.type) {
case CipherType.Login:
case Enums.CipherType.Login:
model.login = await this.login.decrypt(this.organizationId);
model.subTitle = model.login.username;
if (model.login.uri) {
model.login.domain = BrowserPlatformUtilsService.getDomain(model.login.uri);
}
break;
case CipherType.SecureNote:
case Enums.CipherType.SecureNote:
model.secureNote = await this.secureNote.decrypt(this.organizationId);
model.subTitle = null;
break;
case CipherType.Card:
case Enums.CipherType.Card:
model.card = await this.card.decrypt(this.organizationId);
model.subTitle = model.card.brand;
if (model.card.number && model.card.number.length >= 4) {
@@ -134,7 +134,7 @@ class Cipher extends Domain {
model.subTitle += ('*' + model.card.number.substr(model.card.number.length - 4));
}
break;
case CipherType.Identity:
case Enums.CipherType.Identity:
model.identity = await this.identity.decrypt(this.organizationId);
model.subTitle = '';
if (model.identity.firstName) {

View File

@@ -1,19 +1,19 @@
import { EncryptionType } from '@bitwarden/jslib';
import { Enums } from '@bitwarden/jslib';
import ContainerService from '../../services/container.service';
class CipherString {
encryptedString?: string;
encryptionType?: EncryptionType;
encryptionType?: Enums.EncryptionType;
decryptedValue?: string;
cipherText?: string;
initializationVector?: string;
mac?: string;
constructor(encryptedStringOrType: string | EncryptionType, ct?: string, iv?: string, mac?: string) {
constructor(encryptedStringOrType: string | Enums.EncryptionType, ct?: string, iv?: string, mac?: string) {
if (ct != null) {
// ct and header
const encType = encryptedStringOrType as EncryptionType;
const encType = encryptedStringOrType as Enums.EncryptionType;
this.encryptedString = encType + '.' + ct;
// iv
@@ -51,13 +51,13 @@ class CipherString {
}
} else {
encPieces = this.encryptedString.split('|');
this.encryptionType = encPieces.length === 3 ? EncryptionType.AesCbc128_HmacSha256_B64 :
EncryptionType.AesCbc256_B64;
this.encryptionType = encPieces.length === 3 ? Enums.EncryptionType.AesCbc128_HmacSha256_B64 :
Enums.EncryptionType.AesCbc256_B64;
}
switch (this.encryptionType) {
case EncryptionType.AesCbc128_HmacSha256_B64:
case EncryptionType.AesCbc256_HmacSha256_B64:
case Enums.EncryptionType.AesCbc128_HmacSha256_B64:
case Enums.EncryptionType.AesCbc256_HmacSha256_B64:
if (encPieces.length !== 3) {
return;
}
@@ -66,7 +66,7 @@ class CipherString {
this.cipherText = encPieces[1];
this.mac = encPieces[2];
break;
case EncryptionType.AesCbc256_B64:
case Enums.EncryptionType.AesCbc256_B64:
if (encPieces.length !== 2) {
return;
}
@@ -74,8 +74,8 @@ class CipherString {
this.initializationVector = encPieces[0];
this.cipherText = encPieces[1];
break;
case EncryptionType.Rsa2048_OaepSha256_B64:
case EncryptionType.Rsa2048_OaepSha1_B64:
case Enums.EncryptionType.Rsa2048_OaepSha256_B64:
case Enums.EncryptionType.Rsa2048_OaepSha1_B64:
if (encPieces.length !== 1) {
return;
}

View File

@@ -1,4 +1,4 @@
import { FieldType } from '@bitwarden/jslib';
import { Enums } from '@bitwarden/jslib';
import { FieldData } from '../data/fieldData';
@@ -8,7 +8,7 @@ import Domain from './domain';
class Field extends Domain {
name: CipherString;
vault: CipherString;
type: FieldType;
type: Enums.FieldType;
constructor(obj?: FieldData, alreadyEncrypted: boolean = false) {
super();

View File

@@ -1,11 +1,11 @@
import { SecureNoteType } from '@bitwarden/jslib';
import { Enums } from '@bitwarden/jslib';
import { SecureNoteData } from '../data/secureNoteData';
import Domain from './domain';
class SecureNote extends Domain {
type: SecureNoteType;
type: Enums.SecureNoteType;
constructor(obj?: SecureNoteData, alreadyEncrypted: boolean = false) {
super();

View File

@@ -1,20 +1,18 @@
import * as forge from 'node-forge';
import { EncryptionType } from '@bitwarden/jslib';
import { Enums, Services } from '@bitwarden/jslib';
import SymmetricCryptoKeyBuffers from './symmetricCryptoKeyBuffers';
import UtilsService from '../../services/utils.service';
export default class SymmetricCryptoKey {
key: string;
keyB64: string;
encKey: string;
macKey: string;
encType: EncryptionType;
encType: Enums.EncryptionType;
keyBuf: SymmetricCryptoKeyBuffers;
constructor(keyBytes: string, b64KeyBytes?: boolean, encType?: EncryptionType) {
constructor(keyBytes: string, b64KeyBytes?: boolean, encType?: Enums.EncryptionType) {
if (b64KeyBytes) {
keyBytes = forge.util.decode64(keyBytes);
}
@@ -32,9 +30,9 @@ export default class SymmetricCryptoKey {
if (encType == null) {
if (bufferLength === 32) {
encType = EncryptionType.AesCbc256_B64;
encType = Enums.EncryptionType.AesCbc256_B64;
} else if (bufferLength === 64) {
encType = EncryptionType.AesCbc256_HmacSha256_B64;
encType = Enums.EncryptionType.AesCbc256_HmacSha256_B64;
} else {
throw new Error('Unable to determine encType.');
}
@@ -44,13 +42,13 @@ export default class SymmetricCryptoKey {
this.keyB64 = forge.util.encode64(keyBytes);
this.encType = encType;
if (encType === EncryptionType.AesCbc256_B64 && bufferLength === 32) {
if (encType === Enums.EncryptionType.AesCbc256_B64 && bufferLength === 32) {
this.encKey = keyBytes;
this.macKey = null;
} else if (encType === EncryptionType.AesCbc128_HmacSha256_B64 && bufferLength === 32) {
} else if (encType === Enums.EncryptionType.AesCbc128_HmacSha256_B64 && bufferLength === 32) {
this.encKey = buffer.getBytes(16); // first half
this.macKey = buffer.getBytes(16); // second half
} else if (encType === EncryptionType.AesCbc256_HmacSha256_B64 && bufferLength === 64) {
} else if (encType === Enums.EncryptionType.AesCbc256_HmacSha256_B64 && bufferLength === 64) {
this.encKey = buffer.getBytes(32); // first half
this.macKey = buffer.getBytes(32); // second half
} else {
@@ -63,7 +61,7 @@ export default class SymmetricCryptoKey {
return this.keyBuf;
}
const key = UtilsService.fromB64ToArray(this.keyB64);
const key = Services.UtilsService.fromB64ToArray(this.keyB64);
const keys = new SymmetricCryptoKeyBuffers(key.buffer);
if (this.macKey) {

View File

@@ -1,7 +1,7 @@
import { CipherType } from '@bitwarden/jslib';
import { Enums } from '@bitwarden/jslib';
class CipherRequest {
type: CipherType;
type: Enums.CipherType;
folderId: string;
organizationId: string;
name: string;
@@ -22,7 +22,7 @@ class CipherRequest {
this.favorite = cipher.favorite;
switch (this.type) {
case CipherType.Login:
case Enums.CipherType.Login:
this.login = {
uri: cipher.login.uri ? cipher.login.uri.encryptedString : null,
username: cipher.login.username ? cipher.login.username.encryptedString : null,
@@ -30,12 +30,12 @@ class CipherRequest {
totp: cipher.login.totp ? cipher.login.totp.encryptedString : null,
};
break;
case CipherType.SecureNote:
case Enums.CipherType.SecureNote:
this.secureNote = {
type: cipher.secureNote.type,
};
break;
case CipherType.Card:
case Enums.CipherType.Card:
this.card = {
cardholderName: cipher.card.cardholderName ? cipher.card.cardholderName.encryptedString : null,
brand: cipher.card.brand ? cipher.card.brand.encryptedString : null,
@@ -45,7 +45,7 @@ class CipherRequest {
code: cipher.card.code ? cipher.card.code.encryptedString : null,
};
break;
case CipherType.Identity:
case Enums.CipherType.Identity:
this.identity = {
title: cipher.identity.title ? cipher.identity.title.encryptedString : null,
firstName: cipher.identity.firstName ? cipher.identity.firstName.encryptedString : null,

View File

@@ -1,12 +1,12 @@
import { DeviceType, PlatformUtilsService } from '@bitwarden/jslib';
import { Abstractions, Enums } from '@bitwarden/jslib';
class DeviceRequest {
type: DeviceType;
type: Enums.DeviceType;
name: string;
identifier: string;
pushToken?: string;
constructor(appId: string, platformUtilsService: PlatformUtilsService) {
constructor(appId: string, platformUtilsService: Abstractions.PlatformUtilsService) {
this.type = platformUtilsService.getDevice();
this.name = platformUtilsService.getDeviceString();
this.identifier = appId;

View File

@@ -1,10 +1,10 @@
import { DeviceType } from '@bitwarden/jslib';
import { Enums } from '@bitwarden/jslib';
class DeviceResponse {
id: string;
name: number;
identifier: string;
type: DeviceType;
type: Enums.DeviceType;
creationDate: string;
constructor(response: any) {