summaryrefslogtreecommitdiffstats
path: root/third_party/rust/authenticator/src/ctap2/utils.rs
blob: ba9c7db3b4e29e04497263691433744e95ac4c08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
use serde::de;
use serde_cbor::error::Result;
use serde_cbor::Deserializer;

pub fn from_slice_stream<'a, T>(slice: &'a [u8]) -> Result<(&'a [u8], T)>
where
    T: de::Deserialize<'a>,
{
    let mut deserializer = Deserializer::from_slice(slice);
    let value = de::Deserialize::deserialize(&mut deserializer)?;
    let rest = &slice[deserializer.byte_offset()..];

    Ok((rest, value))
}