1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-19 01:33:33 +00:00

[PM-328] Move Send to Tools (#5104)

* Move send in libs/common

* Move send in libs/angular

* Move send in browser

* Move send in cli

* Move send in desktop

* Move send in web
This commit is contained in:
Daniel James Smith
2023-03-29 16:23:37 +02:00
committed by GitHub
parent e645688f8a
commit e238ea20a9
105 changed files with 328 additions and 321 deletions

View File

@@ -13,14 +13,14 @@ import { KdfType } from "../../enums/kdfType";
import { UriMatchType } from "../../enums/uriMatchType";
import { Utils } from "../../misc/utils";
import { GeneratedPasswordHistory } from "../../tools/generator/password";
import { SendData } from "../../tools/send/models/data/send.data";
import { SendView } from "../../tools/send/models/view/send.view";
import { DeepJsonify } from "../../types/deep-jsonify";
import { CipherData } from "../../vault/models/data/cipher.data";
import { FolderData } from "../../vault/models/data/folder.data";
import { CipherView } from "../../vault/models/view/cipher.view";
import { EventData } from "../data/event.data";
import { SendData } from "../data/send.data";
import { ServerConfigData } from "../data/server-config.data";
import { SendView } from "../view/send.view";
import { EncString } from "./enc-string";
import { SymmetricCryptoKey } from "./symmetric-crypto-key";

View File

@@ -1,77 +0,0 @@
import { SendType } from "../../enums/sendType";
import { SendAccessResponse } from "../response/send-access.response";
import { SendAccessView } from "../view/send-access.view";
import Domain from "./domain-base";
import { EncString } from "./enc-string";
import { SendFile } from "./send-file";
import { SendText } from "./send-text";
import { SymmetricCryptoKey } from "./symmetric-crypto-key";
export class SendAccess extends Domain {
id: string;
type: SendType;
name: EncString;
file: SendFile;
text: SendText;
expirationDate: Date;
creatorIdentifier: string;
constructor(obj?: SendAccessResponse) {
super();
if (obj == null) {
return;
}
this.buildDomainModel(
this,
obj,
{
id: null,
name: null,
expirationDate: null,
creatorIdentifier: null,
},
["id", "expirationDate", "creatorIdentifier"]
);
this.type = obj.type;
switch (this.type) {
case SendType.Text:
this.text = new SendText(obj.text);
break;
case SendType.File:
this.file = new SendFile(obj.file);
break;
default:
break;
}
}
async decrypt(key: SymmetricCryptoKey): Promise<SendAccessView> {
const model = new SendAccessView(this);
await this.decryptObj(
model,
{
name: null,
},
null,
key
);
switch (this.type) {
case SendType.File:
model.file = await this.file.decrypt(key);
break;
case SendType.Text:
model.text = await this.text.decrypt(key);
break;
default:
break;
}
return model;
}
}

View File

@@ -1,56 +0,0 @@
import { Jsonify } from "type-fest";
import { SendFileData } from "../data/send-file.data";
import { SendFileView } from "../view/send-file.view";
import Domain from "./domain-base";
import { EncString } from "./enc-string";
import { SymmetricCryptoKey } from "./symmetric-crypto-key";
export class SendFile extends Domain {
id: string;
size: string;
sizeName: string;
fileName: EncString;
constructor(obj?: SendFileData) {
super();
if (obj == null) {
return;
}
this.size = obj.size;
this.buildDomainModel(
this,
obj,
{
id: null,
sizeName: null,
fileName: null,
},
["id", "sizeName"]
);
}
async decrypt(key: SymmetricCryptoKey): Promise<SendFileView> {
const view = await this.decryptObj(
new SendFileView(this),
{
fileName: null,
},
null,
key
);
return view;
}
static fromJSON(obj: Jsonify<SendFile>) {
if (obj == null) {
return null;
}
return Object.assign(new SendFile(), obj, {
fileName: EncString.fromJSON(obj.fileName),
});
}
}

View File

@@ -1,51 +0,0 @@
import { Jsonify } from "type-fest";
import { SendTextData } from "../data/send-text.data";
import { SendTextView } from "../view/send-text.view";
import Domain from "./domain-base";
import { EncString } from "./enc-string";
import { SymmetricCryptoKey } from "./symmetric-crypto-key";
export class SendText extends Domain {
text: EncString;
hidden: boolean;
constructor(obj?: SendTextData) {
super();
if (obj == null) {
return;
}
this.hidden = obj.hidden;
this.buildDomainModel(
this,
obj,
{
text: null,
},
[]
);
}
decrypt(key: SymmetricCryptoKey): Promise<SendTextView> {
return this.decryptObj(
new SendTextView(this),
{
text: null,
},
null,
key
);
}
static fromJSON(obj: Jsonify<SendText>) {
if (obj == null) {
return null;
}
return Object.assign(new SendText(), obj, {
text: EncString.fromJSON(obj.text),
});
}
}

View File

@@ -1,128 +0,0 @@
import { Jsonify } from "type-fest";
import { SendType } from "../../enums/sendType";
import { Utils } from "../../misc/utils";
import { SendData } from "../data/send.data";
import { SendView } from "../view/send.view";
import Domain from "./domain-base";
import { EncString } from "./enc-string";
import { SendFile } from "./send-file";
import { SendText } from "./send-text";
export class Send extends Domain {
id: string;
accessId: string;
type: SendType;
name: EncString;
notes: EncString;
file: SendFile;
text: SendText;
key: EncString;
maxAccessCount?: number;
accessCount: number;
revisionDate: Date;
expirationDate: Date;
deletionDate: Date;
password: string;
disabled: boolean;
hideEmail: boolean;
constructor(obj?: SendData) {
super();
if (obj == null) {
return;
}
this.buildDomainModel(
this,
obj,
{
id: null,
accessId: null,
name: null,
notes: null,
key: null,
},
["id", "accessId"]
);
this.type = obj.type;
this.maxAccessCount = obj.maxAccessCount;
this.accessCount = obj.accessCount;
this.password = obj.password;
this.disabled = obj.disabled;
this.revisionDate = obj.revisionDate != null ? new Date(obj.revisionDate) : null;
this.deletionDate = obj.deletionDate != null ? new Date(obj.deletionDate) : null;
this.expirationDate = obj.expirationDate != null ? new Date(obj.expirationDate) : null;
this.hideEmail = obj.hideEmail;
switch (this.type) {
case SendType.Text:
this.text = new SendText(obj.text);
break;
case SendType.File:
this.file = new SendFile(obj.file);
break;
default:
break;
}
}
async decrypt(): Promise<SendView> {
const model = new SendView(this);
const cryptoService = Utils.getContainerService().getCryptoService();
try {
model.key = await cryptoService.decryptToBytes(this.key, null);
model.cryptoKey = await cryptoService.makeSendKey(model.key);
} catch (e) {
// TODO: error?
}
await this.decryptObj(
model,
{
name: null,
notes: null,
},
null,
model.cryptoKey
);
switch (this.type) {
case SendType.File:
model.file = await this.file.decrypt(model.cryptoKey);
break;
case SendType.Text:
model.text = await this.text.decrypt(model.cryptoKey);
break;
default:
break;
}
return model;
}
static fromJSON(obj: Jsonify<Send>) {
if (obj == null) {
return null;
}
const revisionDate = obj.revisionDate == null ? null : new Date(obj.revisionDate);
const expirationDate = obj.expirationDate == null ? null : new Date(obj.expirationDate);
const deletionDate = obj.deletionDate == null ? null : new Date(obj.deletionDate);
return Object.assign(new Send(), obj, {
key: EncString.fromJSON(obj.key),
name: EncString.fromJSON(obj.name),
notes: EncString.fromJSON(obj.notes),
text: SendText.fromJSON(obj.text),
file: SendFile.fromJSON(obj.file),
revisionDate,
expirationDate,
deletionDate,
});
}
}