Skip to content

Commit

Permalink
Rename a few things
Browse files Browse the repository at this point in the history
  • Loading branch information
jedisct1 committed Oct 21, 2024
1 parent f0183c2 commit deb7cc9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/lib/src/signature/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl PublicKeySet {
detached_signature: Option<&[u8]>,
predicates: &[impl Fn(&Section) -> bool],
) -> Result<Vec<HashSet<&PublicKey>>, WSError> {
let mut sections = Module::stream(Module::stream_init(reader)?)?;
let mut sections = Module::iterate(Module::read_from_stream(reader)?)?;
let signature_header_section = if let Some(detached_signature) = &detached_signature {
Section::Custom(CustomSection::new(
SIGNATURE_SECTION_HEADER_NAME.to_string(),
Expand Down
2 changes: 1 addition & 1 deletion src/lib/src/signature/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl PublicKey {
where
P: FnMut(&Section) -> bool,
{
let mut sections = Module::stream(Module::stream_init(reader)?)?.enumerate();
let mut sections = Module::iterate(Module::read_from_stream(reader)?)?.enumerate();
let signature_header_section = if let Some(detached_signature) = &detached_signature {
Section::Custom(CustomSection::new(
SIGNATURE_SECTION_HEADER_NAME.to_string(),
Expand Down
6 changes: 3 additions & 3 deletions src/lib/src/signature/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ impl PublicKey {
reader: &mut impl Read,
detached_signature: Option<&[u8]>,
) -> Result<(), WSError> {
let stream = Module::stream_init(reader)?;
let mut sections = Module::stream(stream)?;
let stream = Module::read_from_stream(reader)?;
let mut sections = Module::iterate(stream)?;

// Read the signature header from the module, or reconstruct it from the detached signature.
let signature_header_section = if let Some(detached_signature) = &detached_signature {
Expand Down Expand Up @@ -147,7 +147,7 @@ impl PublicKeySet {
reader: &mut impl Read,
detached_signature: Option<&[u8]>,
) -> Result<HashSet<&PublicKey>, WSError> {
let mut sections = Module::stream(Module::stream_init(reader)?)?;
let mut sections = Module::iterate(Module::read_from_stream(reader)?)?;

// Read the signature header from the module, or reconstruct it from the detached signature.
let signature_header: &Section;
Expand Down
16 changes: 8 additions & 8 deletions src/lib/src/wasm_module/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,9 @@ pub struct Module {
impl Module {
/// Deserialize a WebAssembly module from the given reader.
pub fn deserialize(reader: &mut impl Read) -> Result<Self, WSError> {
let stream = Self::stream_init(reader)?;
let stream = Self::read_from_stream(reader)?;
let header = stream.header;
let it = Self::stream(stream)?;
let it = Self::iterate(stream)?;
let mut sections = Vec::new();
for section in it {
sections.push(section?);
Expand Down Expand Up @@ -405,28 +405,28 @@ impl Module {
}

/// Parse the module's header. This function must be called before `stream()`.
pub fn stream_init<T: Read>(reader: &mut T) -> Result<InitialModuleStream<T>, WSError> {
pub fn read_from_stream<T: Read>(reader: &mut T) -> Result<ModuleStreamReader<T>, WSError> {
let mut header = Header::default();
reader.read_exact(&mut header)?;
if header != WASM_HEADER && header != WASM_COMPONENT_HEADER {
return Err(WSError::UnsupportedModuleType);
}
Ok(InitialModuleStream { reader, header })
Ok(ModuleStreamReader { reader, header })
}

/// Return an iterator over the sections of a WebAssembly module.
///
/// The module is read in a streaming fashion, and doesn't have to be fully loaded into memory.
pub fn stream<T: Read>(
initial_module_stream: InitialModuleStream<T>,
pub fn iterate<T: Read>(
module_stream: ModuleStreamReader<T>,
) -> Result<SectionsIterator<T>, WSError> {
Ok(SectionsIterator {
reader: initial_module_stream.reader,
reader: module_stream.reader,
})
}
}

pub struct InitialModuleStream<'t, T: Read> {
pub struct ModuleStreamReader<'t, T: Read> {
reader: &'t mut T,
header: Header,
}
Expand Down

0 comments on commit deb7cc9

Please sign in to comment.