azathoth_transformers 0.1.0

Data transformers for the AzathothC2 project
Documentation
  • Coverage
  • 100%
    18 out of 18 items documented5 out of 8 items with examples
  • Size
  • Source code size: 16.7 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 4.32 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 13s Average build duration of successful builds.
  • all releases: 13s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • AzathothC2/azathoth_transformers
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • mrLochness350

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

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