-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathChangeKdfRequestModel.cs
More file actions
50 lines (44 loc) · 1.99 KB
/
ChangeKdfRequestModel.cs
File metadata and controls
50 lines (44 loc) · 1.99 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
46
47
48
49
50
using System.ComponentModel.DataAnnotations;
using Bit.Core.KeyManagement.Models.Api.Request;
using Bit.Core.Utilities;
namespace Bit.Api.Auth.Models.Request.Accounts;
/// <summary>
/// Dual-shape request: validation accepts either the legacy
/// (<see cref="NewMasterPasswordHash"/>, <see cref="Key"/>) or new
/// (<see cref="AuthenticationData"/>, <see cref="UnlockData"/>) payload so the wire contract
/// can stabilize ahead of caller wiring. <c>PostKdf</c> currently honors only the new shape;
/// legacy-shape dispatch arrives with <c>ChangeKdfCommand</c>'s dual-path refactor. All legacy
/// fields are removed in PM-33141.
/// </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; }
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;
foreach (var validationResult in MasterPasswordPayloadVariantValidator.ValidateExclusivity(
hasNewPayloads, hasLegacyPayloads))
{
yield return validationResult;
}
if (hasNewPayloads)
{
foreach (var validationResult in KdfSettingsValidator.ValidateAuthenticationAndUnlockData(
AuthenticationData!.ToData(), UnlockData!.ToData()))
{
yield return validationResult;
}
}
}
}