Expand description
§azathoth_transformers
A no_std-compatible data transformation library for the Azathoth C2 systems.
§Features
- Chainable transformer pipelines: Can be used to chain multiple transformers together to create a pipeline of data transformation
- Reverse-able: Each type that implements the
Transformertrait must also implement areversefunction for it no_stdby default: doesn’t link thestdcrate, thus lowering the fingerprint
§Installation
Manually adding to Cargo.toml:
[dependencies]
azathoth_transformers = "0.1.0"With std and serde support:
[dependencies]
azathoth_transformers = { version = "0.1.0", features = ["std"] }Using cargo:
cargo add azathoth_transformers With std and serde support:
cargo add azathoth_transformers -F std§Quickstart
use azathoth_transformers::{TransformerPipeline, TransformerExt, TransformerError};
use azathoth_transformers::basic::{AppendTransformer, PrependTransformer};
fn main() -> Result<(), TransformerError> {
let mut pipeline = TransformerPipeline::new();
pipeline.add(AppendTransformer::new(" world"));
pipeline.add(PrependTransformer::new("abc "));
let result = pipeline.apply("hello").unwrap();
assert_eq!(result, b"abc hello world");
let reversed = pipeline.reverse(result).unwrap();
assert_eq!(reversed, b"hello");
Ok(())
}§Default Transformers
The crate comes with a few basic transformers that I thought would be nice to have
| Transformer | Description |
|---|---|
AppendTransformer | Appends a suffix to the data |
PrependTransformer | Prepends a prefix to the data |
XorTransformer | Basic XOR encoding with a key |
§Implementing Custom Transformers
Implementing custom transformers is pretty straight-forward:
use azathoth_transformers::{Transformer, TransformerError};
#[derive(Clone)]
struct UppercaseTransformer;
impl Transformer for UppercaseTransformer {
fn apply_bytes(&mut self, data: &[u8]) -> Result<Vec<u8>, TransformerError> {
Ok(data.iter().map(|b| b.to_ascii_uppercase()).collect())
}
fn reverse_bytes(&mut self, data: &[u8]) -> Result<Vec<u8>, TransformerError> {
Ok(data.iter().map(|b| b.to_ascii_lowercase()).collect())
}
fn name(&self) -> Option<&'static str> {
"uppercase"
}
fn box_clone(&self) -> Box<dyn Transformer> {
Box::new(self.clone())
}
}§License
MIT
Modules§
- basic
- Basic transformers (Append, Prepend, Xor)
Structs§
- Transformer
Pipeline - A
Transformerpipeline
Traits§
- Transformer
- Core transformer trait. Implement this for types that transform data
- Transformer
Ext - Extension to allow transformation for any type that implements
AsRef<[u8]>
Type Aliases§
- Transformer
Error - Generic error wrapper type