From ccf1ffa90fd3b8683e7bf6713f694b0034bae4b8 Mon Sep 17 00:00:00 2001 From: Bernd Schoolmann Date: Thu, 5 Jun 2025 14:21:04 +0200 Subject: [PATCH] Cleanup --- .../Response/PublicKeysResponseModel.cs | 29 +++++++++++++------ .../Data/PublicKeyEncryptionKeyPairData.cs | 2 +- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/Api/KeyManagement/Models/Response/PublicKeysResponseModel.cs b/src/Api/KeyManagement/Models/Response/PublicKeysResponseModel.cs index c2f45de977..0d1f75fa56 100644 --- a/src/Api/KeyManagement/Models/Response/PublicKeysResponseModel.cs +++ b/src/Api/KeyManagement/Models/Response/PublicKeysResponseModel.cs @@ -1,23 +1,34 @@ -using Bit.Core.Models.Api; +using Bit.Core.KeyManagement.Models.Data; +using Bit.Core.Models.Api; namespace Bit.Api.KeyManagement.Models.Response; +#nullable enable + /// /// This response model is used to return the public keys of a user, to any other registered user or entity on the server. /// It can contain public keys (signature/encryption), and proofs between the two. It does not contain (encrypted) private keys. /// public class PublicKeysResponseModel : ResponseModel { - public PublicKeysResponseModel(string verifyingKey, string publicKey, string signedPublicKey) + public PublicKeysResponseModel(UserAccountKeysData accountKeys) : base("publicKeys") { - VerifyingKey = verifyingKey; - SignedPublicKey = signedPublicKey; - PublicKey = publicKey; + if (accountKeys == null) + { + throw new ArgumentNullException(nameof(accountKeys)); + } + + if (accountKeys.SignatureKeyPairData != null) + { + SignedPublicKey = accountKeys.PublicKeyEncryptionKeyPairData.SignedPublicKey; + VerifyingKey = accountKeys.SignatureKeyPairData.VerifyingKey; + } + PublicKey = accountKeys.PublicKeyEncryptionKeyPairData.PublicKey; } - public string VerifyingKey { get; set; } - public string SignedPublicKey { get; set; } - [System.Obsolete("Use SignedPublicKey for new code.")] - public string PublicKey { get; set; } + public string? VerifyingKey { get; set; } + public string? SignedPublicKey { get; set; } + [System.Obsolete("Use SignedPublicKey for new code, if it is not null.")] + public required string PublicKey { get; set; } } diff --git a/src/Core/KeyManagement/Models/Data/PublicKeyEncryptionKeyPairData.cs b/src/Core/KeyManagement/Models/Data/PublicKeyEncryptionKeyPairData.cs index ed39f1dfc7..1f9757f1dd 100644 --- a/src/Core/KeyManagement/Models/Data/PublicKeyEncryptionKeyPairData.cs +++ b/src/Core/KeyManagement/Models/Data/PublicKeyEncryptionKeyPairData.cs @@ -4,6 +4,6 @@ public class PublicKeyEncryptionKeyPairData { public string WrappedPrivateKey { get; set; } public string SignedPublicKey { get; set; } - [System.Obsolete("Use SignedPublicKey instead for new code.")] + [System.Obsolete("Use SignedPublicKey instead for new code, if it is not null.")] public string PublicKey { get; set; } }