about summary refs log tree commit diff
path: root/Tests/LibMatrix.HomeserverEmulator/Controllers/KeysController.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Tests/LibMatrix.HomeserverEmulator/Controllers/KeysController.cs103
1 files changed, 103 insertions, 0 deletions
diff --git a/Tests/LibMatrix.HomeserverEmulator/Controllers/KeysController.cs b/Tests/LibMatrix.HomeserverEmulator/Controllers/KeysController.cs
new file mode 100644
index 0000000..7898a8c
--- /dev/null
+++ b/Tests/LibMatrix.HomeserverEmulator/Controllers/KeysController.cs
@@ -0,0 +1,103 @@
+// using System.Security.Cryptography;
+// using System.Text.Json.Nodes;
+// using System.Text.Json.Serialization;
+// using LibMatrix.HomeserverEmulator.Services;
+// using LibMatrix.Responses;
+// using LibMatrix.Services;
+// using Microsoft.AspNetCore.Mvc;
+//
+// namespace LibMatrix.HomeserverEmulator.Controllers;
+//
+// [ApiController]
+// [Route("/_matrix/client/{version}/")]
+// public class KeysController(ILogger<KeysController> logger, TokenService tokenService, UserStore userStore) : ControllerBase {
+//     [HttpGet("room_keys/version")]
+//     public async Task<RoomKeysResponse> GetRoomKeys() {
+//         var token = tokenService.GetAccessToken(HttpContext);
+//         if (token == null)
+//             throw new MatrixException() {
+//                 ErrorCode = "M_MISSING_TOKEN",
+//                 Error = "Missing token"
+//             };
+//
+//         var user = await userStore.GetUserByToken(token);
+//         if (user == null)
+//             throw new MatrixException() {
+//                 ErrorCode = "M_UNKNOWN_TOKEN",
+//                 Error = "No such user"
+//             };
+//
+//         if (user.RoomKeys is not { Count: > 0 })
+//             throw new MatrixException() {
+//                 ErrorCode = "M_NOT_FOUND",
+//                 Error = "No keys found"
+//             };
+//
+//         return user.RoomKeys.Values.Last();
+//     }
+//
+//     [HttpPost("room_keys/version")]
+//     public async Task<RoomKeysResponse> UploadRoomKeys(RoomKeysRequest request) {
+//         var token = tokenService.GetAccessToken(HttpContext);
+//         if (token == null)
+//             throw new MatrixException() {
+//                 ErrorCode = "M_MISSING_TOKEN",
+//                 Error = "Missing token"
+//             };
+//
+//         var user = await userStore.GetUserByToken(token);
+//         if (user == null)
+//             throw new MatrixException() {
+//                 ErrorCode = "M_UNKNOWN_TOKEN",
+//                 Error = "No such user"
+//             };
+//
+//         var roomKeys = new RoomKeysResponse {
+//             Version = Guid.NewGuid().ToString(),
+//             Etag = Guid.NewGuid().ToString(),
+//             Algorithm = request.Algorithm,
+//             AuthData = request.AuthData
+//         };
+//         user.RoomKeys.Add(roomKeys.Version, roomKeys);
+//         return roomKeys;
+//     }
+//     
+//     [HttpPost("keys/device_signing/upload")]
+//     public async Task<object> UploadDeviceSigning(JsonObject request) {
+//         var token = tokenService.GetAccessToken(HttpContext);
+//         if (token == null)
+//             throw new MatrixException() {
+//                 ErrorCode = "M_MISSING_TOKEN",
+//                 Error = "Missing token"
+//             };
+//
+//         var user = await userStore.GetUserByToken(token);
+//         if (user == null)
+//             throw new MatrixException() {
+//                 ErrorCode = "M_UNKNOWN_TOKEN",
+//                 Error = "No such user"
+//             };
+//
+//         return new { };
+//     }
+// }
+//
+// public class DeviceSigningRequest {
+//     public CrossSigningKey? MasterKey { get; set; }
+//     public CrossSigningKey? SelfSigningKey { get; set; }
+//     public CrossSigningKey? UserSigningKey { get; set; }
+//     
+//     public class CrossSigningKey {
+//         [JsonPropertyName("keys")]
+//         public Dictionary<string, string> Keys { get; set; }
+//         
+//         [JsonPropertyName("signatures")]
+//         public Dictionary<string, Dictionary<string, string>> Signatures { get; set; }
+//         
+//         [JsonPropertyName("usage")]
+//         public List<string> Usage { get; set; }
+//         
+//         [JsonPropertyName("user_id")]
+//         public string UserId { get; set; }
+//     }
+// }
\ No newline at end of file