Skip to content

Commit da7f26d

Browse files
committed
fix max_values()
1 parent 864662b commit da7f26d

File tree

15 files changed

+37
-37
lines changed

15 files changed

+37
-37
lines changed

openssl/src/aes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl AesKey {
9595
#[corresponds(AES_set_encrypt_key)]
9696
pub fn new_encrypt(key: &[u8]) -> Result<AesKey, KeyError> {
9797
unsafe {
98-
assert!(key.len() <= c_int::max_value() as usize / 8);
98+
assert!(key.len() <= c_int::MAX as usize / 8);
9999

100100
let mut aes_key = MaybeUninit::uninit();
101101
let r = ffi::AES_set_encrypt_key(
@@ -119,7 +119,7 @@ impl AesKey {
119119
#[corresponds(AES_set_decrypt_key)]
120120
pub fn new_decrypt(key: &[u8]) -> Result<AesKey, KeyError> {
121121
unsafe {
122-
assert!(key.len() <= c_int::max_value() as usize / 8);
122+
assert!(key.len() <= c_int::MAX as usize / 8);
123123

124124
let mut aes_key = MaybeUninit::uninit();
125125
let r = ffi::AES_set_decrypt_key(

openssl/src/base64.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use openssl_macros::corresponds;
1111
/// Panics if the input length or computed output length overflow a signed C integer.
1212
#[corresponds(EVP_EncodeBlock)]
1313
pub fn encode_block(src: &[u8]) -> String {
14-
assert!(src.len() <= c_int::max_value() as usize);
14+
assert!(src.len() <= c_int::MAX as usize);
1515
let src_len = src.len() as LenType;
1616

1717
let len = encoded_len(src_len).unwrap();
@@ -42,7 +42,7 @@ pub fn decode_block(src: &str) -> Result<Vec<u8>, ErrorStack> {
4242
return Ok(vec![]);
4343
}
4444

45-
assert!(src.len() <= c_int::max_value() as usize);
45+
assert!(src.len() <= c_int::MAX as usize);
4646
let src_len = src.len() as LenType;
4747

4848
let len = decoded_len(src_len).unwrap();

openssl/src/bio.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl<'a> MemBioSlice<'a> {
2121
pub fn new(buf: &'a [u8]) -> Result<MemBioSlice<'a>, ErrorStack> {
2222
ffi::init();
2323

24-
assert!(buf.len() <= c_int::max_value() as usize);
24+
assert!(buf.len() <= c_int::MAX as usize);
2525
let bio = unsafe {
2626
cvt_p(BIO_new_mem_buf(
2727
buf.as_ptr() as *const _,

openssl/src/bn.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl BigNumRef {
187187
pub fn div_word(&mut self, w: u32) -> Result<u64, ErrorStack> {
188188
unsafe {
189189
let r = ffi::BN_div_word(self.as_ptr(), w.into());
190-
if r == ffi::BN_ULONG::max_value() {
190+
if r == ffi::BN_ULONG::MAX {
191191
Err(ErrorStack::get())
192192
} else {
193193
Ok(r.into())
@@ -201,7 +201,7 @@ impl BigNumRef {
201201
pub fn mod_word(&self, w: u32) -> Result<u64, ErrorStack> {
202202
unsafe {
203203
let r = ffi::BN_mod_word(self.as_ptr(), w.into());
204-
if r == ffi::BN_ULONG::max_value() {
204+
if r == ffi::BN_ULONG::MAX {
205205
Err(ErrorStack::get())
206206
} else {
207207
Ok(r.into())
@@ -1108,7 +1108,7 @@ impl BigNum {
11081108
pub fn from_slice(n: &[u8]) -> Result<BigNum, ErrorStack> {
11091109
unsafe {
11101110
ffi::init();
1111-
assert!(n.len() <= LenType::max_value() as usize);
1111+
assert!(n.len() <= LenType::MAX as usize);
11121112

11131113
cvt_p(ffi::BN_bin2bn(
11141114
n.as_ptr(),
@@ -1136,7 +1136,7 @@ impl BigNum {
11361136
#[corresponds(BN_bin2bn)]
11371137
pub fn copy_from_slice(&mut self, n: &[u8]) -> Result<(), ErrorStack> {
11381138
unsafe {
1139-
assert!(n.len() <= LenType::max_value() as usize);
1139+
assert!(n.len() <= LenType::MAX as usize);
11401140

11411141
cvt_p(ffi::BN_bin2bn(n.as_ptr(), n.len() as LenType, self.0))?;
11421142
Ok(())

openssl/src/ecdsa.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl EcdsaSig {
3232
T: HasPrivate,
3333
{
3434
unsafe {
35-
assert!(data.len() <= c_int::max_value() as usize);
35+
assert!(data.len() <= c_int::MAX as usize);
3636
let sig = cvt_p(ffi::ECDSA_do_sign(
3737
data.as_ptr(),
3838
data.len() as LenType,
@@ -77,7 +77,7 @@ impl EcdsaSigRef {
7777
T: HasPublic,
7878
{
7979
unsafe {
80-
assert!(data.len() <= c_int::max_value() as usize);
80+
assert!(data.len() <= c_int::MAX as usize);
8181
cvt_n(ffi::ECDSA_do_verify(
8282
data.as_ptr(),
8383
data.len() as LenType,

openssl/src/envelope.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl Seal {
7575
///
7676
/// Panics if `output.len() < input.len() + block_size` where `block_size` is
7777
/// the block size of the cipher (see `Cipher::block_size`), or if
78-
/// `output.len() > c_int::max_value()`.
78+
/// `output.len() > c_int::MAX`.
7979
pub fn update(&mut self, input: &[u8], output: &mut [u8]) -> Result<usize, ErrorStack> {
8080
self.ctx.cipher_update(input, Some(output))
8181
}
@@ -130,7 +130,7 @@ impl Open {
130130
///
131131
/// Panics if `output.len() < input.len() + block_size` where
132132
/// `block_size` is the block size of the cipher (see `Cipher::block_size`),
133-
/// or if `output.len() > c_int::max_value()`.
133+
/// or if `output.len() > c_int::MAX`.
134134
pub fn update(&mut self, input: &[u8], output: &mut [u8]) -> Result<usize, ErrorStack> {
135135
self.ctx.cipher_update(input, Some(output))
136136
}

openssl/src/macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ macro_rules! private_key_to_pem {
5959
) -> Result<Vec<u8>, crate::error::ErrorStack> {
6060
unsafe {
6161
let bio = crate::bio::MemBio::new()?;
62-
assert!(passphrase.len() <= ::libc::c_int::max_value() as usize);
62+
assert!(passphrase.len() <= ::libc::c_int::MAX as usize);
6363
cvt($f(bio.as_ptr(),
6464
self.as_ptr(),
6565
cipher.as_ptr(),
@@ -109,7 +109,7 @@ macro_rules! from_der {
109109
use std::convert::TryInto;
110110
unsafe {
111111
ffi::init();
112-
let len = ::std::cmp::min(der.len(), ::libc::c_long::max_value() as usize) as ::libc::c_long;
112+
let len = ::std::cmp::min(der.len(), ::libc::c_long::MAX as usize) as ::libc::c_long;
113113
crate::cvt_p($f(::std::ptr::null_mut(), &mut der.as_ptr(), len.try_into().unwrap()))
114114
.map(|p| ::foreign_types::ForeignType::from_ptr(p))
115115
}

openssl/src/pkcs5.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub fn bytes_to_key(
3838
count: i32,
3939
) -> Result<KeyIvPair, ErrorStack> {
4040
unsafe {
41-
assert!(data.len() <= c_int::max_value() as usize);
41+
assert!(data.len() <= c_int::MAX as usize);
4242
let salt_ptr = match salt {
4343
Some(salt) => {
4444
assert_eq!(salt.len(), ffi::PKCS5_SALT_LEN as usize);

openssl/src/pkey.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ impl PKey<Private> {
482482
#[cfg(not(boringssl))]
483483
pub fn hmac(key: &[u8]) -> Result<PKey<Private>, ErrorStack> {
484484
unsafe {
485-
assert!(key.len() <= c_int::max_value() as usize);
485+
assert!(key.len() <= c_int::MAX as usize);
486486
let key = cvt_p(ffi::EVP_PKEY_new_mac_key(
487487
ffi::EVP_PKEY_HMAC,
488488
ptr::null_mut(),
@@ -676,7 +676,7 @@ impl PKey<Private> {
676676
pub fn private_key_from_pkcs8(der: &[u8]) -> Result<PKey<Private>, ErrorStack> {
677677
unsafe {
678678
ffi::init();
679-
let len = der.len().min(c_long::max_value() as usize) as c_long;
679+
let len = der.len().min(c_long::MAX as usize) as c_long;
680680
let p8inf = cvt_p(ffi::d2i_PKCS8_PRIV_KEY_INFO(
681681
ptr::null_mut(),
682682
&mut der.as_ptr(),

openssl/src/rand.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use openssl_macros::corresponds;
3232
pub fn rand_bytes(buf: &mut [u8]) -> Result<(), ErrorStack> {
3333
unsafe {
3434
ffi::init();
35-
assert!(buf.len() <= c_int::max_value() as usize);
35+
assert!(buf.len() <= c_int::MAX as usize);
3636
cvt(ffi::RAND_bytes(buf.as_mut_ptr(), buf.len() as LenType)).map(|_| ())
3737
}
3838
}
@@ -57,7 +57,7 @@ pub fn rand_bytes(buf: &mut [u8]) -> Result<(), ErrorStack> {
5757
pub fn rand_priv_bytes(buf: &mut [u8]) -> Result<(), ErrorStack> {
5858
unsafe {
5959
ffi::init();
60-
assert!(buf.len() <= c_int::max_value() as usize);
60+
assert!(buf.len() <= c_int::MAX as usize);
6161
cvt(ffi::RAND_priv_bytes(buf.as_mut_ptr(), buf.len() as LenType)).map(|_| ())
6262
}
6363
}

openssl/src/rsa.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ where
129129
to: &mut [u8],
130130
padding: Padding,
131131
) -> Result<usize, ErrorStack> {
132-
assert!(from.len() <= i32::max_value() as usize);
132+
assert!(from.len() <= i32::MAX as usize);
133133
assert!(to.len() >= self.size() as usize);
134134

135135
unsafe {
@@ -157,7 +157,7 @@ where
157157
to: &mut [u8],
158158
padding: Padding,
159159
) -> Result<usize, ErrorStack> {
160-
assert!(from.len() <= i32::max_value() as usize);
160+
assert!(from.len() <= i32::MAX as usize);
161161
assert!(to.len() >= self.size() as usize);
162162

163163
unsafe {
@@ -301,7 +301,7 @@ where
301301
to: &mut [u8],
302302
padding: Padding,
303303
) -> Result<usize, ErrorStack> {
304-
assert!(from.len() <= i32::max_value() as usize);
304+
assert!(from.len() <= i32::MAX as usize);
305305
assert!(to.len() >= self.size() as usize);
306306

307307
unsafe {
@@ -328,7 +328,7 @@ where
328328
to: &mut [u8],
329329
padding: Padding,
330330
) -> Result<usize, ErrorStack> {
331-
assert!(from.len() <= i32::max_value() as usize);
331+
assert!(from.len() <= i32::MAX as usize);
332332
assert!(to.len() >= self.size() as usize);
333333

334334
unsafe {

openssl/src/ssl/bio.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub unsafe fn get_mut<'a, S: 'a>(bio: *mut BIO) -> &'a mut S {
7272
}
7373

7474
pub unsafe fn set_dtls_mtu_size<S>(bio: *mut BIO, mtu_size: usize) {
75-
if mtu_size as u64 > c_long::max_value() as u64 {
75+
if mtu_size as u64 > c_long::MAX as u64 {
7676
panic!(
7777
"Given MTU size {} can't be represented in a positive `c_long` range",
7878
mtu_size

openssl/src/ssl/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ impl SslContextBuilder {
965965
#[corresponds(SSL_CTX_set_session_id_context)]
966966
pub fn set_session_id_context(&mut self, sid_ctx: &[u8]) -> Result<(), ErrorStack> {
967967
unsafe {
968-
assert!(sid_ctx.len() <= c_uint::max_value() as usize);
968+
assert!(sid_ctx.len() <= c_uint::MAX as usize);
969969
cvt(ffi::SSL_CTX_set_session_id_context(
970970
self.as_ptr(),
971971
sid_ctx.as_ptr(),
@@ -1228,7 +1228,7 @@ impl SslContextBuilder {
12281228
#[cfg(any(ossl102, libressl261, boringssl))]
12291229
pub fn set_alpn_protos(&mut self, protocols: &[u8]) -> Result<(), ErrorStack> {
12301230
unsafe {
1231-
assert!(protocols.len() <= c_uint::max_value() as usize);
1231+
assert!(protocols.len() <= c_uint::MAX as usize);
12321232
let r = ffi::SSL_CTX_set_alpn_protos(
12331233
self.as_ptr(),
12341234
protocols.as_ptr(),
@@ -2487,7 +2487,7 @@ impl SslRef {
24872487
#[cfg(any(ossl102, libressl261, boringssl))]
24882488
pub fn set_alpn_protos(&mut self, protocols: &[u8]) -> Result<(), ErrorStack> {
24892489
unsafe {
2490-
assert!(protocols.len() <= c_uint::max_value() as usize);
2490+
assert!(protocols.len() <= c_uint::MAX as usize);
24912491
let r =
24922492
ffi::SSL_set_alpn_protos(self.as_ptr(), protocols.as_ptr(), protocols.len() as _);
24932493
// fun fact, SSL_set_alpn_protos has a reversed return code D:
@@ -2938,7 +2938,7 @@ impl SslRef {
29382938
#[cfg(not(boringssl))]
29392939
pub fn set_ocsp_status(&mut self, response: &[u8]) -> Result<(), ErrorStack> {
29402940
unsafe {
2941-
assert!(response.len() <= c_int::max_value() as usize);
2941+
assert!(response.len() <= c_int::MAX as usize);
29422942
let p = cvt_p(ffi::OPENSSL_malloc(response.len() as _))?;
29432943
ptr::copy_nonoverlapping(response.as_ptr(), p as *mut u8, response.len());
29442944
cvt(ffi::SSL_set_tlsext_status_ocsp_resp(
@@ -3801,7 +3801,7 @@ impl<S: Read + Write> SslStream<S> {
38013801
return Ok(0);
38023802
}
38033803

3804-
let len = usize::min(c_int::max_value() as usize, buf.len()) as c_int;
3804+
let len = usize::min(c_int::MAX as usize, buf.len()) as c_int;
38053805
let ret = unsafe {
38063806
ffi::SSL_read(self.ssl().as_ptr(), buf.as_mut_ptr().cast(), len)
38073807
};
@@ -3842,7 +3842,7 @@ impl<S: Read + Write> SslStream<S> {
38423842
return Ok(0);
38433843
}
38443844

3845-
let len = usize::min(c_int::max_value() as usize, buf.len()) as c_int;
3845+
let len = usize::min(c_int::MAX as usize, buf.len()) as c_int;
38463846
let ret = unsafe {
38473847
ffi::SSL_write(self.ssl().as_ptr(), buf.as_ptr().cast(), len)
38483848
};
@@ -3880,7 +3880,7 @@ impl<S: Read + Write> SslStream<S> {
38803880
return Ok(0);
38813881
}
38823882

3883-
let len = usize::min(c_int::max_value() as usize, buf.len()) as c_int;
3883+
let len = usize::min(c_int::MAX as usize, buf.len()) as c_int;
38843884
let ret = unsafe {
38853885
ffi::SSL_peek(self.ssl().as_ptr(), buf.as_mut_ptr().cast(), len)
38863886
};

openssl/src/symm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ impl Crypter {
691691
/// Panics for block ciphers if `output.len() < input.len() + block_size`,
692692
/// where `block_size` is the block size of the cipher (see `Cipher::block_size`).
693693
///
694-
/// Panics if `output.len() > c_int::max_value()`.
694+
/// Panics if `output.len() > c_int::MAX`.
695695
pub fn update(&mut self, input: &[u8], output: &mut [u8]) -> Result<usize, ErrorStack> {
696696
self.ctx.cipher_update(input, Some(output))
697697
}

openssl/src/x509/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,7 @@ impl X509NameBuilder {
10931093
pub fn append_entry_by_text(&mut self, field: &str, value: &str) -> Result<(), ErrorStack> {
10941094
unsafe {
10951095
let field = CString::new(field).unwrap();
1096-
assert!(value.len() <= crate::SLenType::max_value() as usize);
1096+
assert!(value.len() <= crate::SLenType::MAX as usize);
10971097
cvt(ffi::X509_NAME_add_entry_by_txt(
10981098
self.0.as_ptr(),
10991099
field.as_ptr() as *mut _,
@@ -1120,7 +1120,7 @@ impl X509NameBuilder {
11201120
) -> Result<(), ErrorStack> {
11211121
unsafe {
11221122
let field = CString::new(field).unwrap();
1123-
assert!(value.len() <= crate::SLenType::max_value() as usize);
1123+
assert!(value.len() <= crate::SLenType::MAX as usize);
11241124
cvt(ffi::X509_NAME_add_entry_by_txt(
11251125
self.0.as_ptr(),
11261126
field.as_ptr() as *mut _,
@@ -1141,7 +1141,7 @@ impl X509NameBuilder {
11411141
/// [`X509_NAME_add_entry_by_NID`]: https://www.openssl.org/docs/manmaster/crypto/X509_NAME_add_entry_by_NID.html
11421142
pub fn append_entry_by_nid(&mut self, field: Nid, value: &str) -> Result<(), ErrorStack> {
11431143
unsafe {
1144-
assert!(value.len() <= crate::SLenType::max_value() as usize);
1144+
assert!(value.len() <= crate::SLenType::MAX as usize);
11451145
cvt(ffi::X509_NAME_add_entry_by_NID(
11461146
self.0.as_ptr(),
11471147
field.as_raw(),
@@ -1167,7 +1167,7 @@ impl X509NameBuilder {
11671167
ty: Asn1Type,
11681168
) -> Result<(), ErrorStack> {
11691169
unsafe {
1170-
assert!(value.len() <= crate::SLenType::max_value() as usize);
1170+
assert!(value.len() <= crate::SLenType::MAX as usize);
11711171
cvt(ffi::X509_NAME_add_entry_by_NID(
11721172
self.0.as_ptr(),
11731173
field.as_raw(),

0 commit comments

Comments
 (0)