Introduce libsignal-net-chat (and libsignal-cli-utils)

libsignal-net-chat builds higher-level APIs on top of libsignal-net's
ChatConnection, while also abstracting for a future using a
non-WebSocket-message-based transport for these requests. It will
likely change a fair bit as more APIs get filled in, and existing
high-level APIs in libsignal-net may get moved here (specifically
keytrans and registration).

libsignal-cli-utils is a common place to put helpers for our example
binaries; it's not (at this time) meant for the bridge libraries we
ship as our main products.
This commit is contained in:
Jordan Rose
2025-04-09 17:22:38 -07:00
parent 3d17710afd
commit b538947ca1
21 changed files with 651 additions and 40 deletions

View File

@@ -0,0 +1,36 @@
//
// Copyright 2025 Signal Messenger, LLC.
// SPDX-License-Identifier: AGPL-3.0-only
//
use libsignal_core::Aci;
#[derive(Debug, thiserror::Error)]
pub enum ParseHexError<const N: usize> {
#[error("character {c} at position {index} is not a hex digit")]
InvalidHexCharacter { c: char, index: usize },
#[error("got {count} hex digits, expected {} ({N} bytes)", 2 * N)]
WrongNumberOfDigits { count: usize },
}
pub fn parse_hex_bytes<const N: usize>(input: &str) -> Result<[u8; N], ParseHexError<N>>
where
[u8; N]: hex::FromHex<Error = hex::FromHexError>,
{
hex::FromHex::from_hex(input).map_err(|e| match e {
hex::FromHexError::InvalidHexCharacter { c, index } => {
ParseHexError::InvalidHexCharacter { c, index }
}
hex::FromHexError::InvalidStringLength | hex::FromHexError::OddLength => {
ParseHexError::WrongNumberOfDigits { count: input.len() }
}
})
}
pub fn parse_aci(input: &str) -> Result<Aci, AciParseError> {
Aci::parse_from_service_id_string(input).ok_or(AciParseError)
}
/// invalid ACI, expected a UUID like "55555555-5555-5555-5555-555555555555"
#[derive(Debug, thiserror::Error, displaydoc::Display)]
pub struct AciParseError;