Skip to content

Commit 61a277c

Browse files
Rust wrapper: Use core::ptr instead of std::ptr
1 parent b75be94 commit 61a277c

5 files changed

Lines changed: 23 additions & 28 deletions

File tree

wrapper/rust/wolfssl/src/wolfcrypt/aes.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ the raw C functions in a memory-safe and easy-to-use Rust API.
2727
*/
2828

2929
use std::mem::{size_of, MaybeUninit};
30-
use std::ptr::{null, null_mut};
3130
use wolfssl_sys as ws;
3231

3332
/// AES Cipher Block Chaining (CBC) mode.
@@ -989,7 +988,7 @@ impl ECB {
989988
let key_size = key.len() as u32;
990989
let rc = unsafe {
991990
ws::wc_AesSetKey(&mut self.ws_aes, key_ptr, key_size,
992-
null(), dir)
991+
core::ptr::null(), dir)
993992
};
994993
if rc != 0 {
995994
return Err(rc);
@@ -2357,7 +2356,7 @@ impl Drop for XTSStream {
23572356
fn new_ws_aes() -> Result<ws::Aes, i32> {
23582357
let mut ws_aes: MaybeUninit<ws::Aes> = MaybeUninit::uninit();
23592358
let rc = unsafe {
2360-
ws::wc_AesInit(ws_aes.as_mut_ptr(), null_mut(), ws::INVALID_DEVID)
2359+
ws::wc_AesInit(ws_aes.as_mut_ptr(), core::ptr::null_mut(), ws::INVALID_DEVID)
23612360
};
23622361
if rc != 0 {
23632362
return Err(rc);
@@ -2369,7 +2368,7 @@ fn new_ws_aes() -> Result<ws::Aes, i32> {
23692368
fn new_ws_xtsaes() -> Result<ws::XtsAes, i32> {
23702369
let mut ws_xtsaes: MaybeUninit<ws::XtsAes> = MaybeUninit::uninit();
23712370
let rc = unsafe {
2372-
ws::wc_AesXtsInit(ws_xtsaes.as_mut_ptr(), null_mut(), ws::INVALID_DEVID)
2371+
ws::wc_AesXtsInit(ws_xtsaes.as_mut_ptr(), core::ptr::null_mut(), ws::INVALID_DEVID)
23732372
};
23742373
if rc != 0 {
23752374
return Err(rc);

wrapper/rust/wolfssl/src/wolfcrypt/dh.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ wolfSSL `DhKey` object. It ensures proper initialization and deallocation.
3232
use wolfssl_sys as ws;
3333

3434
use std::mem::{MaybeUninit};
35-
use std::ptr::null;
3635
use crate::wolfcrypt::random::RNG;
3736

3837
pub struct DH {
@@ -138,7 +137,7 @@ impl DH {
138137
let p_size = p.len() as u32;
139138
let g_size = g.len() as u32;
140139
let mut no_q = 1i32;
141-
let mut q_ptr: *const u8 = null();
140+
let mut q_ptr: *const u8 = core::ptr::null();
142141
let mut q_size = 0u32;
143142
if let Some(q) = q {
144143
no_q = 0;
@@ -791,7 +790,7 @@ impl DH {
791790
/// ```
792791
pub fn check_priv_key_ex(&mut self, private: &[u8], prime: Option<&[u8]>) -> Result<(), i32> {
793792
let private_size = private.len() as u32;
794-
let mut prime_ptr: *const u8 = null();
793+
let mut prime_ptr: *const u8 = core::ptr::null();
795794
let mut prime_size = 0u32;
796795
if let Some(prime) = prime {
797796
prime_ptr = prime.as_ptr();

wrapper/rust/wolfssl/src/wolfcrypt/ecc.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ wolfSSL `ecc_key` object. It ensures proper initialization and deallocation.
3232
use wolfssl_sys as ws;
3333

3434
use std::mem::{MaybeUninit};
35-
use std::ptr::null_mut;
3635
use crate::wolfcrypt::random::RNG;
3736

3837
/// Rust wrapper for wolfSSL `ecc_point` object.
@@ -1339,10 +1338,10 @@ impl ECC {
13391338
pub fn make_pub(&mut self, rng: Option<&mut RNG>) -> Result<(), i32> {
13401339
let rng_ptr = match rng {
13411340
Some(rng) => &mut rng.wc_rng,
1342-
None => null_mut(),
1341+
None => core::ptr::null_mut(),
13431342
};
13441343
let rc = unsafe {
1345-
ws::wc_ecc_make_pub_ex(&mut self.wc_ecc_key, null_mut(), rng_ptr)
1344+
ws::wc_ecc_make_pub_ex(&mut self.wc_ecc_key, core::ptr::null_mut(), rng_ptr)
13461345
};
13471346
if rc != 0 {
13481347
return Err(rc);
@@ -1377,7 +1376,7 @@ impl ECC {
13771376
pub fn make_pub_to_point(&mut self, rng: Option<&mut RNG>) -> Result<ECCPoint, i32> {
13781377
let rng_ptr = match rng {
13791378
Some(rng) => &mut rng.wc_rng,
1380-
None => null_mut(),
1379+
None => core::ptr::null_mut(),
13811380
};
13821381
let wc_ecc_point = unsafe { ws::wc_ecc_new_point() };
13831382
if wc_ecc_point.is_null() {

wrapper/rust/wolfssl/src/wolfcrypt/rsa.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ assert_eq!(plain_out[0..dec_len], *plain);
5959
use wolfssl_sys as ws;
6060

6161
use std::mem::{MaybeUninit};
62-
use std::ptr::{null_mut};
6362
use crate::wolfcrypt::random::RNG;
6463

6564
/// The `RSA` struct manages the lifecycle of a wolfSSL `RsaKey` object.
@@ -146,7 +145,7 @@ impl RSA {
146145
/// ```
147146
pub fn new_from_der(der: &[u8]) -> Result<Self, i32> {
148147
let mut wc_rsakey: MaybeUninit<ws::RsaKey> = MaybeUninit::uninit();
149-
let rc = unsafe { ws::wc_InitRsaKey(wc_rsakey.as_mut_ptr(), null_mut()) };
148+
let rc = unsafe { ws::wc_InitRsaKey(wc_rsakey.as_mut_ptr(), core::ptr::null_mut()) };
150149
if rc != 0 {
151150
return Err(rc);
152151
}
@@ -200,7 +199,7 @@ impl RSA {
200199
/// ```
201200
pub fn new_public_from_der(der: &[u8]) -> Result<Self, i32> {
202201
let mut wc_rsakey: MaybeUninit<ws::RsaKey> = MaybeUninit::uninit();
203-
let rc = unsafe { ws::wc_InitRsaKey(wc_rsakey.as_mut_ptr(), null_mut()) };
202+
let rc = unsafe { ws::wc_InitRsaKey(wc_rsakey.as_mut_ptr(), core::ptr::null_mut()) };
204203
if rc != 0 {
205204
return Err(rc);
206205
}
@@ -257,7 +256,7 @@ impl RSA {
257256
/// ```
258257
pub fn generate(size: i32, e: i64, rng: &mut RNG) -> Result<Self, i32> {
259258
let mut wc_rsakey: MaybeUninit<ws::RsaKey> = MaybeUninit::uninit();
260-
let rc = unsafe { ws::wc_InitRsaKey(wc_rsakey.as_mut_ptr(), null_mut()) };
259+
let rc = unsafe { ws::wc_InitRsaKey(wc_rsakey.as_mut_ptr(), core::ptr::null_mut()) };
261260
if rc != 0 {
262261
return Err(rc);
263262
}

wrapper/rust/wolfssl/src/wolfcrypt/sha.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ the raw C functions in a memory-safe and easy-to-use Rust API.
2929
use wolfssl_sys as ws;
3030

3131
use std::mem::MaybeUninit;
32-
use std::ptr::null_mut;
3332

3433
/// Context for SHA-1 computation.
3534
pub struct SHA {
@@ -730,7 +729,7 @@ impl SHA3_224 {
730729
/// ```
731730
pub fn new() -> Result<Self, i32> {
732731
let mut wc_sha3: MaybeUninit<ws::wc_Sha3> = MaybeUninit::uninit();
733-
let rc = unsafe { ws::wc_InitSha3_224(wc_sha3.as_mut_ptr(), null_mut(), ws::INVALID_DEVID) };
732+
let rc = unsafe { ws::wc_InitSha3_224(wc_sha3.as_mut_ptr(), core::ptr::null_mut(), ws::INVALID_DEVID) };
734733
if rc != 0 {
735734
return Err(rc);
736735
}
@@ -757,7 +756,7 @@ impl SHA3_224 {
757756
/// sha.init().expect("Error with init()");
758757
/// ```
759758
pub fn init(&mut self) -> Result<(), i32> {
760-
let rc = unsafe { ws::wc_InitSha3_224(&mut self.wc_sha3, null_mut(), ws::INVALID_DEVID) };
759+
let rc = unsafe { ws::wc_InitSha3_224(&mut self.wc_sha3, core::ptr::null_mut(), ws::INVALID_DEVID) };
761760
if rc != 0 {
762761
return Err(rc);
763762
}
@@ -865,7 +864,7 @@ impl SHA3_256 {
865864
/// ```
866865
pub fn new() -> Result<Self, i32> {
867866
let mut wc_sha3: MaybeUninit<ws::wc_Sha3> = MaybeUninit::uninit();
868-
let rc = unsafe { ws::wc_InitSha3_256(wc_sha3.as_mut_ptr(), null_mut(), ws::INVALID_DEVID) };
867+
let rc = unsafe { ws::wc_InitSha3_256(wc_sha3.as_mut_ptr(), core::ptr::null_mut(), ws::INVALID_DEVID) };
869868
if rc != 0 {
870869
return Err(rc);
871870
}
@@ -892,7 +891,7 @@ impl SHA3_256 {
892891
/// sha.init().expect("Error with init()");
893892
/// ```
894893
pub fn init(&mut self) -> Result<(), i32> {
895-
let rc = unsafe { ws::wc_InitSha3_256(&mut self.wc_sha3, null_mut(), ws::INVALID_DEVID) };
894+
let rc = unsafe { ws::wc_InitSha3_256(&mut self.wc_sha3, core::ptr::null_mut(), ws::INVALID_DEVID) };
896895
if rc != 0 {
897896
return Err(rc);
898897
}
@@ -1000,7 +999,7 @@ impl SHA3_384 {
1000999
/// ```
10011000
pub fn new() -> Result<Self, i32> {
10021001
let mut wc_sha3: MaybeUninit<ws::wc_Sha3> = MaybeUninit::uninit();
1003-
let rc = unsafe { ws::wc_InitSha3_384(wc_sha3.as_mut_ptr(), null_mut(), ws::INVALID_DEVID) };
1002+
let rc = unsafe { ws::wc_InitSha3_384(wc_sha3.as_mut_ptr(), core::ptr::null_mut(), ws::INVALID_DEVID) };
10041003
if rc != 0 {
10051004
return Err(rc);
10061005
}
@@ -1027,7 +1026,7 @@ impl SHA3_384 {
10271026
/// sha.init().expect("Error with init()");
10281027
/// ```
10291028
pub fn init(&mut self) -> Result<(), i32> {
1030-
let rc = unsafe { ws::wc_InitSha3_384(&mut self.wc_sha3, null_mut(), ws::INVALID_DEVID) };
1029+
let rc = unsafe { ws::wc_InitSha3_384(&mut self.wc_sha3, core::ptr::null_mut(), ws::INVALID_DEVID) };
10311030
if rc != 0 {
10321031
return Err(rc);
10331032
}
@@ -1135,7 +1134,7 @@ impl SHA3_512 {
11351134
/// ```
11361135
pub fn new() -> Result<Self, i32> {
11371136
let mut wc_sha3: MaybeUninit<ws::wc_Sha3> = MaybeUninit::uninit();
1138-
let rc = unsafe { ws::wc_InitSha3_512(wc_sha3.as_mut_ptr(), null_mut(), ws::INVALID_DEVID) };
1137+
let rc = unsafe { ws::wc_InitSha3_512(wc_sha3.as_mut_ptr(), core::ptr::null_mut(), ws::INVALID_DEVID) };
11391138
if rc != 0 {
11401139
return Err(rc);
11411140
}
@@ -1162,7 +1161,7 @@ impl SHA3_512 {
11621161
/// sha.init().expect("Error with init()");
11631162
/// ```
11641163
pub fn init(&mut self) -> Result<(), i32> {
1165-
let rc = unsafe { ws::wc_InitSha3_512(&mut self.wc_sha3, null_mut(), ws::INVALID_DEVID) };
1164+
let rc = unsafe { ws::wc_InitSha3_512(&mut self.wc_sha3, core::ptr::null_mut(), ws::INVALID_DEVID) };
11661165
if rc != 0 {
11671166
return Err(rc);
11681167
}
@@ -1270,7 +1269,7 @@ impl SHAKE128 {
12701269
/// ```
12711270
pub fn new() -> Result<Self, i32> {
12721271
let mut wc_shake: MaybeUninit<ws::wc_Shake> = MaybeUninit::uninit();
1273-
let rc = unsafe { ws::wc_InitShake128(wc_shake.as_mut_ptr(), null_mut(), ws::INVALID_DEVID) };
1272+
let rc = unsafe { ws::wc_InitShake128(wc_shake.as_mut_ptr(), core::ptr::null_mut(), ws::INVALID_DEVID) };
12741273
if rc != 0 {
12751274
return Err(rc);
12761275
}
@@ -1297,7 +1296,7 @@ impl SHAKE128 {
12971296
/// sha.init().expect("Error with init()");
12981297
/// ```
12991298
pub fn init(&mut self) -> Result<(), i32> {
1300-
let rc = unsafe { ws::wc_InitShake128(&mut self.wc_shake, null_mut(), ws::INVALID_DEVID) };
1299+
let rc = unsafe { ws::wc_InitShake128(&mut self.wc_shake, core::ptr::null_mut(), ws::INVALID_DEVID) };
13011300
if rc != 0 {
13021301
return Err(rc);
13031302
}
@@ -1468,7 +1467,7 @@ impl SHAKE256 {
14681467
/// ```
14691468
pub fn new() -> Result<Self, i32> {
14701469
let mut wc_shake: MaybeUninit<ws::wc_Shake> = MaybeUninit::uninit();
1471-
let rc = unsafe { ws::wc_InitShake256(wc_shake.as_mut_ptr(), null_mut(), ws::INVALID_DEVID) };
1470+
let rc = unsafe { ws::wc_InitShake256(wc_shake.as_mut_ptr(), core::ptr::null_mut(), ws::INVALID_DEVID) };
14721471
if rc != 0 {
14731472
return Err(rc);
14741473
}
@@ -1495,7 +1494,7 @@ impl SHAKE256 {
14951494
/// sha.init().expect("Error with init()");
14961495
/// ```
14971496
pub fn init(&mut self) -> Result<(), i32> {
1498-
let rc = unsafe { ws::wc_InitShake256(&mut self.wc_shake, null_mut(), ws::INVALID_DEVID) };
1497+
let rc = unsafe { ws::wc_InitShake256(&mut self.wc_shake, core::ptr::null_mut(), ws::INVALID_DEVID) };
14991498
if rc != 0 {
15001499
return Err(rc);
15011500
}

0 commit comments

Comments
 (0)