Skip to content

Commit

Permalink
Add an __eq__ method
Browse files Browse the repository at this point in the history
Signed-off-by: Alexis <alexis.challande@trailofbits.com>
  • Loading branch information
DarkaMaul committed Oct 31, 2024
1 parent 02457f7 commit d642b87
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Magic method (`__eq__` and `__repr__`) has been added for TimestampResponse
and TimestampRequest ([#XX](https://github.com/trailofbits/rfc3161-client/pull/XX))

## [0.0.2] - 2024-10-30

Expand Down
12 changes: 12 additions & 0 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ impl TimeStampReq {
hasher.finish()
}

fn __eq__(&self, py: pyo3::Python<'_>, other: pyo3::PyRef<'_, Self>) -> pyo3::PyResult<bool> {
let other_bytes = other.as_bytes(py)?;
let self_bytes = self.as_bytes(py)?;
Ok(other_bytes.eq(&self_bytes.as_bytes()))
}

fn __repr__(&self, py: pyo3::Python<'_>) -> pyo3::PyResult<String> {
let version = self.version()?;
let nonce_repr = match self.nonce(py)? {
Expand Down Expand Up @@ -293,6 +299,12 @@ impl TimeStampResp {
hasher.finish()
}

fn __eq__(&self, other: pyo3::PyRef<'_, Self>) -> pyo3::PyResult<bool> {
let other_bytes = asn1::write_single(&other.raw.borrow_dependent()).unwrap();
let self_bytes = asn1::write_single(&self.raw.borrow_dependent()).unwrap();
Ok(other_bytes.eq(&self_bytes))
}

fn __repr__(&self) -> pyo3::PyResult<String> {
let status = self.status()?;
Ok(format!("<TimestampResponse(status={status}, ...)>"))
Expand Down

0 comments on commit d642b87

Please sign in to comment.