diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cd572e4ce5..8a22186dae 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -82,6 +82,7 @@ jobs: cargo clippy -p sample_core_app && cargo clippy -p sample_create_window && cargo clippy -p sample_create_window_sys && + cargo clippy -p sample_data_protection && cargo clippy -p sample_direct2d && cargo clippy -p sample_direct3d12 && cargo clippy -p sample_enum_windows && diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 857a82b669..b6db49e741 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -116,6 +116,7 @@ jobs: cargo test --target ${{ matrix.target }} -p sample_core_app && cargo test --target ${{ matrix.target }} -p sample_create_window && cargo test --target ${{ matrix.target }} -p sample_create_window_sys && + cargo test --target ${{ matrix.target }} -p sample_data_protection && cargo test --target ${{ matrix.target }} -p sample_direct2d && cargo test --target ${{ matrix.target }} -p sample_direct3d12 && cargo test --target ${{ matrix.target }} -p sample_enum_windows && diff --git a/crates/samples/data_protection/Cargo.toml b/crates/samples/data_protection/Cargo.toml new file mode 100644 index 0000000000..70feccec8f --- /dev/null +++ b/crates/samples/data_protection/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "sample_data_protection" +version = "0.0.0" +edition = "2018" + +[dependencies.windows] +path = "../../libs/windows" +features = [ + "alloc", + "Foundation", + "Storage_Streams", + "Security_Cryptography_DataProtection", +] diff --git a/crates/samples/data_protection/src/main.rs b/crates/samples/data_protection/src/main.rs new file mode 100644 index 0000000000..dcf712cb37 --- /dev/null +++ b/crates/samples/data_protection/src/main.rs @@ -0,0 +1,16 @@ +use windows::{core::*, Security::Cryptography::DataProtection::*, Security::Cryptography::*}; + +fn main() -> Result<()> { + let provider = DataProtectionProvider::CreateOverloadExplicit("LOCAL=user")?; + + let buffer = CryptographicBuffer::ConvertStringToBinary("Hello world", BinaryStringEncoding::Utf8)?; + + let protected = provider.ProtectAsync(buffer)?.get()?; + + let unprotected = provider.UnprotectAsync(protected)?.get()?; + + let message = CryptographicBuffer::ConvertBinaryToString(BinaryStringEncoding::Utf8, unprotected)?; + + println!("{}", message); + Ok(()) +}