diff --git a/src/Core/Models/Domain/Attachment.cs b/src/Core/Models/Domain/Attachment.cs new file mode 100644 index 000000000..69367ff58 --- /dev/null +++ b/src/Core/Models/Domain/Attachment.cs @@ -0,0 +1,59 @@ +using Bit.Core.Models.Data; +using Bit.Core.Models.View; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Bit.Core.Models.Domain +{ + public class Attachment : Domain + { + public Attachment() { } + + public Attachment(AttachmentData obj, bool alreadyEncrypted = false) + { + Size = obj.Size; + BuildDomainModel(this, obj, new HashSet + { + "Id", + "Url", + "SizeName", + "FileName", + "Key" + }, alreadyEncrypted, new HashSet { "Id", "Url", "SizeName" }); + } + + public string Id { get; set; } + public string Url { get; set; } + public string Size { get; set; } + public string SizeName { get; set; } + public CipherString Key { get; set; } + public CipherString FileName { get; set; } + + public async Task DecryptAsync(string orgId) + { + var view = await DecryptObjAsync(new AttachmentView(this), this, new HashSet + { + "FileName" + }, orgId); + + // TODO: Decrypt key + + return view; + } + + public AttachmentData ToAttachmentData() + { + var a = new AttachmentData(); + a.Size = Size; + BuildDataModel(this, a, new HashSet + { + "Id", + "Url", + "SizeName", + "FileName", + "Key" + }, new HashSet { "Id", "Url", "SizeName" }); + return a; + } + } +} diff --git a/src/Core/Models/View/AttachmentView.cs b/src/Core/Models/View/AttachmentView.cs new file mode 100644 index 000000000..b97dfdcfa --- /dev/null +++ b/src/Core/Models/View/AttachmentView.cs @@ -0,0 +1,24 @@ +using Bit.Core.Models.Domain; + +namespace Bit.Core.Models.View +{ + public class AttachmentView : View + { + public AttachmentView() { } + + public AttachmentView(Attachment a) + { + Id = a.Id; + Url = a.Url; + Size = a.Size; + SizeName = a.SizeName; + } + + public string Id { get; set; } + public string Url { get; set; } + public string Size { get; set; } + public string SizeName { get; set; } + public string FileName { get; set; } + public SymmetricCryptoKey Key { get; set; } + } +}