-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathChangeKdfRequestModel.cs
More file actions
45 lines (39 loc) · 1.87 KB
/
ChangeKdfRequestModel.cs
File metadata and controls
45 lines (39 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System.ComponentModel.DataAnnotations;
using Bit.Core.KeyManagement.Models.Api.Request;
namespace Bit.Api.Auth.Models.Request.Accounts;
/// <summary>
/// We recognize this probably doesn't need the obsolete fields but we are leaving it in to be cleaned up anywho
/// later.
/// </summary>
public class ChangeKdfRequestModel : IValidatableObject
{
[Required]
public required string MasterPasswordHash { get; set; }
[Obsolete("To be removed in PM-33141")]
[StringLength(300)]
public string? NewMasterPasswordHash { get; set; }
[Obsolete("To be removed in PM-33141")]
public string? Key { get; set; }
// Should be made required in PM-33141
public MasterPasswordAuthenticationDataRequestModel? AuthenticationData { get; set; }
// Should be made required in PM-33141
public MasterPasswordUnlockDataRequestModel? UnlockData { get; set; }
// To be removed in PM-33141
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
var hasNewPayloads = AuthenticationData is not null && UnlockData is not null;
var hasLegacyPayloads = NewMasterPasswordHash is not null && Key is not null;
if (hasNewPayloads && hasLegacyPayloads)
{
yield return new ValidationResult(
"Cannot provide both new payloads (UnlockData/AuthenticationData) and legacy payloads (NewMasterPasswordHash/Key).",
[nameof(AuthenticationData), nameof(UnlockData), nameof(NewMasterPasswordHash), nameof(Key)]);
}
if (!hasNewPayloads && !hasLegacyPayloads)
{
yield return new ValidationResult(
"Must provide either new payloads (UnlockData/AuthenticationData) or legacy payloads (NewMasterPasswordHash/Key).",
[nameof(AuthenticationData), nameof(UnlockData), nameof(NewMasterPasswordHash), nameof(Key)]);
}
}
}