Skip to content

Commit

Permalink
Add some inital documentation for the core methods
Browse files Browse the repository at this point in the history
  • Loading branch information
tritoke committed Jul 28, 2024
1 parent c264e01 commit b9a566e
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,22 @@ macro_rules! impl_sponge_shaker_classes {
// hasher is tt so we can pick the right kind of methods to generate
($hasher:tt, $xof_reader:ident, $shaker_name:ident, $sponge_name:ident) => {
#[pyclass(module="xof_py")]
#[doc=concat!(stringify!($shaker_name), " implements absorption and finalization for the ", stringify!($hasher), " XOF")]
struct $shaker_name {
hasher: $hasher,
}

impl_sponge_shaker_classes!(@shaker_methods $hasher, $shaker_name, $sponge_name);

#[pyclass(module="xof_py")]
#[doc=concat!(stringify!($sponge_name), " implements sponge expansion for the ", stringify!($hasher), " XOF")]
struct $sponge_name {
xof: XofReaderCoreWrapper<$xof_reader>,
}

#[pymethods]
impl $sponge_name {
/// Docstring for the read??
#[doc=concat!("Read `n` bytes of data from the ", stringify!($hasher), " XOF")]
fn read<'py>(&mut self, py: Python<'py>, n: usize) -> PyResult<Bound<'py, PyBytes>> {
PyBytes::new_bound_with(py, n, |bytes| {
self.xof.read(bytes);
Expand Down Expand Up @@ -70,12 +72,16 @@ macro_rules! impl_sponge_shaker_classes {
Ok(Self { hasher })
}

/// This should be the absorb one...
#[doc=concat!("Absorb `input_bytes` into the ", stringify!($hasher), " state")]
fn absorb(&mut self, input_bytes: &[u8]) {
self.hasher.update(input_bytes);
}

/// This should be the finalize one...
#[doc=concat!(
"Finalize the ", stringify!($hasher), " XOF into a sponge for expansion\n",
"\n",
"This method also resets the state, allowing more data to be absorbed.",
)]
fn finalize(&mut self) -> $sponge_name {
$sponge_name {
xof: self.hasher.finalize_xof_reset(),
Expand All @@ -99,7 +105,6 @@ macro_rules! impl_sponge_shaker_classes {
impl $shaker_name {
#[new]
#[pyo3(signature = (input_bytes = None))]
/// Here is some docstrings...
fn new(input_bytes: Option<&[u8]>) -> Self {
let mut hasher = $hasher::default();
if let Some(initial_data) = input_bytes {
Expand All @@ -108,12 +113,16 @@ macro_rules! impl_sponge_shaker_classes {
Self { hasher }
}

/// This should be the absorb one...
#[doc=concat!("Absorb `input_bytes` into the ", stringify!($hasher), " state")]
fn absorb(&mut self, input_bytes: &[u8]) {
self.hasher.update(input_bytes);
}

/// This should be the finalize one...
#[doc=concat!(
"Finalize the ", stringify!($hasher), " XOF into a sponge for expansion\n",
"\n",
"This method also resets the state, allowing more data to be absorbed.",
)]
fn finalize(&mut self) -> $sponge_name {
$sponge_name {
xof: self.hasher.finalize_xof_reset(),
Expand Down

0 comments on commit b9a566e

Please sign in to comment.