diff --git a/tlsn/Cargo.toml b/tlsn/Cargo.toml index 4c0a4f35b..a957f2ab5 100644 --- a/tlsn/Cargo.toml +++ b/tlsn/Cargo.toml @@ -49,6 +49,7 @@ thiserror = "1" serde = "1" bincode = "1" hex = "0.4" +bytes = "1.4" opaque-debug = "0.3" tracing = "0.1" diff --git a/tlsn/tlsn-core/Cargo.toml b/tlsn/tlsn-core/Cargo.toml index 64aacec49..8733a7a75 100644 --- a/tlsn/tlsn-core/Cargo.toml +++ b/tlsn/tlsn-core/Cargo.toml @@ -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] diff --git a/tlsn/tlsn-core/src/transcript.rs b/tlsn/tlsn-core/src/transcript.rs index 9b491e299..2f181724d 100644 --- a/tlsn/tlsn-core/src/transcript.rs +++ b/tlsn/tlsn-core/src/transcript.rs @@ -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, + data: Bytes, } impl Transcript { /// Creates a new transcript with the given ID and data - pub fn new(id: &str, data: Vec) -> Self { + pub fn new(id: &str, data: impl Into) -> 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]