From 6b2a879635b51c23cc49e228a83773318422f0e7 Mon Sep 17 00:00:00 2001 From: Frank Buss Date: Tue, 14 Jan 2025 18:44:33 +0100 Subject: [PATCH] updated to edition 2021 --- Cargo.toml | 13 +++++++------ src/c_api.rs | 4 ++-- src/lib.rs | 18 +++++++++--------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3b52cdc..4e64686 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,18 +1,19 @@ [package] +name = "rot26" +version = "0.2.0" authors = ["jD91mZM2 "] description = "Pure rust rewrite of the rot26 algorithm" license-file = "LICENSE" -name = "rot26" repository = "https://github.com/jD91mZM2/rot26" -version = "0.1.2" +edition = "2021" +categories = ["algorithms", "cryptography"] +keywords = ["rot26", "encryption"] -[dependencies.rayon] -optional = true -version = "0.9.0" +[dependencies] +rayon = { version = "1.10", optional = true } [features] c_api = [] [lib] crate-type = ["rlib", "staticlib"] -# https://github.com/rust-lang/cargo/issues/4881 diff --git a/src/c_api.rs b/src/c_api.rs index 73ad39a..3f2d9ac 100644 --- a/src/c_api.rs +++ b/src/c_api.rs @@ -1,4 +1,4 @@ -use ::*; +use super::*; use std::{ ffi::{CStr, CString}, os::raw::*, @@ -8,7 +8,7 @@ use std::{ /// Free the Rust-owned string in a safe way. #[no_mangle] pub extern fn rot26_free(input: *mut c_char) { - unsafe { CString::from_raw(input); } + unsafe { drop(CString::from_raw(input)); } } /// Encrypt the input using rot26. diff --git a/src/lib.rs b/src/lib.rs index 79677d6..7653a99 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -43,8 +43,8 @@ pub fn decrypt_rot13(input: &str) -> String { pub fn encrypt_any(input: &str, amount: u32) -> String { let closure = |c| { let base = match c { - 'a'...'z' => 'a' as u32, - 'A'...'Z' => 'A' as u32, + 'a'..='z' => 'a' as u32, + 'A'..='Z' => 'A' as u32, _ => return c }; @@ -62,8 +62,8 @@ pub fn encrypt_any(input: &str, amount: u32) -> String { pub fn decrypt_any(input: &str, amount: u32) -> String { let closure = |c| { let base = match c { - 'a'...'z' => 'a' as u32, - 'A'...'Z' => 'A' as u32, + 'a'..='z' => 'a' as u32, + 'A'..='Z' => 'A' as u32, _ => return c }; @@ -77,14 +77,14 @@ pub fn decrypt_any(input: &str, amount: u32) -> String { #[cfg(test)] mod tests { - use ::*; + use super::*; #[test] fn test_rot26() { - let plain = "hello"; + let plain = "hello😃"; let encrypted = encrypt(plain); - assert_eq!(encrypted, "hello"); + assert_eq!(encrypted, "hello😃"); let decrypted = decrypt(&encrypted); @@ -116,10 +116,10 @@ mod tests { fn test_rot_any() { let amount = 1; - let plain = "hello"; + let plain = "hello😃"; let encrypted = encrypt_any(plain, amount); - assert_eq!(encrypted, "ifmmp"); + assert_eq!(encrypted, "ifmmp😃"); let decrypted = decrypt_any(&encrypted, amount);