mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-13 16:32:56 +00:00
* [proxy] Add SCRAM auth * [proxy] Implement some tests for SCRAM * Refactoring + test fixes * Hide SCRAM mechanism behind `#[cfg(test)]` Currently we only use it in tests, so we hide all relevant module behind `#[cfg(test)]` to prevent "unused item" warnings.
19 lines
586 B
Rust
19 lines
586 B
Rust
//! Small parsing helpers.
|
|
|
|
use std::convert::TryInto;
|
|
use std::ffi::CStr;
|
|
|
|
pub fn split_cstr(bytes: &[u8]) -> Option<(&CStr, &[u8])> {
|
|
let pos = bytes.iter().position(|&x| x == 0)?;
|
|
let (cstr, other) = bytes.split_at(pos + 1);
|
|
// SAFETY: we've already checked that there's a terminator
|
|
Some((unsafe { CStr::from_bytes_with_nul_unchecked(cstr) }, other))
|
|
}
|
|
|
|
pub fn split_at_const<const N: usize>(bytes: &[u8]) -> Option<(&[u8; N], &[u8])> {
|
|
(bytes.len() >= N).then(|| {
|
|
let (head, tail) = bytes.split_at(N);
|
|
(head.try_into().unwrap(), tail)
|
|
})
|
|
}
|