1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-10 21:33:36 +00:00
Files
mobile/src/Core/Models/Domain/Login.cs
Federico Maccaroni a4a0d31fc6 [PM-3811] Passkeys unification (#2774)
* PM-3811 Unified passkeys view and moved both inside Login as an array of FIdo2Key

* PM-3811 Passkeys unification => updated cipher details view an helpers

* PM-3811 Updated passkeys creation date time format
2023-09-22 14:55:35 +00:00

83 lines
2.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Bit.Core.Models.Data;
using Bit.Core.Models.View;
namespace Bit.Core.Models.Domain
{
public class Login : Domain
{
public Login() { }
public Login(LoginData obj, bool alreadyEncrypted = false)
{
PasswordRevisionDate = obj.PasswordRevisionDate;
Uris = obj.Uris?.Select(u => new LoginUri(u, alreadyEncrypted)).ToList();
Fido2Keys = obj.Fido2Keys?.Select(f => new Fido2Key(f, alreadyEncrypted)).ToList();
BuildDomainModel(this, obj, new HashSet<string>
{
"Username",
"Password",
"Totp"
}, alreadyEncrypted);
}
public List<LoginUri> Uris { get; set; }
public EncString Username { get; set; }
public EncString Password { get; set; }
public DateTime? PasswordRevisionDate { get; set; }
public EncString Totp { get; set; }
public List<Fido2Key> Fido2Keys { get; set; }
public async Task<LoginView> DecryptAsync(string orgId)
{
var view = await DecryptObjAsync(new LoginView(this), this, new HashSet<string>
{
"Username",
"Password",
"Totp"
}, orgId);
if (Uris != null)
{
view.Uris = new List<LoginUriView>();
foreach (var uri in Uris)
{
view.Uris.Add(await uri.DecryptAsync(orgId));
}
}
if (Fido2Keys != null)
{
view.Fido2Keys = new List<Fido2KeyView>();
foreach (var fido2Key in Fido2Keys)
{
view.Fido2Keys.Add(await fido2Key.DecryptAsync(orgId));
}
}
return view;
}
public LoginData ToLoginData()
{
var l = new LoginData();
l.PasswordRevisionDate = PasswordRevisionDate;
BuildDataModel(this, l, new HashSet<string>
{
"Username",
"Password",
"Totp"
});
if (Uris?.Any() ?? false)
{
l.Uris = Uris.Select(u => u.ToLoginUriData()).ToList();
}
if (Fido2Keys != null)
{
l.Fido2Keys = Fido2Keys.Select(f => f.ToFido2KeyData()).ToList();
}
return l;
}
}
}