Loading openssl/src/base64.rs +8 −6 Original line number Diff line number Diff line Loading @@ -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. /// Loading @@ -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. Loading @@ -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. Loading @@ -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 Loading
openssl/src/base64.rs +8 −6 Original line number Diff line number Diff line Loading @@ -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. /// Loading @@ -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. Loading @@ -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. Loading @@ -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