diff --git a/src/Api/KeyManagement/Models/Response/PublicKeyEncryptionKeyPairResponseModel.cs b/src/Api/KeyManagement/Models/Response/PublicKeyEncryptionKeyPairResponseModel.cs index db25e498aa..8d62dbcdc1 100644 --- a/src/Api/KeyManagement/Models/Response/PublicKeyEncryptionKeyPairResponseModel.cs +++ b/src/Api/KeyManagement/Models/Response/PublicKeyEncryptionKeyPairResponseModel.cs @@ -1,14 +1,32 @@ -using Bit.Core.KeyManagement.Models.Data; +using System.Text.Json.Serialization; +using Bit.Core.KeyManagement.Models.Data; using Bit.Core.Models.Api; namespace Bit.Api.KeyManagement.Models.Response; -[method: System.Diagnostics.CodeAnalysis.SetsRequiredMembersAttribute] #nullable enable -public class PublicKeyEncryptionKeyPairModel(PublicKeyEncryptionKeyPairData keyPair) : ResponseModel("publicKeyEncryptionKeyPair") +public class PublicKeyEncryptionKeyPairModel : ResponseModel { - public required string WrappedPrivateKey { get; set; } = keyPair.WrappedPrivateKey; - public required string PublicKey { get; set; } = keyPair.PublicKey; - public string? SignedPublicKey { get; set; } = keyPair.SignedPublicKey; + public required string WrappedPrivateKey { get; set; } + public required string PublicKey { get; set; } + public string? SignedPublicKey { get; set; } + + [System.Diagnostics.CodeAnalysis.SetsRequiredMembersAttribute] + public PublicKeyEncryptionKeyPairModel(PublicKeyEncryptionKeyPairData keyPair) + : base("publicKeyEncryptionKeyPair") + { + WrappedPrivateKey = keyPair.WrappedPrivateKey; + PublicKey = keyPair.PublicKey; + SignedPublicKey = keyPair.SignedPublicKey; + } + + [JsonConstructor] + public PublicKeyEncryptionKeyPairModel(string wrappedPrivateKey, string publicKey, string? signedPublicKey) + : base("publicKeyEncryptionKeyPair") + { + WrappedPrivateKey = wrappedPrivateKey ?? throw new ArgumentNullException(nameof(wrappedPrivateKey)); + PublicKey = publicKey ?? throw new ArgumentNullException(nameof(publicKey)); + SignedPublicKey = signedPublicKey; + } } diff --git a/src/Api/KeyManagement/Models/Response/SignatureKeyPairResponseModel.cs b/src/Api/KeyManagement/Models/Response/SignatureKeyPairResponseModel.cs index 59b5ca20c2..76fb8aad10 100644 --- a/src/Api/KeyManagement/Models/Response/SignatureKeyPairResponseModel.cs +++ b/src/Api/KeyManagement/Models/Response/SignatureKeyPairResponseModel.cs @@ -1,13 +1,35 @@ -using Bit.Core.KeyManagement.Models.Data; +using System.Text.Json.Serialization; +using Bit.Core.KeyManagement.Models.Data; using Bit.Core.Models.Api; namespace Bit.Api.KeyManagement.Models.Response; -[method: System.Diagnostics.CodeAnalysis.SetsRequiredMembersAttribute] #nullable enable -public class SignatureKeyPairResponseModel(SignatureKeyPairData signatureKeyPair) : ResponseModel("signatureKeyPair") +public class SignatureKeyPairResponseModel : ResponseModel { - public required string WrappedSigningKey { get; set; } = signatureKeyPair.WrappedSigningKey; - public required string VerifyingKey { get; set; } = signatureKeyPair.VerifyingKey; + public required string WrappedSigningKey; + public required string VerifyingKey; + + [System.Diagnostics.CodeAnalysis.SetsRequiredMembersAttribute] + public SignatureKeyPairResponseModel(SignatureKeyPairData signatureKeyPair) + : base("signatureKeyPair") + { + if (signatureKeyPair == null) + { + throw new ArgumentNullException(nameof(signatureKeyPair)); + } + + WrappedSigningKey = signatureKeyPair.WrappedSigningKey; + VerifyingKey = signatureKeyPair.VerifyingKey; + } + + + [JsonConstructor] + public SignatureKeyPairResponseModel(string wrappedSigningKey, string verifyingKey) + : base("signatureKeyPair") + { + WrappedSigningKey = wrappedSigningKey ?? throw new ArgumentNullException(nameof(wrappedSigningKey)); + VerifyingKey = verifyingKey ?? throw new ArgumentNullException(nameof(verifyingKey)); + } }