Cleanup
This commit is contained in:
parent
b5eafedf17
commit
18552f1f1d
|
|
@ -3,10 +3,10 @@
|
|||
//! See manual page of [`EVP_EncodeInit`] for more information on the specific base64 variant.
|
||||
//!
|
||||
//! [`EVP_EncodeInit`]: https://www.openssl.org/docs/man1.1.1/man3/EVP_EncodeInit.html
|
||||
use cvt_n;
|
||||
use error::ErrorStack;
|
||||
use ffi;
|
||||
use libc::c_int;
|
||||
use cvt_n;
|
||||
|
||||
/// Encodes a given block of bytes to base64.
|
||||
///
|
||||
|
|
@ -19,8 +19,7 @@ pub fn encode_block(src: &[u8]) -> String {
|
|||
let src_len = src.len() as c_int;
|
||||
|
||||
let len = encoded_len(src_len).unwrap();
|
||||
let mut out = Vec::new();
|
||||
out.reserve(len as usize);
|
||||
let mut out = Vec::with_capacity(len as usize);
|
||||
|
||||
// SAFETY: `encoded_len` ensures space for 4 output characters
|
||||
// for every 3 input bytes including padding and nul terminator.
|
||||
|
|
@ -46,8 +45,7 @@ pub fn decode_block(src: &str) -> Result<Vec<u8>, ErrorStack> {
|
|||
let src_len = src.len() as c_int;
|
||||
|
||||
let len = decoded_len(src_len).unwrap();
|
||||
let mut out = Vec::new();
|
||||
out.reserve(len as usize);
|
||||
let mut out = Vec::with_capacity(len as usize);
|
||||
|
||||
// SAFETY: `decoded_len` ensures space for 3 output bytes
|
||||
// for every 4 input characters including padding.
|
||||
|
|
@ -55,7 +53,11 @@ pub fn decode_block(src: &str) -> Result<Vec<u8>, ErrorStack> {
|
|||
// leading and trailing whitespace, but never more.
|
||||
// `EVP_DecodeBlock` will only write to not read from `out`.
|
||||
unsafe {
|
||||
let out_len = cvt_n(ffi::EVP_DecodeBlock(out.as_mut_ptr(), src.as_ptr(), src_len))?;
|
||||
let out_len = cvt_n(ffi::EVP_DecodeBlock(
|
||||
out.as_mut_ptr(),
|
||||
src.as_ptr(),
|
||||
src_len,
|
||||
))?;
|
||||
out.set_len(out_len as usize);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue