use pyo3::exceptions::PyValueError;
use pyo3::prelude::*;
#[pyclass(name = "RevokedRanges")]
pub struct PyRevokedRanges {
inner: synta_mtc::revocation::RevokedRanges,
}
#[pymethods]
impl PyRevokedRanges {
#[new]
fn new() -> Self {
Self {
inner: synta_mtc::revocation::RevokedRanges::new(),
}
}
fn add(&mut self, start: u64, end: u64) -> PyResult<()> {
self.inner
.add(start, end)
.map_err(|e| PyValueError::new_err(e.to_string()))
}
fn is_revoked(&self, index: u64) -> bool {
self.inner.is_revoked(index)
}
fn contains_range(&self, start: u64, end: u64) -> bool {
self.inner.contains_range(start, end)
}
fn len(&self) -> usize {
self.inner.len()
}
fn is_empty(&self) -> bool {
self.inner.is_empty()
}
fn ranges<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, pyo3::types::PyList>> {
let items: Vec<Bound<'_, pyo3::types::PyTuple>> = self
.inner
.iter()
.map(|(s, e)| pyo3::types::PyTuple::new(py, [s, e]))
.collect::<PyResult<Vec<_>>>()?;
pyo3::types::PyList::new(py, items)
}
fn __len__(&self) -> usize {
self.inner.len()
}
fn __repr__(&self) -> String {
format!("RevokedRanges(len={})", self.inner.len())
}
}