Rust-Steganography: A stable steganography library written in rust

Build Status Build Status Build status Crates.io Crates.io Docs.rs dependency status

steganography

A stable steganography library written in rust

Crates.io

Usage

Add the following to the Cargo.toml in your project:

[dependencies]
steganography = "*"

and import using extern crate:

extern crate steganography;

/*
use steganography::encoder::*;
use steganography::decoder::*;
use steganography::util::*;
*/

Writing a message to a file

//Define a secret message to hide in out picture
let message = "This is a steganography demo!".to_string();
//Convert our string to bytes
let payload = str_to_bytes(&message);
//Load the image where we want to embed our secret message
let destination_image = file_as_dynamic_image("example.jpg".to_string());
//Create an encoder
let enc = Encoder::new(payload, destination_image);
//Encode our message into the alpha channel of the image
let result = enc.encode_alpha();
//Save the new image
save_image_buffer(result, "hidden_message.png".to_string());

Reading a message from a file

//Load the image with the secret message
let encoded_image = file_as_image_buffer("examples/decode_message.png".to_string());
//Create a decoder
let dec = Decoder::new(encoded_image);
//Decode the image by reading the alpha channel
let out_buffer = dec.decode_alpha();
//If there is no alpha, it's set to 255 by default so we filter those out
let clean_buffer: Vec<u8> = out_buffer.into_iter()
                                    .filter(|b| {
                                        *b != 0xff_u8
                                    })
                                    .collect();
//Convert those bytes into a string we can read
let message = bytes_to_str(clean_buffer.as_slice());
//Print it out!
println!("{:?}", message);

Running the examples

cargo build --example example_encode
cargo run --example example_encode
cargo build --example example_decode
cargo run --example example_decode

Testing

cargo test -- --test-threads=1

Comments

  • Update image requirement from 0.22.0 to 0.23.0
    Update image requirement from 0.22.0 to 0.23.0

    Feb 10, 2020

    Updates the requirements on image to permit the latest version.

    Changelog

    Sourced from image's changelog.

    Version 0.23.0

    This major release intends to improve the interface with regards to handling of color format data and errors for both decoding and encoding. This necessitated many breaking changes anyways so it was used to improve the compliance to the interface guidelines such as outstanding renaming.

    It is not yet perfect with regards to color spaces but it was designed mainly as an improvement over the current interface with regards to in-memory color formats, first. We'll get to color spaces in a later major version.

    • Heavily reworked ColorType:
      • This type is now used for denoting formats for which we support operations on buffers in these memory representations. Particularly, all channels in pixel types are assumed to be an integer number of bytes (In terms of the Rust type system, these are Sized and one can crate slices of channel values).
      • An ExtendedColorType is used to express more generic color formats for which the library has limited support but can be converted/scaled/mapped into a ColorType buffer. This operation might be fallible but, for example, includes sources with 1/2/4-bit components.
      • Both types are non-exhaustive to add more formats in a minor release.
      • A work-in-progress (#1085) will further separate the color model from the specific channel instantiation, e.g. both 8-bit RGB and 16-bit BGR are instantiations of RGB color model.
    • Heavily rework ImageError:
      • The top-level enum type now serves to differentiate cause with multiple opaque representations for the actual error. These are no longer simple Strings but contains useful types. Third-party decoders that have no variant in ImageFormat have also been considered.
      • Support for Error::source that can be downcast to an error from a matching version of the underlying decoders. Note that the version is not part of the stable interface guarantees, this should not be relied upon for correctness and only be used as an optimization.
      • Added image format indications to errors.
      • The error values produced by decoder will be upgraded incrementally. See something that still produces plain old String messages? Feel free to send a PR.
    • Reworked the ImageDecoder trait:
      • read_image takes an output buffer argument instead of allocating all memory on its own.
      • The return type of dimensions now aligns with GenericImage sizes.
      • The colortype method was renamed to color_type for conformity.
    • The enums ColorType, DynamicImage, imageops::FilterType, ImageFormat no longer re-export all of their variants in the top-level of the crate. This removes the growing pollution in the documentation and usage. You can still insert the equivalent statement on your own: use image::ImageFormat::{self, *};
    • The result of encode operations is now uniformly an ImageResult<()>.
    • Removed public converters from some tiff, png, gif, jpeg types,
    ... (truncated)
    Commits
    • dbb81ef Update readme, change notes, meta data
    • e50ebed Merge pull request #1132 from image-rs/next
    • 140f4ea Merge pull request #1131 from HeroicKatora/upstream-master
    • e3ab70d Merge remote-tracking branch 'upstream/master' into upstream-master
    • 9dd1c44 Merge pull request #1128 from HeroicKatora/hide-num-ratio
    • 642f0a8 Merge pull request #1130 from HeroicKatora/release-0.22.5
    • b6dacab Add a saturating conversion from time::Duration
    • 633f247 Align naming to ratio
    • 68ad0cc Add conversion of Delay into time::Duration
    • 85f163e Update meta data for 0.22.5
    • Additional commits viewable in compare view

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language
    • @dependabot badge me will comment on this PR with code to add a "Dependabot enabled" badge to your readme

    Additionally, you can set the following in your Dependabot dashboard:

    • Update frequency (including time of day and day of week)
    • Pull request limits (per update run and/or open at any time)
    • Automerge options (never/patch/minor, and dev/runtime dependencies)
    • Out-of-range updates (receive only lockfile updates, if desired)
    • Security updates (receive only security updates, if desired)
    dependencies 
    Reply
  • Benchmarking
    Benchmarking

    Sep 9, 2018

                                                                                                                                                                                                           
    Reply
  • Update image requirement from 0.19.0 to 0.20.0
    Update image requirement from 0.19.0 to 0.20.0

    Sep 21, 2018

    Updates the requirements on image to permit the latest version.

    Changelog

    Sourced from image's changelog.

    Rust Image 0.4 Release Notes

    Rust image aims to be a pure-Rust implementation of various popular image formats. Accompanying reading/write support, rust image provides basic imaging processing function. See README.md for further details.

    Known issues

    • Interlaced (progressive) or animated images are not well supported.
    • Images with n bit/channel (n ≠ 8) are not well supported.

    Changes

    Version 0.20

    • Clippy lint pass
    • Updated num-rational dependency
    • Added BGRA and BGR color types
    • Improved performance of image resizing
    • Improved PBM decoding
    • PNM P4 decoding now returns bits instead of bytes
    • Fixed move of overlapping buffers in BMP decoder
    • Fixed some document comments
    • GenericImage and GenericImageView is now object-safe
    • Moved TIFF code to its own library
    • Fixed README examples
    • Fixed ordering of interpolated parameters in TIFF decode error string
    • Thumbnail now handles upscaling
    • GIF encoding for multiple frames
    • Improved subimages API
    • Cargo fmt fixes

    Version 0.19

    • Fixed panic when blending with alpha zero.
    • Made save consistent.
    • Consistent size calculation.
    • Fixed bug in apply_with_alpha.
    • Implemented TGADecoder::read_scanline.
    • Use deprecated attribute for pixels_mut.
    • Fixed bug in JPEG grayscale encoding.
    • Fixed multi image TIFF.
    • PNM encoder.
    • Added #[derive(Hash)] for ColorType.
    • Use num-derive for #[derive(FromPrimitive)].
    • Added into_frames implementation for GIF.
    • Made rayon an optional dependency.
    • Fixed issue where resizing image did not give exact width/height.
    • Improved downscale.
    • Added a way to expose options when saving files.
    • Fixed some compiler warnings.
    • Switched to lzw crate instead of using built-in version.
    • Added ExactSizeIterator implementations to buffer structs.
    ... (truncated)
    Commits

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot ignore this [patch|minor|major] version will close this PR and stop Dependabot creating any more for this minor/major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language
    • @dependabot badge me will comment on this PR with code to add a "Dependabot enabled" badge to your readme

    Additionally, you can set the following in your Dependabot dashboard:

    • Update frequency (including time of day and day of week)
    • Automerge options (never/patch/minor, and dev/runtime dependencies)
    • Pull request limits (per update run and/or open at any time)
    • Out-of-range updates (receive only lockfile updates, if desired)
    • Security updates (receive only security updates, if desired)

    Finally, you can contact us by mentioning @dependabot.

    dependencies 
    Reply
  • Update image requirement from 0.19.0 to 0.20.1
    Update image requirement from 0.19.0 to 0.20.1

    Nov 1, 2018

    Updates the requirements on image to permit the latest version.

    Changelog

    Sourced from image's changelog.

    Rust Image Release Notes

    Rust image aims to be a pure-Rust implementation of various popular image formats. Accompanying reading/write support, rust image provides basic imaging processing function. See README.md for further details.

    Known issues

    • Interlaced (progressive) or animated images are not well supported.
    • Images with n bit/channel (n ≠ 8) are not well supported.

    Changes

    Version 0.20

    • Clippy lint pass
    • Updated num-rational dependency
    • Added BGRA and BGR color types
    • Improved performance of image resizing
    • Improved PBM decoding
    • PNM P4 decoding now returns bits instead of bytes
    • Fixed move of overlapping buffers in BMP decoder
    • Fixed some document comments
    • GenericImage and GenericImageView is now object-safe
    • Moved TIFF code to its own library
    • Fixed README examples
    • Fixed ordering of interpolated parameters in TIFF decode error string
    • Thumbnail now handles upscaling
    • GIF encoding for multiple frames
    • Improved subimages API
    • Cargo fmt fixes

    Version 0.19

    • Fixed panic when blending with alpha zero.
    • Made save consistent.
    • Consistent size calculation.
    • Fixed bug in apply_with_alpha.
    • Implemented TGADecoder::read_scanline.
    • Use deprecated attribute for pixels_mut.
    • Fixed bug in JPEG grayscale encoding.
    • Fixed multi image TIFF.
    • PNM encoder.
    • Added #[derive(Hash)] for ColorType.
    • Use num-derive for #[derive(FromPrimitive)].
    • Added into_frames implementation for GIF.
    • Made rayon an optional dependency.
    • Fixed issue where resizing image did not give exact width/height.
    • Improved downscale.
    • Added a way to expose options when saving files.
    • Fixed some compiler warnings.
    • Switched to lzw crate instead of using built-in version.
    • Added ExactSizeIterator implementations to buffer structs.
    ... (truncated)
    Commits

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot ignore this [patch|minor|major] version will close this PR and stop Dependabot creating any more for this minor/major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language
    • @dependabot badge me will comment on this PR with code to add a "Dependabot enabled" badge to your readme

    Additionally, you can set the following in your Dependabot dashboard:

    • Update frequency (including time of day and day of week)
    • Automerge options (never/patch/minor, and dev/runtime dependencies)
    • Pull request limits (per update run and/or open at any time)
    • Out-of-range updates (receive only lockfile updates, if desired)
    • Security updates (receive only security updates, if desired)

    Finally, you can contact us by mentioning @dependabot.

    dependencies 
    Reply
  • Fixed parenthesis missing in example code.
    Fixed parenthesis missing in example code.

    Feb 22, 2018

    Just noticed and fixed a mistype in your README.

    Reply
  • Publish image dependency update
    Publish image dependency update

    Apr 30, 2019

    I see in the commit log that the image crate dependency was upgraded to 0.21.0. Would it be possible to publish this change to crates.io? I am using steganography and image on its own, but the 0.19.0 and 0.21.0 versions of image conflict, so I have to use the old version of image to be compatible with steganography. I'd like to be using the newest version of the crate.

    Reply