Skip to content

Commit 876e8d0

Browse files
committed
Update to mem::MaybeUninit and Once::new()
Newest version of rust compiler does not like mem::uninitialized and ONCE_INIT - prefers these versions. Bump minimum version to 1.36.0
1 parent 6218737 commit 876e8d0

File tree

5 files changed

+59
-59
lines changed

5 files changed

+59
-59
lines changed

.circleci/config.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
default: false
2020
image:
2121
type: string
22-
default: 1.33.0
22+
default: 1.41.0
2323
minimal_build:
2424
type: boolean
2525
default: false
@@ -172,7 +172,7 @@ jobs:
172172
default: false
173173
image:
174174
type: string
175-
default: 1.33.0
175+
default: 1.41.0
176176
macos:
177177
xcode: "9.0"
178178
environment:
@@ -224,7 +224,7 @@ workflows:
224224
name: mimimal-version
225225
target: x86_64-unknown-linux-musl
226226
vendored: true
227-
image: 1.31.0
227+
image: 1.36.0
228228
minimal_build: true
229229
- linux:
230230
name: musl-vendored

openssl-sys/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ pub fn init() {
103103
use std::io::{self, Write};
104104
use std::mem;
105105
use std::process;
106-
use std::sync::{Mutex, MutexGuard, Once, ONCE_INIT};
106+
use std::sync::{Mutex, MutexGuard, Once};
107107

108108
static mut MUTEXES: *mut Vec<Mutex<()>> = 0 as *mut Vec<Mutex<()>>;
109109
static mut GUARDS: *mut Vec<Option<MutexGuard<'static, ()>>> =
@@ -147,7 +147,7 @@ pub fn init() {
147147
}
148148
}
149149

150-
static INIT: Once = ONCE_INIT;
150+
static INIT: Once = Once::new();;
151151

152152
INIT.call_once(|| unsafe {
153153
SSL_library_init();

openssl/src/aes.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ impl AesKey {
7878
unsafe {
7979
assert!(key.len() <= c_int::max_value() as usize / 8);
8080

81-
let mut aes_key = mem::uninitialized();
81+
let mut aes_key = mem::MaybeUninit::uninit();
8282
let r = ffi::AES_set_encrypt_key(
8383
key.as_ptr() as *const _,
8484
key.len() as c_int * 8,
85-
&mut aes_key,
85+
aes_key.as_mut_ptr(),
8686
);
8787
if r == 0 {
88-
Ok(AesKey(aes_key))
88+
Ok(AesKey(aes_key.assume_init()))
8989
} else {
9090
Err(KeyError(()))
9191
}
@@ -101,15 +101,15 @@ impl AesKey {
101101
unsafe {
102102
assert!(key.len() <= c_int::max_value() as usize / 8);
103103

104-
let mut aes_key = mem::uninitialized();
104+
let mut aes_key = mem::MaybeUninit::uninit();
105105
let r = ffi::AES_set_decrypt_key(
106106
key.as_ptr() as *const _,
107107
key.len() as c_int * 8,
108-
&mut aes_key,
108+
aes_key.as_mut_ptr(),
109109
);
110110

111111
if r == 0 {
112-
Ok(AesKey(aes_key))
112+
Ok(AesKey(aes_key.assume_init()))
113113
} else {
114114
Err(KeyError(()))
115115
}

openssl/src/sha.rs

+45-45
Original file line numberDiff line numberDiff line change
@@ -58,49 +58,49 @@ use std::mem;
5858
#[inline]
5959
pub fn sha1(data: &[u8]) -> [u8; 20] {
6060
unsafe {
61-
let mut hash: [u8; 20] = mem::uninitialized();
62-
ffi::SHA1(data.as_ptr(), data.len(), hash.as_mut_ptr());
63-
hash
61+
let mut hash: mem::MaybeUninit<[u8; 20]> = mem::MaybeUninit::uninit();
62+
ffi::SHA1(data.as_ptr(), data.len(), hash.as_mut_ptr() as *mut u8);
63+
hash.assume_init()
6464
}
6565
}
6666

6767
/// Computes the SHA224 hash of some data.
6868
#[inline]
6969
pub fn sha224(data: &[u8]) -> [u8; 28] {
7070
unsafe {
71-
let mut hash: [u8; 28] = mem::uninitialized();
72-
ffi::SHA224(data.as_ptr(), data.len(), hash.as_mut_ptr());
73-
hash
71+
let mut hash: mem::MaybeUninit<[u8; 28]> = mem::MaybeUninit::uninit();
72+
ffi::SHA224(data.as_ptr(), data.len(), hash.as_mut_ptr() as *mut u8);
73+
hash.assume_init()
7474
}
7575
}
7676

7777
/// Computes the SHA256 hash of some data.
7878
#[inline]
7979
pub fn sha256(data: &[u8]) -> [u8; 32] {
8080
unsafe {
81-
let mut hash: [u8; 32] = mem::uninitialized();
82-
ffi::SHA256(data.as_ptr(), data.len(), hash.as_mut_ptr());
83-
hash
81+
let mut hash: mem::MaybeUninit<[u8; 32]> = mem::MaybeUninit::uninit();
82+
ffi::SHA256(data.as_ptr(), data.len(), hash.as_mut_ptr() as *mut u8);
83+
hash.assume_init()
8484
}
8585
}
8686

8787
/// Computes the SHA384 hash of some data.
8888
#[inline]
8989
pub fn sha384(data: &[u8]) -> [u8; 48] {
9090
unsafe {
91-
let mut hash: [u8; 48] = mem::uninitialized();
92-
ffi::SHA384(data.as_ptr(), data.len(), hash.as_mut_ptr());
93-
hash
91+
let mut hash: mem::MaybeUninit<[u8; 48]> = mem::MaybeUninit::uninit();
92+
ffi::SHA384(data.as_ptr(), data.len(), hash.as_mut_ptr() as *mut u8);
93+
hash.assume_init()
9494
}
9595
}
9696

9797
/// Computes the SHA512 hash of some data.
9898
#[inline]
9999
pub fn sha512(data: &[u8]) -> [u8; 64] {
100100
unsafe {
101-
let mut hash: [u8; 64] = mem::uninitialized();
102-
ffi::SHA512(data.as_ptr(), data.len(), hash.as_mut_ptr());
103-
hash
101+
let mut hash: mem::MaybeUninit<[u8; 64]> = mem::MaybeUninit::uninit();
102+
ffi::SHA512(data.as_ptr(), data.len(), hash.as_mut_ptr() as *mut u8);
103+
hash.assume_init()
104104
}
105105
}
106106

@@ -118,9 +118,9 @@ impl Sha1 {
118118
#[inline]
119119
pub fn new() -> Sha1 {
120120
unsafe {
121-
let mut ctx = mem::uninitialized();
122-
ffi::SHA1_Init(&mut ctx);
123-
Sha1(ctx)
121+
let mut ctx: mem::MaybeUninit<ffi::SHA_CTX> = mem::MaybeUninit::uninit();
122+
ffi::SHA1_Init(ctx.as_mut_ptr());
123+
Sha1(ctx.assume_init())
124124
}
125125
}
126126

@@ -138,9 +138,9 @@ impl Sha1 {
138138
#[inline]
139139
pub fn finish(mut self) -> [u8; 20] {
140140
unsafe {
141-
let mut hash: [u8; 20] = mem::uninitialized();
142-
ffi::SHA1_Final(hash.as_mut_ptr(), &mut self.0);
143-
hash
141+
let mut hash: mem::MaybeUninit<[u8; 20]> = mem::MaybeUninit::uninit();
142+
ffi::SHA1_Final(hash.as_mut_ptr() as *mut u8, &mut self.0);
143+
hash.assume_init()
144144
}
145145
}
146146
}
@@ -154,9 +154,9 @@ impl Sha224 {
154154
#[inline]
155155
pub fn new() -> Sha224 {
156156
unsafe {
157-
let mut ctx = mem::uninitialized();
158-
ffi::SHA224_Init(&mut ctx);
159-
Sha224(ctx)
157+
let mut ctx: mem::MaybeUninit<ffi::SHA256_CTX> = mem::MaybeUninit::uninit();
158+
ffi::SHA224_Init(ctx.as_mut_ptr());
159+
Sha224(ctx.assume_init())
160160
}
161161
}
162162

@@ -174,9 +174,9 @@ impl Sha224 {
174174
#[inline]
175175
pub fn finish(mut self) -> [u8; 28] {
176176
unsafe {
177-
let mut hash: [u8; 28] = mem::uninitialized();
178-
ffi::SHA224_Final(hash.as_mut_ptr(), &mut self.0);
179-
hash
177+
let mut hash: mem::MaybeUninit<[u8; 28]> = mem::MaybeUninit::uninit();
178+
ffi::SHA224_Final(hash.as_mut_ptr() as *mut u8, &mut self.0);
179+
hash.assume_init()
180180
}
181181
}
182182
}
@@ -190,9 +190,9 @@ impl Sha256 {
190190
#[inline]
191191
pub fn new() -> Sha256 {
192192
unsafe {
193-
let mut ctx = mem::uninitialized();
194-
ffi::SHA256_Init(&mut ctx);
195-
Sha256(ctx)
193+
let mut ctx: mem::MaybeUninit<ffi::SHA256_CTX> = mem::MaybeUninit::uninit();
194+
ffi::SHA256_Init(ctx.as_mut_ptr());
195+
Sha256(ctx.assume_init())
196196
}
197197
}
198198

@@ -210,9 +210,9 @@ impl Sha256 {
210210
#[inline]
211211
pub fn finish(mut self) -> [u8; 32] {
212212
unsafe {
213-
let mut hash: [u8; 32] = mem::uninitialized();
214-
ffi::SHA256_Final(hash.as_mut_ptr(), &mut self.0);
215-
hash
213+
let mut hash: mem::MaybeUninit<[u8; 32]> = mem::MaybeUninit::uninit();
214+
ffi::SHA256_Final(hash.as_mut_ptr() as *mut u8, &mut self.0);
215+
hash.assume_init()
216216
}
217217
}
218218
}
@@ -226,9 +226,9 @@ impl Sha384 {
226226
#[inline]
227227
pub fn new() -> Sha384 {
228228
unsafe {
229-
let mut ctx = mem::uninitialized();
230-
ffi::SHA384_Init(&mut ctx);
231-
Sha384(ctx)
229+
let mut ctx: mem::MaybeUninit<ffi::SHA512_CTX> = mem::MaybeUninit::uninit();
230+
ffi::SHA384_Init(ctx.as_mut_ptr());
231+
Sha384(ctx.assume_init())
232232
}
233233
}
234234

@@ -246,9 +246,9 @@ impl Sha384 {
246246
#[inline]
247247
pub fn finish(mut self) -> [u8; 48] {
248248
unsafe {
249-
let mut hash: [u8; 48] = mem::uninitialized();
250-
ffi::SHA384_Final(hash.as_mut_ptr(), &mut self.0);
251-
hash
249+
let mut hash: mem::MaybeUninit<[u8; 48]> = mem::MaybeUninit::uninit();
250+
ffi::SHA384_Final(hash.as_mut_ptr() as *mut u8, &mut self.0);
251+
hash.assume_init()
252252
}
253253
}
254254
}
@@ -262,9 +262,9 @@ impl Sha512 {
262262
#[inline]
263263
pub fn new() -> Sha512 {
264264
unsafe {
265-
let mut ctx = mem::uninitialized();
266-
ffi::SHA512_Init(&mut ctx);
267-
Sha512(ctx)
265+
let mut ctx: mem::MaybeUninit<ffi::SHA512_CTX> = mem::MaybeUninit::uninit();
266+
ffi::SHA512_Init(ctx.as_mut_ptr());
267+
Sha512(ctx.assume_init())
268268
}
269269
}
270270

@@ -282,9 +282,9 @@ impl Sha512 {
282282
#[inline]
283283
pub fn finish(mut self) -> [u8; 64] {
284284
unsafe {
285-
let mut hash: [u8; 64] = mem::uninitialized();
286-
ffi::SHA512_Final(hash.as_mut_ptr(), &mut self.0);
287-
hash
285+
let mut hash: mem::MaybeUninit<[u8; 64]> = mem::MaybeUninit::uninit();
286+
ffi::SHA512_Final(hash.as_mut_ptr() as *mut u8, &mut self.0);
287+
hash.assume_init()
288288
}
289289
}
290290
}

openssl/src/ssl/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3928,11 +3928,11 @@ cfg_if! {
39283928
)
39293929
}
39303930
} else {
3931-
use std::sync::{Once, ONCE_INIT};
3931+
use std::sync::Once;
39323932

39333933
unsafe fn get_new_idx(f: ffi::CRYPTO_EX_free) -> c_int {
39343934
// hack around https://rt.openssl.org/Ticket/Display.html?id=3710&user=guest&pass=guest
3935-
static ONCE: Once = ONCE_INIT;
3935+
static ONCE: Once = Once::new();
39363936
ONCE.call_once(|| {
39373937
ffi::SSL_CTX_get_ex_new_index(0, ptr::null_mut(), None, None, None);
39383938
});
@@ -3942,7 +3942,7 @@ cfg_if! {
39423942

39433943
unsafe fn get_new_ssl_idx(f: ffi::CRYPTO_EX_free) -> c_int {
39443944
// hack around https://rt.openssl.org/Ticket/Display.html?id=3710&user=guest&pass=guest
3945-
static ONCE: Once = ONCE_INIT;
3945+
static ONCE: Once = Once::new();
39463946
ONCE.call_once(|| {
39473947
ffi::SSL_get_ex_new_index(0, ptr::null_mut(), None, None, None);
39483948
});

0 commit comments

Comments
 (0)