upub/apb/src/key.rs
alemi 0dedb4d243
feat(apb): all owned by default
references are cool but it was mostly cloned anyway so may aswell be
consistent. it would be awesome to make a Node which works by references
eventually, so it can be Copy, but probably quite annoying to make
2024-11-20 19:19:20 +01:00

33 lines
882 B
Rust

// TODO technically this is not part of ActivityStreams
pub trait PublicKey : super::Base {
fn owner(&self) -> crate::Field<String> { Err(crate::FieldErr("owner")) }
fn public_key_pem(&self) -> String;
}
pub trait PublicKeyMut : super::BaseMut {
fn set_owner(self, val: Option<String>) -> Self;
fn set_public_key_pem(self, val: String) -> Self;
}
#[cfg(feature = "unstructured")]
impl PublicKey for serde_json::Value {
crate::getter! { owner -> String }
fn public_key_pem(&self) -> String {
self.get("publicKeyPem").and_then(|x| x.as_str()).unwrap_or_default().to_string()
}
}
#[cfg(feature = "unstructured")]
impl PublicKeyMut for serde_json::Value {
crate::setter! { owner -> String }
fn set_public_key_pem(mut self, val: String) -> Self {
self.as_object_mut().unwrap().insert(
"publicKeyPem".to_string(),
serde_json::Value::String(val),
);
self
}
}