Skip to content

Commit 96ae6b7

Browse files
committed
Added openssl 1.x compatibility
1 parent 5fe61ac commit 96ae6b7

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

snx-rs/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ libc = "0.2"
2020
tracing-subscriber = "0.3"
2121
clap = { version = "4.5.4", features = ["derive"] }
2222
ipnet = { version = "2", features = ["serde"] }
23+
openssl-sys = "0.9"
2324
openssl = "0.10"
2425

2526
[features]

snx-rs/build.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn main() {
2+
if let Ok(v) = std::env::var("DEP_OPENSSL_VERSION_NUMBER") {
3+
let version = u64::from_str_radix(&v, 16).unwrap();
4+
if version >= 0x3000_0000 {
5+
println!("cargo:rustc-cfg=openssl3");
6+
}
7+
}
8+
}

snx-rs/src/main.rs

+18-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
use std::{
2-
collections::VecDeque,
3-
future::Future,
4-
sync::{Arc, OnceLock},
5-
};
1+
#![allow(unexpected_cfgs)]
2+
3+
use std::{collections::VecDeque, future::Future, sync::Arc};
64

75
use anyhow::anyhow;
86
use clap::Parser;
97
use futures::pin_mut;
10-
use openssl::provider::Provider;
118
use tokio::{
129
signal::unix,
1310
sync::{mpsc, oneshot},
@@ -61,6 +58,20 @@ where
6158
}
6259
}
6360

61+
fn init_openssl() {
62+
#[cfg(openssl3)]
63+
{
64+
use openssl::provider::Provider;
65+
use std::sync::OnceLock;
66+
67+
static LEGACY_PROVIDER: OnceLock<Provider> = OnceLock::new();
68+
69+
if let Ok(provider) = Provider::try_load(None, "legacy", true) {
70+
let _ = LEGACY_PROVIDER.set(provider);
71+
}
72+
}
73+
}
74+
6475
#[tokio::main]
6576
async fn main() -> anyhow::Result<()> {
6677
let cmdline_params = CmdlineParams::parse();
@@ -69,11 +80,7 @@ async fn main() -> anyhow::Result<()> {
6980
return Err(anyhow!("Please run me as a root user!"));
7081
}
7182

72-
static LEGACY_PROVIDER: OnceLock<Provider> = OnceLock::new();
73-
74-
if let Ok(provider) = Provider::try_load(None, "legacy", true) {
75-
let _ = LEGACY_PROVIDER.set(provider);
76-
}
83+
init_openssl();
7784

7885
let mode = cmdline_params.mode;
7986

0 commit comments

Comments
 (0)