diff --git a/src/Api/Models/Request/CipherRequestModel.cs b/src/Api/Models/Request/CipherRequestModel.cs index 417fb4497137..7d7e0fa0b766 100644 --- a/src/Api/Models/Request/CipherRequestModel.cs +++ b/src/Api/Models/Request/CipherRequestModel.cs @@ -22,6 +22,7 @@ public class CipherRequestModel public string FolderId { get; set; } public bool Favorite { get; set; } public CipherRepromptType Reprompt { get; set; } + public EncObject Data { get; set; } [Required] [EncryptedString] [EncryptedStringLength(1000)] @@ -86,7 +87,8 @@ public Cipher ToCipher(Cipher existingCipher) existingCipher.Data = JsonSerializer.Serialize(ToCipherSecureNoteData(), JsonHelpers.IgnoreWritingNull); break; default: - throw new ArgumentException("Unsupported type: " + nameof(Type) + "."); + existingCipher.Data = JsonSerializer.Serialize(Data, JsonHelpers.IgnoreWritingNull); + break; } existingCipher.Reprompt = Reprompt; @@ -227,7 +229,6 @@ private CipherSecureNoteData ToCipherSecureNoteData() Notes = Notes, Fields = Fields?.Select(f => f.ToCipherFieldData()), PasswordHistory = PasswordHistory?.Select(ph => ph.ToCipherPasswordHistoryData()), - Type = SecureNote.Type, }; } diff --git a/src/Api/Models/Response/CipherResponseModel.cs b/src/Api/Models/Response/CipherResponseModel.cs index 6ebf671e6e5d..1bcb721f53e4 100644 --- a/src/Api/Models/Response/CipherResponseModel.cs +++ b/src/Api/Models/Response/CipherResponseModel.cs @@ -52,13 +52,19 @@ public CipherMiniResponseModel(Cipher cipher, IGlobalSettings globalSettings, bo Identity = new CipherIdentityModel(identityData); break; default: - throw new ArgumentException("Unsupported " + nameof(Type) + "."); + var customData = JsonSerializer.Deserialize(cipher.Data); + Data = customData; + cipherData = null; + break; } - Name = cipherData.Name; - Notes = cipherData.Notes; - Fields = cipherData.Fields?.Select(f => new CipherFieldModel(f)); - PasswordHistory = cipherData.PasswordHistory?.Select(ph => new CipherPasswordHistoryModel(ph)); + if (cipherData != null) + { + Name = cipherData.Name; + Notes = cipherData.Notes; + Fields = cipherData.Fields?.Select(f => new CipherFieldModel(f)); + PasswordHistory = cipherData.PasswordHistory?.Select(ph => new CipherPasswordHistoryModel(ph)); + } RevisionDate = cipher.RevisionDate; OrganizationId = cipher.OrganizationId?.ToString(); Attachments = AttachmentResponseModel.FromCipher(cipher, globalSettings); diff --git a/src/Core/Enums/CipherType.cs b/src/Core/Enums/CipherType.cs index 0aca94864088..3e56a37c7615 100644 --- a/src/Core/Enums/CipherType.cs +++ b/src/Core/Enums/CipherType.cs @@ -7,6 +7,6 @@ public enum CipherType : byte Login = 1, SecureNote = 2, Card = 3, - Identity = 4 + Identity = 4, } } diff --git a/src/Core/Models/Data/CipherAttachment.cs b/src/Core/Models/Data/Cipher/CipherAttachment.cs similarity index 100% rename from src/Core/Models/Data/CipherAttachment.cs rename to src/Core/Models/Data/Cipher/CipherAttachment.cs diff --git a/src/Core/Models/Data/CipherCardData.cs b/src/Core/Models/Data/Cipher/CipherCardData.cs similarity index 100% rename from src/Core/Models/Data/CipherCardData.cs rename to src/Core/Models/Data/Cipher/CipherCardData.cs diff --git a/src/Core/Models/Data/CipherData.cs b/src/Core/Models/Data/Cipher/CipherData.cs similarity index 100% rename from src/Core/Models/Data/CipherData.cs rename to src/Core/Models/Data/Cipher/CipherData.cs diff --git a/src/Core/Models/Data/CipherDetails.cs b/src/Core/Models/Data/Cipher/CipherDetails.cs similarity index 100% rename from src/Core/Models/Data/CipherDetails.cs rename to src/Core/Models/Data/Cipher/CipherDetails.cs diff --git a/src/Core/Models/Data/CipherFieldData.cs b/src/Core/Models/Data/Cipher/CipherFieldData.cs similarity index 100% rename from src/Core/Models/Data/CipherFieldData.cs rename to src/Core/Models/Data/Cipher/CipherFieldData.cs diff --git a/src/Core/Models/Data/CipherIdentityData.cs b/src/Core/Models/Data/Cipher/CipherIdentityData.cs similarity index 100% rename from src/Core/Models/Data/CipherIdentityData.cs rename to src/Core/Models/Data/Cipher/CipherIdentityData.cs diff --git a/src/Core/Models/Data/CipherLoginData.cs b/src/Core/Models/Data/Cipher/CipherLoginData.cs similarity index 100% rename from src/Core/Models/Data/CipherLoginData.cs rename to src/Core/Models/Data/Cipher/CipherLoginData.cs diff --git a/src/Core/Models/Data/CipherOrganizationDetails.cs b/src/Core/Models/Data/Cipher/CipherOrganizationDetails.cs similarity index 100% rename from src/Core/Models/Data/CipherOrganizationDetails.cs rename to src/Core/Models/Data/Cipher/CipherOrganizationDetails.cs diff --git a/src/Core/Models/Data/CipherPasswordHistoryData.cs b/src/Core/Models/Data/Cipher/CipherPasswordHistoryData.cs similarity index 100% rename from src/Core/Models/Data/CipherPasswordHistoryData.cs rename to src/Core/Models/Data/Cipher/CipherPasswordHistoryData.cs diff --git a/src/Core/Models/Data/CipherSecureNoteData.cs b/src/Core/Models/Data/Cipher/CipherSecureNoteData.cs similarity index 100% rename from src/Core/Models/Data/CipherSecureNoteData.cs rename to src/Core/Models/Data/Cipher/CipherSecureNoteData.cs diff --git a/src/Core/Models/Data/EncObject.cs b/src/Core/Models/Data/EncObject.cs new file mode 100644 index 000000000000..8525e3794b36 --- /dev/null +++ b/src/Core/Models/Data/EncObject.cs @@ -0,0 +1,12 @@ +using Bit.Core.Enums; + +namespace Bit.Core.Models.Data +{ + public class EncObject + { + public EncryptionType Type { get; set; } + public string Data { get; set; } + public string Iv { get; set; } + public string Mac { get; set; } + } +}