mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 01:33:33 +00:00
support for encrypted json export (#216)
* support for encrypted json export * adjust filename prefix for encrypted formats * flip if logic * remove format param from encrypted export * encryptedFormat getter
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { CardView } from '../view/cardView';
|
||||
|
||||
import { Card as CardDomain } from '../domain/card';
|
||||
|
||||
export class Card {
|
||||
static template(): Card {
|
||||
const req = new Card();
|
||||
@@ -29,16 +31,25 @@ export class Card {
|
||||
expYear: string;
|
||||
code: string;
|
||||
|
||||
constructor(o?: CardView) {
|
||||
constructor(o?: CardView | CardDomain) {
|
||||
if (o == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.cardholderName = o.cardholderName;
|
||||
this.brand = o.brand;
|
||||
this.number = o.number;
|
||||
this.expMonth = o.expMonth;
|
||||
this.expYear = o.expYear;
|
||||
this.code = o.code;
|
||||
if (o instanceof CardView) {
|
||||
this.cardholderName = o.cardholderName;
|
||||
this.brand = o.brand;
|
||||
this.number = o.number;
|
||||
this.expMonth = o.expMonth;
|
||||
this.expYear = o.expYear;
|
||||
this.code = o.code;
|
||||
} else {
|
||||
this.cardholderName = o.cardholderName?.encryptedString;
|
||||
this.brand = o.brand?.encryptedString;
|
||||
this.number = o.number?.encryptedString;
|
||||
this.expMonth = o.expMonth?.encryptedString;
|
||||
this.expYear = o.expYear?.encryptedString;
|
||||
this.code = o.code?.encryptedString;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ import { CipherType } from '../../enums/cipherType';
|
||||
|
||||
import { CipherView } from '../view/cipherView';
|
||||
|
||||
import { Cipher as CipherDomain } from '../domain/cipher';
|
||||
|
||||
import { Card } from './card';
|
||||
import { Field } from './field';
|
||||
import { Identity } from './identity';
|
||||
@@ -70,16 +72,27 @@ export class Cipher {
|
||||
identity: Identity;
|
||||
|
||||
// Use build method instead of ctor so that we can control order of JSON stringify for pretty print
|
||||
build(o: CipherView) {
|
||||
build(o: CipherView | CipherDomain) {
|
||||
this.organizationId = o.organizationId;
|
||||
this.folderId = o.folderId;
|
||||
this.type = o.type;
|
||||
this.name = o.name;
|
||||
this.notes = o.notes;
|
||||
|
||||
if (o instanceof CipherView) {
|
||||
this.name = o.name;
|
||||
this.notes = o.notes;
|
||||
} else {
|
||||
this.name = o.name?.encryptedString;
|
||||
this.notes = o.notes?.encryptedString;
|
||||
}
|
||||
|
||||
this.favorite = o.favorite;
|
||||
|
||||
if (o.fields != null) {
|
||||
this.fields = o.fields.map((f) => new Field(f));
|
||||
if (o instanceof CipherView) {
|
||||
this.fields = o.fields.map((f) => new Field(f));
|
||||
} else {
|
||||
this.fields = o.fields.map((f) => new Field(f));
|
||||
}
|
||||
}
|
||||
|
||||
switch (o.type) {
|
||||
|
||||
@@ -2,12 +2,14 @@ import { Cipher } from './cipher';
|
||||
|
||||
import { CipherView } from '../view/cipherView';
|
||||
|
||||
import { Cipher as CipherDomain } from '../domain/cipher';
|
||||
|
||||
export class CipherWithIds extends Cipher {
|
||||
id: string;
|
||||
collectionIds: string[];
|
||||
|
||||
// Use build method instead of ctor so that we can control order of JSON stringify for pretty print
|
||||
build(o: CipherView) {
|
||||
build(o: CipherView | CipherDomain) {
|
||||
this.id = o.id;
|
||||
super.build(o);
|
||||
this.collectionIds = o.collectionIds;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { CollectionView } from '../view/collectionView';
|
||||
|
||||
import { Collection as CollectionDomain } from '../domain/collection';
|
||||
|
||||
export class Collection {
|
||||
static template(): Collection {
|
||||
const req = new Collection();
|
||||
@@ -23,9 +25,13 @@ export class Collection {
|
||||
externalId: string;
|
||||
|
||||
// Use build method instead of ctor so that we can control order of JSON stringify for pretty print
|
||||
build(o: CollectionView) {
|
||||
build(o: CollectionView | CollectionDomain) {
|
||||
this.organizationId = o.organizationId;
|
||||
this.name = o.name;
|
||||
if (o instanceof CollectionView) {
|
||||
this.name = o.name;
|
||||
} else {
|
||||
this.name = o.name?.encryptedString;
|
||||
}
|
||||
this.externalId = o.externalId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,13 @@ import { Collection } from './collection';
|
||||
|
||||
import { CollectionView } from '../view/collectionView';
|
||||
|
||||
import { Collection as CollectionDomain } from '../domain/collection';
|
||||
|
||||
export class CollectionWithId extends Collection {
|
||||
id: string;
|
||||
|
||||
// Use build method instead of ctor so that we can control order of JSON stringify for pretty print
|
||||
build(o: CollectionView) {
|
||||
build(o: CollectionView | CollectionDomain) {
|
||||
this.id = o.id;
|
||||
super.build(o);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ import { FieldType } from '../../enums/fieldType';
|
||||
|
||||
import { FieldView } from '../view/fieldView';
|
||||
|
||||
import { Field as FieldDomain } from '../domain/field';
|
||||
|
||||
export class Field {
|
||||
static template(): Field {
|
||||
const req = new Field();
|
||||
@@ -22,13 +24,18 @@ export class Field {
|
||||
value: string;
|
||||
type: FieldType;
|
||||
|
||||
constructor(o?: FieldView) {
|
||||
constructor(o?: FieldView | FieldDomain) {
|
||||
if (o == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.name = o.name;
|
||||
this.value = o.value;
|
||||
if (o instanceof FieldView) {
|
||||
this.name = o.name;
|
||||
this.value = o.value;
|
||||
} else {
|
||||
this.name = o.name?.encryptedString;
|
||||
this.value = o.value?.encryptedString;
|
||||
}
|
||||
this.type = o.type;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { FolderView } from '../view/folderView';
|
||||
|
||||
import { Folder as FolderDomain } from '../domain/folder';
|
||||
|
||||
export class Folder {
|
||||
static template(): Folder {
|
||||
const req = new Folder();
|
||||
@@ -15,7 +17,11 @@ export class Folder {
|
||||
name: string;
|
||||
|
||||
// Use build method instead of ctor so that we can control order of JSON stringify for pretty print
|
||||
build(o: FolderView) {
|
||||
this.name = o.name;
|
||||
build(o: FolderView | FolderDomain) {
|
||||
if (o instanceof FolderView) {
|
||||
this.name = o.name;
|
||||
} else {
|
||||
this.name = o.name?.encryptedString;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,13 @@ import { Folder } from './folder';
|
||||
|
||||
import { FolderView } from '../view/folderView';
|
||||
|
||||
import { Folder as FolderDomain } from '../domain/folder';
|
||||
|
||||
export class FolderWithId extends Folder {
|
||||
id: string;
|
||||
|
||||
// Use build method instead of ctor so that we can control order of JSON stringify for pretty print
|
||||
build(o: FolderView) {
|
||||
build(o: FolderView | FolderDomain) {
|
||||
this.id = o.id;
|
||||
super.build(o);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { IdentityView } from '../view/identityView';
|
||||
|
||||
import { Identity as IdentityDomain } from '../domain/identity';
|
||||
|
||||
export class Identity {
|
||||
static template(): Identity {
|
||||
const req = new Identity();
|
||||
@@ -65,28 +67,49 @@ export class Identity {
|
||||
passportNumber: string;
|
||||
licenseNumber: string;
|
||||
|
||||
constructor(o?: IdentityView) {
|
||||
constructor(o?: IdentityView | IdentityDomain) {
|
||||
if (o == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.title = o.title;
|
||||
this.firstName = o.firstName;
|
||||
this.middleName = o.middleName;
|
||||
this.lastName = o.lastName;
|
||||
this.address1 = o.address1;
|
||||
this.address2 = o.address2;
|
||||
this.address3 = o.address3;
|
||||
this.city = o.city;
|
||||
this.state = o.state;
|
||||
this.postalCode = o.postalCode;
|
||||
this.country = o.country;
|
||||
this.company = o.company;
|
||||
this.email = o.email;
|
||||
this.phone = o.phone;
|
||||
this.ssn = o.ssn;
|
||||
this.username = o.username;
|
||||
this.passportNumber = o.passportNumber;
|
||||
this.licenseNumber = o.licenseNumber;
|
||||
if (o instanceof IdentityView) {
|
||||
this.title = o.title;
|
||||
this.firstName = o.firstName;
|
||||
this.middleName = o.middleName;
|
||||
this.lastName = o.lastName;
|
||||
this.address1 = o.address1;
|
||||
this.address2 = o.address2;
|
||||
this.address3 = o.address3;
|
||||
this.city = o.city;
|
||||
this.state = o.state;
|
||||
this.postalCode = o.postalCode;
|
||||
this.country = o.country;
|
||||
this.company = o.company;
|
||||
this.email = o.email;
|
||||
this.phone = o.phone;
|
||||
this.ssn = o.ssn;
|
||||
this.username = o.username;
|
||||
this.passportNumber = o.passportNumber;
|
||||
this.licenseNumber = o.licenseNumber;
|
||||
} else {
|
||||
this.title = o.title?.encryptedString;
|
||||
this.firstName = o.firstName?.encryptedString;
|
||||
this.middleName = o.middleName?.encryptedString;
|
||||
this.lastName = o.lastName?.encryptedString;
|
||||
this.address1 = o.address1?.encryptedString;
|
||||
this.address2 = o.address2?.encryptedString;
|
||||
this.address3 = o.address3?.encryptedString;
|
||||
this.city = o.city?.encryptedString;
|
||||
this.state = o.state?.encryptedString;
|
||||
this.postalCode = o.postalCode?.encryptedString;
|
||||
this.country = o.country?.encryptedString;
|
||||
this.company = o.company?.encryptedString;
|
||||
this.email = o.email?.encryptedString;
|
||||
this.phone = o.phone?.encryptedString;
|
||||
this.ssn = o.ssn?.encryptedString;
|
||||
this.username = o.username?.encryptedString;
|
||||
this.passportNumber = o.passportNumber?.encryptedString;
|
||||
this.licenseNumber = o.licenseNumber?.encryptedString;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ import { LoginUri } from './loginUri';
|
||||
|
||||
import { LoginView } from '../view/loginView';
|
||||
|
||||
import { Login as LoginDomain } from '../domain/login';
|
||||
|
||||
export class Login {
|
||||
static template(): Login {
|
||||
const req = new Login();
|
||||
@@ -27,17 +29,27 @@ export class Login {
|
||||
password: string;
|
||||
totp: string;
|
||||
|
||||
constructor(o?: LoginView) {
|
||||
constructor(o?: LoginView | LoginDomain) {
|
||||
if (o == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (o.uris != null) {
|
||||
this.uris = o.uris.map((u) => new LoginUri(u));
|
||||
if (o instanceof LoginView) {
|
||||
this.uris = o.uris.map((u) => new LoginUri(u));
|
||||
} else {
|
||||
this.uris = o.uris.map((u) => new LoginUri(u));
|
||||
}
|
||||
}
|
||||
|
||||
this.username = o.username;
|
||||
this.password = o.password;
|
||||
this.totp = o.totp;
|
||||
if (o instanceof LoginView) {
|
||||
this.username = o.username;
|
||||
this.password = o.password;
|
||||
this.totp = o.totp;
|
||||
} else {
|
||||
this.username = o.username?.encryptedString;
|
||||
this.password = o.password?.encryptedString;
|
||||
this.totp = o.totp?.encryptedString;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ import { UriMatchType } from '../../enums/uriMatchType';
|
||||
|
||||
import { LoginUriView } from '../view/loginUriView';
|
||||
|
||||
import { LoginUri as LoginUriDomain } from '../domain/loginUri';
|
||||
|
||||
export class LoginUri {
|
||||
static template(): LoginUri {
|
||||
const req = new LoginUri();
|
||||
@@ -19,12 +21,16 @@ export class LoginUri {
|
||||
uri: string;
|
||||
match: UriMatchType = null;
|
||||
|
||||
constructor(o?: LoginUriView) {
|
||||
constructor(o?: LoginUriView | LoginUriDomain) {
|
||||
if (o == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.uri = o.uri;
|
||||
if (o instanceof LoginUriView) {
|
||||
this.uri = o.uri;
|
||||
} else {
|
||||
this.uri = o.uri?.encryptedString;
|
||||
}
|
||||
this.match = o.match;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ import { SecureNoteType } from '../../enums/secureNoteType';
|
||||
|
||||
import { SecureNoteView } from '../view/secureNoteView';
|
||||
|
||||
import { SecureNote as SecureNoteDomain } from '../domain/secureNote';
|
||||
|
||||
export class SecureNote {
|
||||
static template(): SecureNote {
|
||||
const req = new SecureNote();
|
||||
@@ -16,7 +18,7 @@ export class SecureNote {
|
||||
|
||||
type: SecureNoteType;
|
||||
|
||||
constructor(o?: SecureNoteView) {
|
||||
constructor(o?: SecureNoteView | SecureNoteDomain) {
|
||||
if (o == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user