mirror of
https://github.com/bitwarden/server.git
synced 2025-06-20 02:48:03 -05:00
45 lines
1.8 KiB
C#
45 lines
1.8 KiB
C#
using System.Text.Json.Serialization;
|
|
using Bit.Core.KeyManagement.Models.Data;
|
|
using Bit.Core.Models.Api;
|
|
|
|
namespace Bit.Api.KeyManagement.Models.Response;
|
|
|
|
#nullable enable
|
|
|
|
/// <summary>
|
|
/// This response model is used to return the the asymmetric encryption keys,
|
|
/// and signature keys of an entity. This includes the private keys of the key pairs,
|
|
/// (private key, signing key), and the public keys of the key pairs (unsigned public key,
|
|
/// signed public key, verification key).
|
|
/// </summary>
|
|
public class PrivateKeysResponseModel : ResponseModel
|
|
{
|
|
[System.Diagnostics.CodeAnalysis.SetsRequiredMembersAttribute]
|
|
public PrivateKeysResponseModel(UserAccountKeysData accountKeys) : base("privateKeys")
|
|
{
|
|
PublicKeyEncryptionKeyPair = new PublicKeyEncryptionKeyPairModel(accountKeys.PublicKeyEncryptionKeyPairData);
|
|
if (accountKeys == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(accountKeys));
|
|
}
|
|
|
|
if (accountKeys.SignatureKeyPairData != null)
|
|
{
|
|
SignatureKeyPair = new SignatureKeyPairResponseModel(accountKeys.SignatureKeyPairData);
|
|
}
|
|
}
|
|
|
|
[JsonConstructor]
|
|
public PrivateKeysResponseModel(SignatureKeyPairResponseModel? signatureKeyPair, PublicKeyEncryptionKeyPairModel publicKeyEncryptionKeyPair)
|
|
: base("privateKeys")
|
|
{
|
|
SignatureKeyPair = signatureKeyPair;
|
|
PublicKeyEncryptionKeyPair = publicKeyEncryptionKeyPair ?? throw new ArgumentNullException(nameof(publicKeyEncryptionKeyPair));
|
|
}
|
|
|
|
// Not all accounts have signature keys, but all accounts have public encryption keys.
|
|
public SignatureKeyPairResponseModel? SignatureKeyPair { get; set; }
|
|
public required PublicKeyEncryptionKeyPairModel PublicKeyEncryptionKeyPair { get; set; }
|
|
|
|
}
|