use pyo3::prelude::*;
use pyo3::types::PyBytes;
#[pyclass(name = "AuthenticationContextsBuilder")]
pub struct PyAuthenticationContextsBuilder {
inner: synta_certificate::AuthenticationContextsBuilder,
built: bool,
}
#[pymethods]
impl PyAuthenticationContextsBuilder {
#[new]
fn new() -> Self {
Self {
inner: synta_certificate::AuthenticationContextsBuilder::new(),
built: false,
}
}
#[pyo3(signature = (context_type, context_info=None))]
fn add<'py>(
slf: Bound<'py, Self>,
context_type: &str,
context_info: Option<&str>,
) -> Bound<'py, Self> {
{
let mut guard = slf.borrow_mut();
let old = std::mem::replace(
&mut guard.inner,
synta_certificate::AuthenticationContextsBuilder::new(),
);
guard.inner = old.add(context_type, context_info);
}
slf
}
fn build<'py>(&mut self, py: Python<'py>) -> PyResult<Bound<'py, PyBytes>> {
if self.built {
return Err(pyo3::exceptions::PyValueError::new_err(
"build() has already been called; create a new builder",
));
}
self.built = true;
let inner = std::mem::replace(
&mut self.inner,
synta_certificate::AuthenticationContextsBuilder::new(),
);
let der = inner
.build()
.map_err(pyo3::exceptions::PyValueError::new_err)?;
Ok(PyBytes::new(py, &der))
}
fn __repr__(&self) -> String {
"AuthenticationContextsBuilder()".to_string()
}
}
pub(super) fn register_ace88_classes(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<PyAuthenticationContextsBuilder>()?;
Ok(())
}