Skip to content

Commit ef066b3

Browse files
committed
fix: truncate session ID to 36 chars to match server validation
1 parent ba5d171 commit ef066b3

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/client/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ pub(crate) fn build_session_id(machine_id: &str, app_key: &str, date: &str) -> S
1717
hasher.update(app_key.as_bytes());
1818
hasher.update(date.as_bytes());
1919

20-
format!("{:x}", hasher.finalize())
20+
let hash = format!("{:x}", hasher.finalize());
21+
// Aptabase server validates SessionId <= 36 chars, SHA-256 hex is 64
22+
hash[..36].to_string()
2123
}
2224

2325
/// Creates a deterministic session ID from machine ID, app key, and current UTC date.

src/client/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ fn build_session_id_changes_with_different_machine() {
2929
}
3030

3131
#[test]
32-
fn build_session_id_returns_valid_sha256_hex() {
32+
fn build_session_id_returns_truncated_hex() {
3333
let id = build_session_id("machine-123", "A-US-abc", "2026-02-13");
34-
assert_eq!(id.len(), 64);
34+
assert_eq!(id.len(), 36);
3535
assert!(id.chars().all(|c| c.is_ascii_hexdigit()));
3636
}
3737

0 commit comments

Comments
 (0)