Implement bounded XML LLSD codec

This commit is contained in:
2026-08-09 01:08:14 +00:00
parent 2308e55671
commit 84bc31d031
14 changed files with 853 additions and 34 deletions

View File

@@ -7,16 +7,44 @@ mod dispatch;
mod generated;
mod model;
mod notation;
mod xml_codec;
pub mod xml {
use std::sync::{Arc, Mutex};
/// Project-owned XML element boundary; external XML APIs are not copied.
pub struct Element;
/// Native XML reader boundary; external XML APIs are not copied.
pub struct Reader;
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct Reader(pub String);
/// Native XML writer boundary; external XML APIs are not copied.
pub struct Writer;
#[derive(Clone, Debug, Default)]
pub struct Writer(pub Arc<Mutex<String>>);
impl Writer {
#[must_use]
pub fn contents(&self) -> String {
self.0
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner)
.clone()
}
pub(crate) fn append(&self, value: &str) -> Result<(), crate::Error> {
let mut output = self.0.lock().map_err(|_| crate::Error::InvalidOperation)?;
let length = output
.len()
.checked_add(value.len())
.ok_or(crate::Error::Argument)?;
if length > crate::OSD::DEFAULT_MAX_BINARY_BYTES {
return Err(crate::Error::Argument);
}
output.push_str(value);
Ok(())
}
}
}
pub use generated::*;