Implement /generate-server-padlock-2

This commit is contained in:
Xiretza 2024-02-10 18:59:28 +00:00
parent 8d4b969419
commit 045d5394ca

View file

@ -42,6 +42,10 @@ pub async fn run(
"/generate-user-server-key-2",
post(generate_user_server_key_2),
)
.route(
"/generate-server-padlock-2",
post(generate_server_padlock_2),
)
.with_state(app_state);
let listener = tokio::net::TcpListener::bind((Ipv6Addr::UNSPECIFIED, port)).await?;
axum::serve(listener, app).await?;
@ -151,3 +155,27 @@ async fn generate_user_server_key_2(
server_key_timestamp,
}))
}
#[derive(Serialize)]
struct ServerPadlockResponse {
server_hash: ServerHash,
server_padlock: String,
}
#[instrument]
async fn generate_server_padlock_2(
State(state): State<Arc<AppState>>,
Query(ApiVersion { api_version }): Query<ApiVersion>,
) -> ApiResult<Json<ServerPadlockResponse>> {
event!(Level::INFO, "Creating server padlock");
let server_hash = ServerPadlockGenerator::generate_hash();
let server_padlock = state
.server_padlock_generator
.generate_padlock(&server_hash);
Ok(Json(ServerPadlockResponse {
server_hash,
server_padlock: server_padlock.0.expose_secret().to_owned(),
}))
}