-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathV4VaultConfigurationDataModel.cs
More file actions
89 lines (79 loc) · 3.59 KB
/
V4VaultConfigurationDataModel.cs
File metadata and controls
89 lines (79 loc) · 3.59 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using SecureFolderFS.Shared.Models;
using System;
using System.ComponentModel;
using System.Security.Cryptography;
using System.Text.Json.Serialization;
using static SecureFolderFS.Core.Constants.Vault;
namespace SecureFolderFS.Core.DataModels
{
[Serializable]
public sealed record class V4VaultConfigurationDataModel : VersionDataModel
{
/// <summary>
/// Gets the ID for content encryption.
/// </summary>
[JsonPropertyName(Associations.ASSOC_CONTENT_CIPHER_ID)]
[DefaultValue("")]
public required string ContentCipherId { get; init; }
/// <summary>
/// Gets the ID for file name encryption.
/// </summary>
[JsonPropertyName(Associations.ASSOC_FILENAME_CIPHER_ID)]
[DefaultValue("")]
public required string FileNameCipherId { get; init; }
/// <summary>
/// Gets the ID for file name encoding.
/// </summary>
[JsonPropertyName(Associations.ASSOC_FILENAME_ENCODING_ID)]
[DefaultValue("")]
public string FileNameEncodingId { get; set; } = Cryptography.Constants.CipherId.ENCODING_BASE64URL;
/// <summary>
/// Gets the size of the recycle bin.
/// </summary>
/// <remarks>
/// If the size is zero, the recycle bin is disabled.
/// If the size is any value smaller than zero, the recycle bin has unlimited size capacity.
/// Any values above zero indicate the maximum capacity in bytes that is allowed for the recycling operation to proceed.
/// </remarks>
[JsonPropertyName(Associations.ASSOC_RECYCLE_SIZE)]
[DefaultValue(0L)]
public long RecycleBinSize { get; set; }
/// <summary>
/// Gets the information about the authentication method used for this vault.
/// </summary>
[JsonPropertyName(Associations.ASSOC_AUTHENTICATION)]
[DefaultValue("")]
public required string AuthenticationMethod { get; set; } = string.Empty;
/// <summary>
/// Gets the unique identifier of the vault represented by a GUID.
/// </summary>
[JsonPropertyName(Associations.ASSOC_VAULT_ID)]
[DefaultValue("")]
public required string Uid { get; init; } = string.Empty;
/// <summary>
/// Gets the App Platform used by this vault.
/// </summary>
[JsonPropertyName(Associations.ASSOC_APP_PLATFORM)]
public AppPlatformVaultOptions? AppPlatform { get; init; }
/// <summary>
/// Gets the HMAC-SHA256 hash of the payload.
/// </summary>
[JsonPropertyName("hmacsha256mac")]
public byte[]? PayloadMac { get; set; }
public static V4VaultConfigurationDataModel V4FromVaultOptions(VaultOptions vaultOptions)
{
return new()
{
Version = vaultOptions.Version < 1 ? Versions.LATEST_VERSION : vaultOptions.Version,
ContentCipherId = vaultOptions.ContentCipherId ?? Cryptography.Constants.CipherId.XCHACHA20_POLY1305,
FileNameCipherId = vaultOptions.FileNameCipherId ?? Cryptography.Constants.CipherId.AES_SIV,
FileNameEncodingId = vaultOptions.NameEncodingId ?? Cryptography.Constants.CipherId.ENCODING_BASE64URL,
AuthenticationMethod = vaultOptions.UnlockProcedure.ToString(),
RecycleBinSize = vaultOptions.RecycleBinSize,
Uid = vaultOptions.VaultId ?? Guid.NewGuid().ToString(),
AppPlatform = vaultOptions.AppPlatform,
PayloadMac = new byte[HMACSHA256.HashSizeInBytes]
};
}
}
}