mirror of
https://github.com/signalapp/libsignal.git
synced 2026-05-05 06:32:35 +02:00
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:
36
rust/cli-utils/src/args.rs
Normal file
36
rust/cli-utils/src/args.rs
Normal 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;
|
||||
Reference in New Issue
Block a user