mod archive;
mod builder;
mod bundle;
mod error;
mod manifest;
mod secrets;
mod sign;
#[cfg(feature = "wasm")]
mod wasm;
pub use builder::BundleBuilder;
pub use bundle::{Bundle, BundledPlugin, CompatReport, OpenOptions};
pub use error::BundleError;
#[cfg(feature = "wasm")]
pub use graphrt_wasm::WasmLimits;
pub use manifest::{BUNDLE_FORMAT_VERSION, BundleManifest, MANIFEST_PATH, PluginRef, Requires, SIGNATURE_PATH};
pub use secrets::check_no_inline_secrets;
pub use sign::{BundleSignature, KeyPair, generate_keypair, parse_public_key, sign_bundle};
pub fn sha256_hex(bytes: &[u8]) -> String {
use sha2::Digest;
let digest = sha2::Sha256::digest(bytes);
hex(&digest)
}
pub(crate) fn hex(bytes: &[u8]) -> String {
const DIGITS: &[u8; 16] = b"0123456789abcdef";
let mut out = String::with_capacity(bytes.len() * 2);
for b in bytes {
out.push(char::from(DIGITS.get(usize::from(b >> 4)).copied().unwrap_or(b'0')));
out.push(char::from(DIGITS.get(usize::from(b & 0x0f)).copied().unwrap_or(b'0')));
}
out
}
pub(crate) fn unhex(text: &str) -> Option<Vec<u8>> {
let text = text.trim();
if text.len() % 2 != 0 {
return None;
}
let mut out = Vec::with_capacity(text.len() / 2);
let bytes = text.as_bytes();
for pair in bytes.chunks(2) {
let s = std::str::from_utf8(pair).ok()?;
out.push(u8::from_str_radix(s, 16).ok()?);
}
Some(out)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn hex_roundtrip() {
let bytes = [0u8, 1, 0xab, 0xff];
assert_eq!(hex(&bytes), "0001abff");
assert_eq!(unhex("0001abff").unwrap(), bytes);
assert!(unhex("abc").is_none());
assert!(unhex("zz").is_none());
assert_eq!(sha256_hex(b"abc"), "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad");
}
}