mirror of
https://github.com/tlsnotary/tlsn.git
synced 2026-04-28 03:00:14 -04:00
refactor: use Bytes in Transcript (#322)
This commit is contained in:
@@ -49,6 +49,7 @@ thiserror = "1"
|
||||
serde = "1"
|
||||
bincode = "1"
|
||||
hex = "0.4"
|
||||
bytes = "1.4"
|
||||
opaque-debug = "0.3"
|
||||
|
||||
tracing = "0.1"
|
||||
|
||||
@@ -27,8 +27,9 @@ serde.workspace = true
|
||||
p256 = { workspace = true, features = ["serde"] }
|
||||
webpki-roots.workspace = true
|
||||
rs_merkle.workspace = true
|
||||
rstest = { workspace = true, optional = true}
|
||||
hex = { workspace = true, optional = true}
|
||||
rstest = { workspace = true, optional = true }
|
||||
hex = { workspace = true, optional = true }
|
||||
bytes = { workspace = true, features = ["serde"] }
|
||||
tracing = { workspace = true, optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
@@ -1,28 +1,36 @@
|
||||
//! This module contains code for transcripts of the TLSNotary session
|
||||
|
||||
use crate::error::Error;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::ops::Range;
|
||||
|
||||
use bytes::Bytes;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::error::Error;
|
||||
|
||||
/// A transcript contains a subset of bytes from a TLS session
|
||||
#[derive(Default, Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct Transcript {
|
||||
id: String,
|
||||
data: Vec<u8>,
|
||||
data: Bytes,
|
||||
}
|
||||
|
||||
impl Transcript {
|
||||
/// Creates a new transcript with the given ID and data
|
||||
pub fn new(id: &str, data: Vec<u8>) -> Self {
|
||||
pub fn new(id: &str, data: impl Into<Bytes>) -> Self {
|
||||
Self {
|
||||
id: id.to_string(),
|
||||
data,
|
||||
data: data.into(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Extends the transcript with the given data
|
||||
pub fn extend(&mut self, data: &[u8]) {
|
||||
self.data.extend(data);
|
||||
/// Returns the id used to identify this transcript
|
||||
pub fn id(&self) -> &String {
|
||||
&self.id
|
||||
}
|
||||
|
||||
/// Returns the actual traffic data of this transcript
|
||||
pub fn data(&self) -> &Bytes {
|
||||
&self.data
|
||||
}
|
||||
|
||||
/// Returns the value ID for each byte in the provided range
|
||||
@@ -54,16 +62,6 @@ impl Transcript {
|
||||
|
||||
Ok(dst)
|
||||
}
|
||||
|
||||
/// Returns the id used to identify this transcript
|
||||
pub fn id(&self) -> &String {
|
||||
&self.id
|
||||
}
|
||||
|
||||
/// Returns the actual traffic data of this transcript
|
||||
pub fn data(&self) -> &[u8] {
|
||||
&self.data
|
||||
}
|
||||
}
|
||||
|
||||
/// Authenticated slice of [Transcript]. The [Direction] should be infered from some outer context.
|
||||
@@ -140,7 +138,10 @@ mod tests {
|
||||
recv.get_bytes_in_ranges(&[range1, range2]).unwrap()
|
||||
);
|
||||
|
||||
assert_eq!(sent.data(), sent.get_bytes_in_ranges(&[range3]).unwrap());
|
||||
assert_eq!(
|
||||
sent.data().as_ref(),
|
||||
sent.get_bytes_in_ranges(&[range3]).unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
|
||||
Reference in New Issue
Block a user