Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clippy and fmt issues #1039

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test-rust.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
rust: [stable, '1.58']
rust: [stable, '1.60']
fail-fast: false
steps:
- name: Install system dependencies
Expand Down Expand Up @@ -81,7 +81,7 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
rust: [stable, '1.58']
rust: [stable, '1.60']
fail-fast: false
steps:
- name: Install system dependencies
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ _Code:_

This is technically a breaking change, but most reasonble implementations should be `Send` already. Please raise an issue if your code fails to build.

- Minimum supported Rust version is now 1.58 ([#977](https://github.com/cossacklabs/themis/pull/977), [#984](https://github.com/cossacklabs/themis/pull/984)).
- Minimum supported Rust version is now 1.60 ([#977](https://github.com/cossacklabs/themis/pull/977), [#984](https://github.com/cossacklabs/themis/pull/984), [#1039](https://github.com/cossacklabs/themis/pull/1039)).

- **WasmThemis**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub fn decryption(c: &mut Criterion) {
|b, &size| {
let message = vec![0; size];
let encrypted = SecureMessage::new(key_pair.clone())
.encrypt(&message)
.encrypt(message)
.expect("failed encryption");

let mut decrypted = vec![0; size];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub fn decryption(c: &mut Criterion) {
|b, &size| {
let message = vec![0; size];
let encrypted = SecureMessage::new(key_pair.clone())
.encrypt(&message)
.encrypt(message)
.expect("failed encryption");

let mut decrypted = vec![0; size];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub fn verification(c: &mut Criterion) {
|b, &size| {
let message = vec![0; size];
let signature = SecureSign::new(private.clone())
.sign(&message)
.sign(message)
.expect("failed signing");

let mut received_message = vec![0; size];
Expand Down
2 changes: 1 addition & 1 deletion benches/themis/benches/secure_message_sign_verify_rsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub fn verification(c: &mut Criterion) {
|b, &size| {
let message = vec![0; size];
let signature = SecureSign::new(private.clone())
.sign(&message)
.sign(message)
.expect("failed signing");

let mut received_message = vec![0; size];
Expand Down
12 changes: 6 additions & 6 deletions docs/examples/rust/secure_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn main() -> themis::Result<()> {

println!("Encoded: {}", base64::encode(&message));

let encrypted_message = scell_mk.encrypt(&message)?;
let encrypted_message = scell_mk.encrypt(message)?;
println!("Encrypted: {}", base64::encode(&encrypted_message));

let decrypted_message = scell_mk.decrypt(&encrypted_message)?;
Expand All @@ -44,11 +44,11 @@ fn main() -> themis::Result<()> {

println!("## Passphrase API");
{
let scell_pw = SecureCell::with_passphrase(&passphrase)?.seal();
let scell_pw = SecureCell::with_passphrase(passphrase)?.seal();

println!("Encoded: {}", base64::encode(&message));

let encrypted_message = scell_pw.encrypt(&message)?;
let encrypted_message = scell_pw.encrypt(message)?;
println!("Encrypted: {}", base64::encode(&encrypted_message));

let decrypted_message = scell_pw.decrypt(&encrypted_message)?;
Expand All @@ -64,7 +64,7 @@ fn main() -> themis::Result<()> {

println!("Encoded: {}", base64::encode(&message));

let (encrypted_message, auth_token) = scell_tp.encrypt(&message)?;
let (encrypted_message, auth_token) = scell_tp.encrypt(message)?;
println!("Encrypted: {}", base64::encode(&encrypted_message));
println!("Auth token: {}", base64::encode(&auth_token));

Expand All @@ -81,10 +81,10 @@ fn main() -> themis::Result<()> {

println!("Encoded: {}", base64::encode(&message));

let encrypted_message = scell_ci.encrypt_with_context(&message, &context)?;
let encrypted_message = scell_ci.encrypt_with_context(message, context)?;
println!("Encrypted: {}", base64::encode(&encrypted_message));

let decrypted_message = scell_ci.decrypt_with_context(&encrypted_message, &context)?;
let decrypted_message = scell_ci.decrypt_with_context(&encrypted_message, context)?;
println!("Decrypted: {}", as_str(&decrypted_message));
assert_eq!(decrypted_message, message);
}
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/rust/secure_message_client_encrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn main() {
let key_pair = KeyPair::try_join(private_key, public_key).expect("matching keys");

let socket = UdpSocket::bind("localhost:0").expect("client socket");
socket.connect(&remote_addr).expect("client connection");
socket.connect(remote_addr).expect("client connection");

let receive_socket = socket;
let relay_socket = receive_socket.try_clone().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/rust/secure_message_client_verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn main() {
let public_key = PublicKey::try_from_slice(public_key).expect("parse public key");

let socket = UdpSocket::bind("localhost:0").expect("client socket");
socket.connect(&remote_addr).expect("client connection");
socket.connect(remote_addr).expect("client connection");

let receive_socket = socket;
let relay_socket = receive_socket.try_clone().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/rust/secure_message_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn main() {
let port = matches.value_of("port").unwrap_or("7573").parse().unwrap();
let listen_addr = SocketAddr::new([0; 16].into(), port);

let socket = UdpSocket::bind(&listen_addr).expect("server listen");
let socket = UdpSocket::bind(listen_addr).expect("server listen");
let mut peers = HashSet::new();
let mut process_message = || -> io::Result<()> {
let (message, sender) = recv_from(&socket)?;
Expand Down
8 changes: 4 additions & 4 deletions docs/examples/rust/secure_session_echo_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ fn main() {

info!("connecting to {:?}", remote_addr);

let mut socket = TcpStream::connect(&remote_addr).expect("client connection");
let mut socket = TcpStream::connect(remote_addr).expect("client connection");

let mut session = SecureSession::new(&CLIENT_ID, &CLIENT_PRIVATE, ExpectServer)
let mut session = SecureSession::new(CLIENT_ID, &CLIENT_PRIVATE, ExpectServer)
.expect("Secure Session client");
let mut buffer = [0; MAX_MESSAGE_SIZE];

Expand All @@ -75,7 +75,7 @@ fn main() {

loop {
let reply = read_framed(&mut socket, &mut buffer).expect("receive reply");
let response = session.negotiate_reply(&reply).expect("negotiate");
let response = session.negotiate_reply(reply).expect("negotiate");
if session.is_established() {
break;
}
Expand All @@ -95,7 +95,7 @@ fn main() {
write_framed(&mut socket, &message).expect("write to socket");

let reply = read_framed(&mut socket, &mut buffer).expect("read from socket");
let reply = session.unwrap(&reply).expect("unwrap incoming");
let reply = session.unwrap(reply).expect("unwrap incoming");

io::stdout().write_all(&reply).expect("write to stdout");
}
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/rust/secure_session_echo_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fn main() {
.expect("valid port");

let listen_addr = SocketAddr::new([0; 16].into(), port);
let listen_socket = TcpListener::bind(&listen_addr).expect("server listen");
let listen_socket = TcpListener::bind(listen_addr).expect("server listen");

info!("listening on port {}", port);

Expand All @@ -123,7 +123,7 @@ fn main() {
info!("{:?}: connected", client_address);

let transport = SocketTransport::new(client);
let mut session = SecureSession::new(&SERVER_ID, &SERVER_PRIVATE, transport)
let mut session = SecureSession::new(SERVER_ID, &SERVER_PRIVATE, transport)
.expect("Secure Session server");

while !session.is_established() {
Expand Down
19 changes: 13 additions & 6 deletions src/wrappers/themis/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "themis"
version = "0.14.0"
edition = "2018"
rust-version = "1.58.0"
rust-version = "1.60.0"
authors = ["rust-themis developers"]
description = "High-level cryptographic services for storage and messaging"
homepage = "https://www.cossacklabs.com/themis/"
Expand All @@ -29,11 +29,18 @@ bindings = { package = "libthemis-sys", path = "libthemis-sys", version = "0.14.
zeroize = "1"

[dev-dependencies]
base64 = "0.10.0"
# Freeze `log` and `byteorder` so that tests still build/run with Rust 1.58.
# Freeze byteorder, log so that tests still build/run with Rust 1.60.
# Other crates are frozen in hope to avoid more problems in future, where something updates
# and requires newer toolchain version compared to what we require for RustThemis.
# FIXME: remove/update strict version requirement after we bump minimum required Rust version
base64 = "=0.10.1"
byteorder = "=1.4.3"
clap = "2.32"
lazy_static = "1.2.0"
clap = "=2.34.0"
lazy_static = "=1.4.0"
log = "=0.4.17"
env_logger = "0.6.0"
env_logger = "=0.6.2"

# These are not used in themis tests, but are rather dependencies of dev-dependencies listed above.
# Specifying exact versions so that tests could build/run on Rust 1.60.
regex = "=1.9.5"
memchr = "=2.6.1"
2 changes: 1 addition & 1 deletion src/wrappers/themis/rust/libthemis-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "libthemis-sys"
version = "0.14.0"
edition = "2018"
rust-version = "1.58.0"
rust-version = "1.60.0"
authors = ["rust-themis developers"]
description = "FFI binding to libthemis"
homepage = "https://www.cossacklabs.com/themis/"
Expand Down
12 changes: 6 additions & 6 deletions src/wrappers/themis/rust/src/secure_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ impl SecureCellSeal {
/// # }
/// ```
pub fn encrypt(&self, message: impl AsRef<[u8]>) -> Result<Vec<u8>> {
self.encrypt_with_context(message, &[])
self.encrypt_with_context(message, [])
}

/// Encrypts the provided message with associated context.
Expand Down Expand Up @@ -501,7 +501,7 @@ impl SecureCellSeal {
/// # }
/// ```
pub fn decrypt(&self, message: impl AsRef<[u8]>) -> Result<Vec<u8>> {
self.decrypt_with_context(message, &[])
self.decrypt_with_context(message, [])
}

/// Decrypts the provided message with associated context.
Expand Down Expand Up @@ -689,7 +689,7 @@ impl SecureCellSealWithPassphrase {
/// # }
/// ```
pub fn encrypt(&self, message: impl AsRef<[u8]>) -> Result<Vec<u8>> {
self.encrypt_with_context(message, &[])
self.encrypt_with_context(message, [])
}

/// Encrypts the provided message with associated context.
Expand Down Expand Up @@ -822,7 +822,7 @@ impl SecureCellSealWithPassphrase {
/// # }
/// ```
pub fn decrypt(&self, message: impl AsRef<[u8]>) -> Result<Vec<u8>> {
self.decrypt_with_context(message, &[])
self.decrypt_with_context(message, [])
}

/// Decrypts the provided message with associated context.
Expand Down Expand Up @@ -1225,7 +1225,7 @@ impl SecureCellTokenProtect {
/// # }
/// ```
pub fn encrypt(&self, message: impl AsRef<[u8]>) -> Result<(Vec<u8>, Vec<u8>)> {
self.encrypt_with_context(message, &[])
self.encrypt_with_context(message, [])
}

/// Encrypts the provided message with associated context.
Expand Down Expand Up @@ -1393,7 +1393,7 @@ impl SecureCellTokenProtect {
/// # }
/// ```
pub fn decrypt(&self, message: impl AsRef<[u8]>, token: impl AsRef<[u8]>) -> Result<Vec<u8>> {
self.decrypt_with_context(message, token, &[])
self.decrypt_with_context(message, token, [])
}

/// Decrypts the provided message with associated context.
Expand Down
8 changes: 4 additions & 4 deletions tests/rust/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ fn parse_generated_keys_back() {

#[test]
fn parse_invalid_buffers() {
let error = EcdsaPublicKey::try_from_slice(&[1, 2, 3]).expect_err("parse failure");
let error = EcdsaPublicKey::try_from_slice([1, 2, 3]).expect_err("parse failure");
assert_eq!(error.kind(), ErrorKind::InvalidParameter);

let error = RsaPrivateKey::try_from_slice(&[]).expect_err("parse failure");
let error = RsaPrivateKey::try_from_slice([]).expect_err("parse failure");
assert_eq!(error.kind(), ErrorKind::InvalidParameter);
}

Expand Down Expand Up @@ -105,6 +105,6 @@ fn parse_generated_symmetric_keys_back() {

#[test]
fn parse_custom_symmetric_keys() {
assert!(SymmetricKey::try_from_slice(&[0]).is_ok());
assert!(SymmetricKey::try_from_slice(&[]).is_err());
assert!(SymmetricKey::try_from_slice([0]).is_ok());
assert!(SymmetricKey::try_from_slice([]).is_err());
}
Loading
Loading