using Bit.App.Enums; using Bit.App.Models; using System; using System.Collections.Generic; using System.Linq; namespace Bit.iOS.Core.Models { public class CipherViewModel { public CipherViewModel(Cipher cipher) { Id = cipher.Id; Name = cipher.Name?.Decrypt(cipher.OrganizationId); Username = cipher.Login?.Username?.Decrypt(cipher.OrganizationId); Password = cipher.Login?.Password?.Decrypt(cipher.OrganizationId); Uris = cipher.Login?.Uris?.Select(u => new LoginUriModel(u, cipher.OrganizationId)); Totp = new Lazy(() => cipher.Login?.Totp?.Decrypt(cipher.OrganizationId)); Fields = new Lazy>>(() => { if(!cipher.Fields?.Any() ?? true) { return null; } var fields = new List>(); foreach(var field in cipher.Fields) { fields.Add(new Tuple( field.Name?.Decrypt(cipher.OrganizationId), field.Value?.Decrypt(cipher.OrganizationId))); } return fields; }); } public string Id { get; set; } public string Name { get; set; } public string Username { get; set; } public string Password { get; set; } public IEnumerable Uris { get; set; } public Lazy Totp { get; set; } public Lazy>> Fields { get; set; } public class LoginUriModel { public LoginUriModel(LoginUri data, string orgId) { Uri = data?.Uri?.Decrypt(orgId); Match = data?.Match; } public string Uri { get; set; } public UriMatchType? Match { get; set; } } } }