Skip to main content

Crate azathoth_transformers

Crate azathoth_transformers 

Source
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 Transformer trait must also implement a reverse function for it
  • no_std by default: doesn’t link the std crate, 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

TransformerDescription
AppendTransformerAppends a suffix to the data
PrependTransformerPrepends a prefix to the data
XorTransformerBasic 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§

TransformerPipeline
A Transformer pipeline

Traits§

Transformer
Core transformer trait. Implement this for types that transform data
TransformerExt
Extension to allow transformation for any type that implements AsRef<[u8]>

Type Aliases§

TransformerError
Generic error wrapper type