mirror of
https://github.com/bitwarden/mobile
synced 2025-12-16 00:03:22 +00:00
Port send jslib to mobile (#1219)
* Expand Hkdf crypto functions * Add tests for hkdf crypto functions Took the testing infrastructure from bitwarden/server * Move Hkdf to cryptoFunctionService * Port changes from bitwarden/jslib#192 * Port changes from bitwarden/jslib#205 * Make Send Expiration Optional implement changes from bitwarden/jslib#242 * Bug fixes found by testing * Test helpers * Test conversion between model types * Test SendService These are mostly happy-path tests to ensure a reasonably correct implementation * Add run tests step to GitHub Actions * Test send decryption * Test Request generation from Send * Constructor dependencies on separate lines * Remove unused testing infrastructure * Rename to match class name * Move fat arrows to previous lines * Handle exceptions in App layer * PR review cleanups * Throw when attempting to save an unkown Send Type I think it's best to only throw on unknown send types here. I don't think we want to throw whenever we encounter one since that would do bad things like lock up Sync if clients get out of date relative to servers. Instead, keep the client from ruining saved data by complaining last minute that it doesn't know what it's doing.
This commit is contained in:
25
src/Core/Models/View/SendFileView.cs
Normal file
25
src/Core/Models/View/SendFileView.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System.Dynamic;
|
||||
using Bit.Core.Models.Domain;
|
||||
|
||||
namespace Bit.Core.Models.View
|
||||
{
|
||||
public class SendFileView : View
|
||||
{
|
||||
public SendFileView() : base() { }
|
||||
|
||||
public SendFileView(SendFile file)
|
||||
{
|
||||
Id = file.Id;
|
||||
Url = file.Url;
|
||||
Size = file.Size;
|
||||
SizeName = file.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 int FileSize => int.TryParse(Size ?? "0", out var sizeInt) ? sizeInt : 0;
|
||||
}
|
||||
}
|
||||
17
src/Core/Models/View/SendTextView.cs
Normal file
17
src/Core/Models/View/SendTextView.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Bit.Core.Models.Domain;
|
||||
|
||||
namespace Bit.Core.Models.View
|
||||
{
|
||||
public class SendTextView : View
|
||||
{
|
||||
public SendTextView() : base() { }
|
||||
public SendTextView(SendText text)
|
||||
{
|
||||
Hidden = text.Hidden;
|
||||
}
|
||||
|
||||
public string Text { get; set; } = null;
|
||||
public bool Hidden { get; set; }
|
||||
public string MaskedText => Text != null ? "••••••••" : null;
|
||||
}
|
||||
}
|
||||
45
src/Core/Models/View/SendView.cs
Normal file
45
src/Core/Models/View/SendView.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.Domain;
|
||||
using Bit.Core.Utilities;
|
||||
|
||||
namespace Bit.Core.Models.View
|
||||
{
|
||||
public class SendView : View
|
||||
{
|
||||
public SendView(Send send) : base()
|
||||
{
|
||||
Id = send.Id;
|
||||
AccessId = send.AccessId;
|
||||
Type = send.Type;
|
||||
MaxAccessCount = send.MaxAccessCount;
|
||||
AccessCount = send.AccessCount;
|
||||
RevisionDate = send.RevisionDate;
|
||||
DeletionDate = send.DeletionDate;
|
||||
ExpirationDate = send.ExpirationDate;
|
||||
Disabled = send.Disabled;
|
||||
Password = send.Password;
|
||||
}
|
||||
|
||||
public string Id { get; set; }
|
||||
public string AccessId { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public byte[] Key { get; set; }
|
||||
public SymmetricCryptoKey CryptoKey { get; set; }
|
||||
public SendType Type { get; set; }
|
||||
public SendTextView Text { get; set; } = new SendTextView();
|
||||
public SendFileView File { get; set; } = new SendFileView();
|
||||
public int? MaxAccessCount { get; set; }
|
||||
public int AccessCount { get; set; }
|
||||
public DateTime RevisionDate { get; set; }
|
||||
public DateTime DeletionDate { get; set; }
|
||||
public DateTime? ExpirationDate { get; set; }
|
||||
public string Password { get; set; }
|
||||
public bool Disabled { get; set; }
|
||||
public string UrlB64Key => Key == null ? null : CoreHelpers.Base64UrlEncode(Key);
|
||||
public bool MaxAccessCountReached => MaxAccessCount.HasValue && AccessCount >= MaxAccessCount.Value;
|
||||
public bool Expired => ExpirationDate.HasValue && ExpirationDate.Value <= DateTime.UtcNow;
|
||||
public bool PendingDelete => DeletionDate <= DateTime.UtcNow;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user