Merge pull request #1184 from Atul9/cargo-fmt
Format code using 'cargo fmt'
This commit is contained in:
commit
f85d631fcf
|
|
@ -4,7 +4,10 @@ use std::path::PathBuf;
|
||||||
pub fn get_openssl(_target: &str) -> (PathBuf, PathBuf) {
|
pub fn get_openssl(_target: &str) -> (PathBuf, PathBuf) {
|
||||||
let artifacts = openssl_src::Build::new().build();
|
let artifacts = openssl_src::Build::new().build();
|
||||||
println!("cargo:vendored=1");
|
println!("cargo:vendored=1");
|
||||||
println!("cargo:root={}", artifacts.lib_dir().parent().unwrap().display());
|
println!(
|
||||||
|
"cargo:root={}",
|
||||||
|
artifacts.lib_dir().parent().unwrap().display()
|
||||||
|
);
|
||||||
|
|
||||||
(
|
(
|
||||||
artifacts.lib_dir().to_path_buf(),
|
artifacts.lib_dir().to_path_buf(),
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
|
extern crate autocfg;
|
||||||
extern crate cc;
|
extern crate cc;
|
||||||
#[cfg(feature = "vendored")]
|
#[cfg(feature = "vendored")]
|
||||||
extern crate openssl_src;
|
extern crate openssl_src;
|
||||||
extern crate pkg_config;
|
extern crate pkg_config;
|
||||||
extern crate autocfg;
|
|
||||||
#[cfg(target_env = "msvc")]
|
#[cfg(target_env = "msvc")]
|
||||||
extern crate vcpkg;
|
extern crate vcpkg;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,12 @@ extern "C" {
|
||||||
pub fn ASN1_GENERALIZEDTIME_print(b: *mut BIO, tm: *const ASN1_GENERALIZEDTIME) -> c_int;
|
pub fn ASN1_GENERALIZEDTIME_print(b: *mut BIO, tm: *const ASN1_GENERALIZEDTIME) -> c_int;
|
||||||
pub fn ASN1_TIME_new() -> *mut ASN1_TIME;
|
pub fn ASN1_TIME_new() -> *mut ASN1_TIME;
|
||||||
#[cfg(ossl102)]
|
#[cfg(ossl102)]
|
||||||
pub fn ASN1_TIME_diff(pday: *mut c_int, psec: *mut c_int, from: *const ASN1_TIME, to: *const ASN1_TIME) -> c_int;
|
pub fn ASN1_TIME_diff(
|
||||||
|
pday: *mut c_int,
|
||||||
|
psec: *mut c_int,
|
||||||
|
from: *const ASN1_TIME,
|
||||||
|
to: *const ASN1_TIME,
|
||||||
|
) -> c_int;
|
||||||
pub fn ASN1_TIME_free(tm: *mut ASN1_TIME);
|
pub fn ASN1_TIME_free(tm: *mut ASN1_TIME);
|
||||||
pub fn ASN1_TIME_print(b: *mut BIO, tm: *const ASN1_TIME) -> c_int;
|
pub fn ASN1_TIME_print(b: *mut BIO, tm: *const ASN1_TIME) -> c_int;
|
||||||
pub fn ASN1_TIME_set(from: *mut ASN1_TIME, to: time_t) -> *mut ASN1_TIME;
|
pub fn ASN1_TIME_set(from: *mut ASN1_TIME, to: time_t) -> *mut ASN1_TIME;
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,11 @@ extern "C" {
|
||||||
pub fn i2d_CMS_ContentInfo(a: *mut ::CMS_ContentInfo, pp: *mut *mut c_uchar) -> c_int;
|
pub fn i2d_CMS_ContentInfo(a: *mut ::CMS_ContentInfo, pp: *mut *mut c_uchar) -> c_int;
|
||||||
|
|
||||||
#[cfg(ossl101)]
|
#[cfg(ossl101)]
|
||||||
pub fn d2i_CMS_ContentInfo(a: *mut *mut ::CMS_ContentInfo, pp: *mut *const c_uchar, length: c_long) -> *mut ::CMS_ContentInfo;
|
pub fn d2i_CMS_ContentInfo(
|
||||||
|
a: *mut *mut ::CMS_ContentInfo,
|
||||||
|
pp: *mut *const c_uchar,
|
||||||
|
length: c_long,
|
||||||
|
) -> *mut ::CMS_ContentInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(ossl101)]
|
#[cfg(ossl101)]
|
||||||
|
|
@ -76,7 +80,7 @@ extern "C" {
|
||||||
certs: *mut stack_st_X509,
|
certs: *mut stack_st_X509,
|
||||||
data: *mut ::BIO,
|
data: *mut ::BIO,
|
||||||
cipher: *const EVP_CIPHER,
|
cipher: *const EVP_CIPHER,
|
||||||
flags: c_uint
|
flags: c_uint,
|
||||||
) -> *mut ::CMS_ContentInfo;
|
) -> *mut ::CMS_ContentInfo;
|
||||||
|
|
||||||
#[cfg(ossl101)]
|
#[cfg(ossl101)]
|
||||||
|
|
|
||||||
|
|
@ -85,10 +85,7 @@ extern "C" {
|
||||||
|
|
||||||
pub fn EC_POINT_free(point: *mut EC_POINT);
|
pub fn EC_POINT_free(point: *mut EC_POINT);
|
||||||
|
|
||||||
pub fn EC_POINT_dup(
|
pub fn EC_POINT_dup(p: *const EC_POINT, group: *const EC_GROUP) -> *mut EC_POINT;
|
||||||
p: *const EC_POINT,
|
|
||||||
group: *const EC_GROUP,
|
|
||||||
) -> *mut EC_POINT;
|
|
||||||
|
|
||||||
pub fn EC_POINT_get_affine_coordinates_GFp(
|
pub fn EC_POINT_get_affine_coordinates_GFp(
|
||||||
group: *const EC_GROUP,
|
group: *const EC_GROUP,
|
||||||
|
|
|
||||||
|
|
@ -180,7 +180,8 @@ pub fn wrap_key(
|
||||||
|
|
||||||
let written = ffi::AES_wrap_key(
|
let written = ffi::AES_wrap_key(
|
||||||
&key.0 as *const _ as *mut _, // this is safe, the implementation only uses the key as a const pointer.
|
&key.0 as *const _ as *mut _, // this is safe, the implementation only uses the key as a const pointer.
|
||||||
iv.as_ref().map_or(ptr::null(), |iv| iv.as_ptr() as *const _),
|
iv.as_ref()
|
||||||
|
.map_or(ptr::null(), |iv| iv.as_ptr() as *const _),
|
||||||
out.as_ptr() as *mut _,
|
out.as_ptr() as *mut _,
|
||||||
in_.as_ptr() as *const _,
|
in_.as_ptr() as *const _,
|
||||||
in_.len() as c_uint,
|
in_.len() as c_uint,
|
||||||
|
|
@ -217,7 +218,8 @@ pub fn unwrap_key(
|
||||||
|
|
||||||
let written = ffi::AES_unwrap_key(
|
let written = ffi::AES_unwrap_key(
|
||||||
&key.0 as *const _ as *mut _, // this is safe, the implementation only uses the key as a const pointer.
|
&key.0 as *const _ as *mut _, // this is safe, the implementation only uses the key as a const pointer.
|
||||||
iv.as_ref().map_or(ptr::null(), |iv| iv.as_ptr() as *const _),
|
iv.as_ref()
|
||||||
|
.map_or(ptr::null(), |iv| iv.as_ptr() as *const _),
|
||||||
out.as_ptr() as *mut _,
|
out.as_ptr() as *mut _,
|
||||||
in_.as_ptr() as *const _,
|
in_.as_ptr() as *const _,
|
||||||
in_.len() as c_uint,
|
in_.len() as c_uint,
|
||||||
|
|
@ -286,5 +288,4 @@ mod test {
|
||||||
);
|
);
|
||||||
assert_eq!(&unwrapped[..], &key_data[..]);
|
assert_eq!(&unwrapped[..], &key_data[..]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -127,9 +127,7 @@ impl Asn1TimeRef {
|
||||||
let mut seconds = 0;
|
let mut seconds = 0;
|
||||||
let other = compare.as_ptr();
|
let other = compare.as_ptr();
|
||||||
|
|
||||||
let err = unsafe {
|
let err = unsafe { ffi::ASN1_TIME_diff(&mut days, &mut seconds, self.as_ptr(), other) };
|
||||||
ffi::ASN1_TIME_diff(&mut days, &mut seconds, self.as_ptr(), other)
|
|
||||||
};
|
|
||||||
|
|
||||||
match err {
|
match err {
|
||||||
0 => Err(ErrorStack::get()),
|
0 => Err(ErrorStack::get()),
|
||||||
|
|
@ -164,21 +162,27 @@ impl Asn1TimeRef {
|
||||||
#[cfg(ossl102)]
|
#[cfg(ossl102)]
|
||||||
impl PartialEq for Asn1TimeRef {
|
impl PartialEq for Asn1TimeRef {
|
||||||
fn eq(&self, other: &Asn1TimeRef) -> bool {
|
fn eq(&self, other: &Asn1TimeRef) -> bool {
|
||||||
self.diff(other).map(|t| t.days == 0 && t.secs == 0).unwrap_or(false)
|
self.diff(other)
|
||||||
|
.map(|t| t.days == 0 && t.secs == 0)
|
||||||
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(ossl102)]
|
#[cfg(ossl102)]
|
||||||
impl PartialEq<Asn1Time> for Asn1TimeRef {
|
impl PartialEq<Asn1Time> for Asn1TimeRef {
|
||||||
fn eq(&self, other: &Asn1Time) -> bool {
|
fn eq(&self, other: &Asn1Time) -> bool {
|
||||||
self.diff(other).map(|t| t.days == 0 && t.secs == 0).unwrap_or(false)
|
self.diff(other)
|
||||||
|
.map(|t| t.days == 0 && t.secs == 0)
|
||||||
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(ossl102)]
|
#[cfg(ossl102)]
|
||||||
impl<'a> PartialEq<Asn1Time> for &'a Asn1TimeRef {
|
impl<'a> PartialEq<Asn1Time> for &'a Asn1TimeRef {
|
||||||
fn eq(&self, other: &Asn1Time) -> bool {
|
fn eq(&self, other: &Asn1Time) -> bool {
|
||||||
self.diff(other).map(|t| t.days == 0 && t.secs == 0).unwrap_or(false)
|
self.diff(other)
|
||||||
|
.map(|t| t.days == 0 && t.secs == 0)
|
||||||
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -286,21 +290,27 @@ impl Asn1Time {
|
||||||
#[cfg(ossl102)]
|
#[cfg(ossl102)]
|
||||||
impl PartialEq for Asn1Time {
|
impl PartialEq for Asn1Time {
|
||||||
fn eq(&self, other: &Asn1Time) -> bool {
|
fn eq(&self, other: &Asn1Time) -> bool {
|
||||||
self.diff(other).map(|t| t.days == 0 && t.secs == 0).unwrap_or(false)
|
self.diff(other)
|
||||||
|
.map(|t| t.days == 0 && t.secs == 0)
|
||||||
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(ossl102)]
|
#[cfg(ossl102)]
|
||||||
impl PartialEq<Asn1TimeRef> for Asn1Time {
|
impl PartialEq<Asn1TimeRef> for Asn1Time {
|
||||||
fn eq(&self, other: &Asn1TimeRef) -> bool {
|
fn eq(&self, other: &Asn1TimeRef) -> bool {
|
||||||
self.diff(other).map(|t| t.days == 0 && t.secs == 0).unwrap_or(false)
|
self.diff(other)
|
||||||
|
.map(|t| t.days == 0 && t.secs == 0)
|
||||||
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(ossl102)]
|
#[cfg(ossl102)]
|
||||||
impl<'a> PartialEq<&'a Asn1TimeRef> for Asn1Time {
|
impl<'a> PartialEq<&'a Asn1TimeRef> for Asn1Time {
|
||||||
fn eq(&self, other: & &'a Asn1TimeRef) -> bool {
|
fn eq(&self, other: &&'a Asn1TimeRef) -> bool {
|
||||||
self.diff(other).map(|t| t.days == 0 && t.secs == 0).unwrap_or(false)
|
self.diff(other)
|
||||||
|
.map(|t| t.days == 0 && t.secs == 0)
|
||||||
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,8 @@ use error::ErrorStack;
|
||||||
use libc::c_uint;
|
use libc::c_uint;
|
||||||
use pkey::{HasPrivate, PKeyRef};
|
use pkey::{HasPrivate, PKeyRef};
|
||||||
use stack::StackRef;
|
use stack::StackRef;
|
||||||
use x509::{X509Ref, X509};
|
|
||||||
use symm::Cipher;
|
use symm::Cipher;
|
||||||
|
use x509::{X509Ref, X509};
|
||||||
use {cvt, cvt_p};
|
use {cvt, cvt_p};
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
|
|
@ -206,8 +206,7 @@ impl CmsContentInfo {
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
cipher: Cipher,
|
cipher: Cipher,
|
||||||
flags: CMSOptions,
|
flags: CMSOptions,
|
||||||
) -> Result<CmsContentInfo, ErrorStack>
|
) -> Result<CmsContentInfo, ErrorStack> {
|
||||||
{
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let data_bio = MemBioSlice::new(data)?;
|
let data_bio = MemBioSlice::new(data)?;
|
||||||
|
|
||||||
|
|
@ -226,9 +225,9 @@ impl CmsContentInfo {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use pkcs12::Pkcs12;
|
||||||
use stack::Stack;
|
use stack::Stack;
|
||||||
use x509::X509;
|
use x509::X509;
|
||||||
use pkcs12::Pkcs12;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn cms_encrypt_decrypt() {
|
fn cms_encrypt_decrypt() {
|
||||||
|
|
@ -239,31 +238,48 @@ mod test {
|
||||||
// load cert with private key
|
// load cert with private key
|
||||||
let priv_cert_bytes = include_bytes!("../test/cms.p12");
|
let priv_cert_bytes = include_bytes!("../test/cms.p12");
|
||||||
let priv_cert = Pkcs12::from_der(priv_cert_bytes).expect("failed to load priv cert");
|
let priv_cert = Pkcs12::from_der(priv_cert_bytes).expect("failed to load priv cert");
|
||||||
let priv_cert = priv_cert.parse("mypass").expect("failed to parse priv cert");
|
let priv_cert = priv_cert
|
||||||
|
.parse("mypass")
|
||||||
|
.expect("failed to parse priv cert");
|
||||||
|
|
||||||
// encrypt cms message using public key cert
|
// encrypt cms message using public key cert
|
||||||
let input = String::from("My Message");
|
let input = String::from("My Message");
|
||||||
let mut cert_stack = Stack::new().expect("failed to create stack");
|
let mut cert_stack = Stack::new().expect("failed to create stack");
|
||||||
cert_stack.push(pub_cert).expect("failed to add pub cert to stack");
|
cert_stack
|
||||||
|
.push(pub_cert)
|
||||||
|
.expect("failed to add pub cert to stack");
|
||||||
|
|
||||||
let encrypt = CmsContentInfo::encrypt(&cert_stack, &input.as_bytes(), Cipher::des_ede3_cbc(), CMSOptions::empty())
|
let encrypt = CmsContentInfo::encrypt(
|
||||||
|
&cert_stack,
|
||||||
|
&input.as_bytes(),
|
||||||
|
Cipher::des_ede3_cbc(),
|
||||||
|
CMSOptions::empty(),
|
||||||
|
)
|
||||||
.expect("failed create encrypted cms");
|
.expect("failed create encrypted cms");
|
||||||
|
|
||||||
// decrypt cms message using private key cert (DER)
|
// decrypt cms message using private key cert (DER)
|
||||||
{
|
{
|
||||||
let encrypted_der = encrypt.to_der().expect("failed to create der from cms");
|
let encrypted_der = encrypt.to_der().expect("failed to create der from cms");
|
||||||
let decrypt = CmsContentInfo::from_der(&encrypted_der).expect("failed read cms from der");
|
let decrypt =
|
||||||
let decrypt = decrypt.decrypt(&priv_cert.pkey, &priv_cert.cert).expect("failed to decrypt cms");
|
CmsContentInfo::from_der(&encrypted_der).expect("failed read cms from der");
|
||||||
let decrypt = String::from_utf8(decrypt).expect("failed to create string from cms content");
|
let decrypt = decrypt
|
||||||
|
.decrypt(&priv_cert.pkey, &priv_cert.cert)
|
||||||
|
.expect("failed to decrypt cms");
|
||||||
|
let decrypt =
|
||||||
|
String::from_utf8(decrypt).expect("failed to create string from cms content");
|
||||||
assert_eq!(input, decrypt);
|
assert_eq!(input, decrypt);
|
||||||
}
|
}
|
||||||
|
|
||||||
// decrypt cms message using private key cert (PEM)
|
// decrypt cms message using private key cert (PEM)
|
||||||
{
|
{
|
||||||
let encrypted_pem = encrypt.to_pem().expect("failed to create pem from cms");
|
let encrypted_pem = encrypt.to_pem().expect("failed to create pem from cms");
|
||||||
let decrypt = CmsContentInfo::from_pem(&encrypted_pem).expect("failed read cms from pem");
|
let decrypt =
|
||||||
let decrypt = decrypt.decrypt(&priv_cert.pkey, &priv_cert.cert).expect("failed to decrypt cms");
|
CmsContentInfo::from_pem(&encrypted_pem).expect("failed read cms from pem");
|
||||||
let decrypt = String::from_utf8(decrypt).expect("failed to create string from cms content");
|
let decrypt = decrypt
|
||||||
|
.decrypt(&priv_cert.pkey, &priv_cert.cert)
|
||||||
|
.expect("failed to decrypt cms");
|
||||||
|
let decrypt =
|
||||||
|
String::from_utf8(decrypt).expect("failed to create string from cms content");
|
||||||
assert_eq!(input, decrypt);
|
assert_eq!(input, decrypt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -288,7 +288,11 @@ impl EcGroupRef {
|
||||||
/// [`EC_GROUP_get_curve_name`]: https://www.openssl.org/docs/man1.1.0/crypto/EC_GROUP_get_curve_name.html
|
/// [`EC_GROUP_get_curve_name`]: https://www.openssl.org/docs/man1.1.0/crypto/EC_GROUP_get_curve_name.html
|
||||||
pub fn curve_name(&self) -> Option<Nid> {
|
pub fn curve_name(&self) -> Option<Nid> {
|
||||||
let nid = unsafe { ffi::EC_GROUP_get_curve_name(self.as_ptr()) };
|
let nid = unsafe { ffi::EC_GROUP_get_curve_name(self.as_ptr()) };
|
||||||
if nid > 0 { Some(Nid::from_raw(nid)) } else { None }
|
if nid > 0 {
|
||||||
|
Some(Nid::from_raw(nid))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -461,13 +465,8 @@ impl EcPointRef {
|
||||||
/// OpenSSL documentation at [`EC_POINT_dup`]
|
/// OpenSSL documentation at [`EC_POINT_dup`]
|
||||||
///
|
///
|
||||||
/// [`EC_POINT_dup`]: https://www.openssl.org/docs/man1.1.0/crypto/EC_POINT_dup.html
|
/// [`EC_POINT_dup`]: https://www.openssl.org/docs/man1.1.0/crypto/EC_POINT_dup.html
|
||||||
pub fn to_owned(
|
pub fn to_owned(&self, group: &EcGroupRef) -> Result<EcPoint, ErrorStack> {
|
||||||
&self,
|
unsafe { cvt_p(ffi::EC_POINT_dup(self.as_ptr(), group.as_ptr())).map(EcPoint) }
|
||||||
group: &EcGroupRef,
|
|
||||||
) -> Result<EcPoint, ErrorStack> {
|
|
||||||
unsafe {
|
|
||||||
cvt_p(ffi::EC_POINT_dup(self.as_ptr(), group.as_ptr())).map(EcPoint)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Determines if this point is equal to another.
|
/// Determines if this point is equal to another.
|
||||||
|
|
|
||||||
|
|
@ -305,7 +305,7 @@ impl<'a> Signer<'a> {
|
||||||
ptr::null_mut(),
|
ptr::null_mut(),
|
||||||
&mut len,
|
&mut len,
|
||||||
ptr::null(),
|
ptr::null(),
|
||||||
0
|
0,
|
||||||
))?;
|
))?;
|
||||||
Ok(len)
|
Ok(len)
|
||||||
}
|
}
|
||||||
|
|
@ -362,7 +362,7 @@ impl<'a> Signer<'a> {
|
||||||
sig_buf.as_mut_ptr() as *mut _,
|
sig_buf.as_mut_ptr() as *mut _,
|
||||||
&mut sig_len,
|
&mut sig_len,
|
||||||
data_buf.as_ptr() as *const _,
|
data_buf.as_ptr() as *const _,
|
||||||
data_buf.len()
|
data_buf.len(),
|
||||||
))?;
|
))?;
|
||||||
Ok(sig_len)
|
Ok(sig_len)
|
||||||
}
|
}
|
||||||
|
|
@ -436,13 +436,15 @@ impl<'a> Verifier<'a> {
|
||||||
/// [`EVP_DigestVerifyInit`]: https://www.openssl.org/docs/manmaster/man3/EVP_DigestVerifyInit.html
|
/// [`EVP_DigestVerifyInit`]: https://www.openssl.org/docs/manmaster/man3/EVP_DigestVerifyInit.html
|
||||||
pub fn new_without_digest<T>(pkey: &'a PKeyRef<T>) -> Result<Verifier<'a>, ErrorStack>
|
pub fn new_without_digest<T>(pkey: &'a PKeyRef<T>) -> Result<Verifier<'a>, ErrorStack>
|
||||||
where
|
where
|
||||||
T: HasPublic
|
T: HasPublic,
|
||||||
{
|
{
|
||||||
Verifier::new_intern(None, pkey)
|
Verifier::new_intern(None, pkey)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn new_intern<T>(
|
||||||
fn new_intern<T>(type_: Option<MessageDigest>, pkey: &'a PKeyRef<T>) -> Result<Verifier<'a>, ErrorStack>
|
type_: Option<MessageDigest>,
|
||||||
|
pkey: &'a PKeyRef<T>,
|
||||||
|
) -> Result<Verifier<'a>, ErrorStack>
|
||||||
where
|
where
|
||||||
T: HasPublic,
|
T: HasPublic,
|
||||||
{
|
{
|
||||||
|
|
@ -596,7 +598,7 @@ impl<'a> Verifier<'a> {
|
||||||
0 => {
|
0 => {
|
||||||
ErrorStack::get();
|
ErrorStack::get();
|
||||||
Ok(false)
|
Ok(false)
|
||||||
},
|
}
|
||||||
_ => Err(ErrorStack::get()),
|
_ => Err(ErrorStack::get()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,10 @@ use pkey::Params;
|
||||||
use ssl::AlpnError;
|
use ssl::AlpnError;
|
||||||
#[cfg(ossl111)]
|
#[cfg(ossl111)]
|
||||||
use ssl::{ClientHelloResponse, ExtensionContext};
|
use ssl::{ClientHelloResponse, ExtensionContext};
|
||||||
use ssl::{SniError, Ssl, SslAlert, SslContext, SslContextRef, SslRef, SslSession, SslSessionRef, SESSION_CTX_INDEX};
|
use ssl::{
|
||||||
|
SniError, Ssl, SslAlert, SslContext, SslContextRef, SslRef, SslSession, SslSessionRef,
|
||||||
|
SESSION_CTX_INDEX,
|
||||||
|
};
|
||||||
#[cfg(ossl111)]
|
#[cfg(ossl111)]
|
||||||
use x509::X509Ref;
|
use x509::X509Ref;
|
||||||
use x509::{X509StoreContext, X509StoreContextRef};
|
use x509::{X509StoreContext, X509StoreContextRef};
|
||||||
|
|
|
||||||
|
|
@ -544,7 +544,11 @@ impl Crypter {
|
||||||
/// Panics if `output.len() > c_int::max_value()`.
|
/// Panics if `output.len() > c_int::max_value()`.
|
||||||
pub fn update(&mut self, input: &[u8], output: &mut [u8]) -> Result<usize, ErrorStack> {
|
pub fn update(&mut self, input: &[u8], output: &mut [u8]) -> Result<usize, ErrorStack> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let block_size = if self.block_size > 1 { self.block_size } else { 0 };
|
let block_size = if self.block_size > 1 {
|
||||||
|
self.block_size
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
};
|
||||||
assert!(output.len() >= input.len() + block_size);
|
assert!(output.len() >= input.len() + block_size);
|
||||||
assert!(output.len() <= c_int::max_value() as usize);
|
assert!(output.len() <= c_int::max_value() as usize);
|
||||||
let mut outl = output.len() as c_int;
|
let mut outl = output.len() as c_int;
|
||||||
|
|
@ -575,7 +579,9 @@ impl Crypter {
|
||||||
/// where `block_size` is the block size of the cipher (see `Cipher::block_size`).
|
/// where `block_size` is the block size of the cipher (see `Cipher::block_size`).
|
||||||
pub fn finalize(&mut self, output: &mut [u8]) -> Result<usize, ErrorStack> {
|
pub fn finalize(&mut self, output: &mut [u8]) -> Result<usize, ErrorStack> {
|
||||||
unsafe {
|
unsafe {
|
||||||
if self.block_size > 1 { assert!(output.len() >= self.block_size); }
|
if self.block_size > 1 {
|
||||||
|
assert!(output.len() >= self.block_size);
|
||||||
|
}
|
||||||
let mut outl = cmp::min(output.len(), c_int::max_value() as usize) as c_int;
|
let mut outl = cmp::min(output.len(), c_int::max_value() as usize) as c_int;
|
||||||
|
|
||||||
cvt(ffi::EVP_CipherFinal(
|
cvt(ffi::EVP_CipherFinal(
|
||||||
|
|
@ -811,7 +817,8 @@ mod tests {
|
||||||
super::Mode::Encrypt,
|
super::Mode::Encrypt,
|
||||||
&key,
|
&key,
|
||||||
Some(&iv),
|
Some(&iv),
|
||||||
).unwrap();
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(c.update(&[0u8; 15], &mut [0u8; 15]).unwrap(), 15);
|
assert_eq!(c.update(&[0u8; 15], &mut [0u8; 15]).unwrap(), 15);
|
||||||
assert_eq!(c.update(&[0u8; 1], &mut [0u8; 1]).unwrap(), 1);
|
assert_eq!(c.update(&[0u8; 1], &mut [0u8; 1]).unwrap(), 1);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue