// FIXME: Update this file to be null safe and then delete the line below #nullable disable using System.Text.Json; using Bit.Core.Models.Api; using Bit.Core.Tools.Entities; using Bit.Core.Tools.Enums; using Bit.Core.Tools.Models.Data; using Bit.Core.Utilities; namespace Bit.Api.Tools.Models.Response; /// /// A response issued to a Bitwarden client in response to access operations. /// public class SendAccessResponseModel : ResponseModel { /// /// Instantiates a send access response model /// /// Content to transmit to the client. /// /// Thrown when is /// /// /// Thrown when has an invalid . /// public SendAccessResponseModel(Send send) : base("send-access") { if (send == null) { throw new ArgumentNullException(nameof(send)); } Id = CoreHelpers.Base64UrlEncode(send.Id.ToByteArray()); Type = send.Type; AuthType = send.AuthType; SendData sendData; switch (send.Type) { case SendType.File: var fileData = JsonSerializer.Deserialize(send.Data); sendData = fileData; File = new SendFileModel(fileData); break; case SendType.Text: var textData = JsonSerializer.Deserialize(send.Data); sendData = textData; Text = new SendTextModel(textData); break; default: throw new ArgumentException("Unsupported " + nameof(Type) + "."); } Name = sendData.Name; ExpirationDate = send.ExpirationDate; } /// /// Identifies the send in a send URL /// public string Id { get; set; } /// /// Indicates whether the send contains text or file data. /// public SendType Type { get; set; } /// /// Specifies the authentication method required to access this Send. /// public AuthType? AuthType { get; set; } /// /// Label for the send. This is only visible to the owner of the send. /// /// /// This field contains a base64-encoded byte array. The array contains /// the E2E-encrypted encrypted content. /// public string Name { get; set; } /// /// Describes the file attached to the send. /// /// /// File content is downloaded separately using /// /// public SendFileModel File { get; set; } /// /// Contains text data uploaded with the send. /// public SendTextModel Text { get; set; } /// /// The date after which a send cannot be accessed. When this value is /// , there is no expiration date. /// public DateTime? ExpirationDate { get; set; } /// /// Indicates the person that created the send to the accessor. /// public string CreatorIdentifier { get; set; } }