use pyo3::prelude::*;
use pyo3::types::PyBytes;
#[pyclass(name = "LogotypeExtnBuilder")]
pub struct PyLogotypeExtnBuilder {
inner: synta_certificate::LogotypeExtnBuilder,
built: bool,
}
#[pymethods]
impl PyLogotypeExtnBuilder {
#[new]
fn new() -> Self {
Self {
inner: synta_certificate::LogotypeExtnBuilder::new(),
built: false,
}
}
#[pyo3(signature = (media_type, hash_alg_oid, hash_value, uri))]
fn issuer_logo_direct<'py>(
slf: Bound<'py, Self>,
media_type: &str,
hash_alg_oid: Vec<u32>,
hash_value: &[u8],
uri: &str,
) -> Bound<'py, Self> {
let spec = synta_certificate::LogotypeDetailsSpec {
media_type,
hash_alg_oid: &hash_alg_oid,
hash_value,
uri,
};
{
let mut guard = slf.borrow_mut();
let old = std::mem::replace(
&mut guard.inner,
synta_certificate::LogotypeExtnBuilder::new(),
);
guard.inner = old.issuer_logo_direct(spec);
}
slf
}
#[pyo3(signature = (media_type, hash_alg_oid, hash_value, uri))]
fn subject_logo_direct<'py>(
slf: Bound<'py, Self>,
media_type: &str,
hash_alg_oid: Vec<u32>,
hash_value: &[u8],
uri: &str,
) -> Bound<'py, Self> {
let spec = synta_certificate::LogotypeDetailsSpec {
media_type,
hash_alg_oid: &hash_alg_oid,
hash_value,
uri,
};
{
let mut guard = slf.borrow_mut();
let old = std::mem::replace(
&mut guard.inner,
synta_certificate::LogotypeExtnBuilder::new(),
);
guard.inner = old.subject_logo_direct(spec);
}
slf
}
#[pyo3(signature = (media_type, hash_alg_oid, hash_value, uri))]
fn add_community_logo_direct<'py>(
slf: Bound<'py, Self>,
media_type: &str,
hash_alg_oid: Vec<u32>,
hash_value: &[u8],
uri: &str,
) -> Bound<'py, Self> {
let spec = synta_certificate::LogotypeDetailsSpec {
media_type,
hash_alg_oid: &hash_alg_oid,
hash_value,
uri,
};
{
let mut guard = slf.borrow_mut();
let old = std::mem::replace(
&mut guard.inner,
synta_certificate::LogotypeExtnBuilder::new(),
);
guard.inner = old.add_community_logo_direct(spec);
}
slf
}
#[pyo3(signature = (logotype_type_oid, media_type, hash_alg_oid, hash_value, uri))]
fn add_other_logo_direct<'py>(
slf: Bound<'py, Self>,
logotype_type_oid: Vec<u32>,
media_type: &str,
hash_alg_oid: Vec<u32>,
hash_value: &[u8],
uri: &str,
) -> Bound<'py, Self> {
let spec = synta_certificate::LogotypeDetailsSpec {
media_type,
hash_alg_oid: &hash_alg_oid,
hash_value,
uri,
};
{
let mut guard = slf.borrow_mut();
let old = std::mem::replace(
&mut guard.inner,
synta_certificate::LogotypeExtnBuilder::new(),
);
guard.inner = old.add_other_logo_direct(&logotype_type_oid, spec);
}
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::LogotypeExtnBuilder::new(),
);
let der = inner
.build()
.map_err(pyo3::exceptions::PyValueError::new_err)?;
Ok(PyBytes::new(py, &der))
}
fn __repr__(&self) -> String {
"LogotypeExtnBuilder()".to_string()
}
}
pub(super) fn register_logotype_classes(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<PyLogotypeExtnBuilder>()?;
Ok(())
}