1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// githttp-fs
//
// Git-based Content Management System
// Copyright: 2026, Valerian Saliou <valerian@valeriansaliou.name>
// License: Mozilla Public License v2.0 (MPL v2.0)
//! Small cross-cutting helpers with no better home.
use crateAppError;
/// Runs a blocking closure on Tokio's blocking thread pool, returning the
/// inner result. Centralises the JoinError → AppError mapping so handlers
/// stay focused on their logic.
///
/// Why this exists: libgit2 (and therefore everything in `git.rs`) is fully
/// synchronous — it does disk I/O, zlib compression, and SHA hashing on the
/// calling thread. Running that directly inside an async handler would park
/// a tokio worker thread and, under load, starve *every* request on the
/// server, not just the slow one. `spawn_blocking` moves the work onto
/// tokio's dedicated (much larger) blocking pool instead.
///
/// The double `?`-ish shape at the end unwraps two layers: the outer
/// `JoinError` (the task panicked or was cancelled — mapped to a 500) and
/// the inner `Result` produced by the closure itself.
pub async
/// Constant-time equality check for byte slices, used for comparing secrets
/// to avoid leaking length-prefix matches through timing side channels.
///
/// A naive `left == right` short-circuits at the first mismatching byte, so
/// the comparison takes measurably longer the more leading bytes match —
/// enough signal for an attacker to brute-force a key byte by byte. This
/// version always walks both slices in full and folds every XOR into one
/// accumulator, so the running time depends only on the length.
///
/// The early length check *is* allowed to short-circuit: the length of the
/// configured API key is not considered secret.