1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-20 02:48:03 -05:00

Apply suggestions

This commit is contained in:
Bernd Schoolmann 2025-06-19 15:56:22 +02:00
parent 4d6b8c88fc
commit ad32c5f257
No known key found for this signature in database
3 changed files with 10 additions and 10 deletions

View File

@ -6,6 +6,8 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using UserKeyResponseModel = Bit.Api.Models.Response.UserKeyResponseModel;
#nullable enable
namespace Bit.Api.KeyManagement.Controllers;
[Route("users")]
@ -22,11 +24,10 @@ public class UsersController : Controller
}
[HttpGet("{id}/public-key")]
public async Task<UserKeyResponseModel> GetPublicKeyAsync(string id)
public async Task<UserKeyResponseModel> GetPublicKeyAsync([FromRoute] Guid id)
{
var guidId = new Guid(id);
var key = await _userRepository.GetPublicKeyAsync(guidId) ?? throw new NotFoundException();
return new UserKeyResponseModel(guidId, key);
var key = await _userRepository.GetPublicKeyAsync(id) ?? throw new NotFoundException();
return new UserKeyResponseModel(id, key);
}
[HttpGet("{id}/keys")]

View File

@ -14,6 +14,10 @@ namespace Bit.Api.KeyManagement.Models.Response;
/// </summary>
public class PrivateKeysResponseModel : ResponseModel
{
// Not all accounts have signature keys, but all accounts have public encryption keys.
public SignatureKeyPairResponseModel? SignatureKeyPair { get; set; }
public required PublicKeyEncryptionKeyPairModel PublicKeyEncryptionKeyPair { get; set; }
[System.Diagnostics.CodeAnalysis.SetsRequiredMembersAttribute]
public PrivateKeysResponseModel(UserAccountKeysData accountKeys) : base("privateKeys")
{
@ -33,9 +37,4 @@ public class PrivateKeysResponseModel : ResponseModel
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; }
}

View File

@ -15,8 +15,8 @@ public class PublicKeysResponseModel : ResponseModel
public PublicKeysResponseModel(UserAccountKeysData accountKeys)
: base("publicKeys")
{
PublicKey = accountKeys.PublicKeyEncryptionKeyPairData.PublicKey;
ArgumentNullException.ThrowIfNull(accountKeys);
PublicKey = accountKeys.PublicKeyEncryptionKeyPairData.PublicKey;
if (accountKeys.SignatureKeyPairData != null)
{