aboutsummaryrefslogtreecommitdiff
path: root/openssl/src
diff options
context:
space:
mode:
Diffstat (limited to 'openssl/src')
-rw-r--r--openssl/src/crypto/pkey.rs30
-rw-r--r--openssl/src/ssl/mod.rs14
2 files changed, 37 insertions, 7 deletions
diff --git a/openssl/src/crypto/pkey.rs b/openssl/src/crypto/pkey.rs
index 33433b0c..b013e4dd 100644
--- a/openssl/src/crypto/pkey.rs
+++ b/openssl/src/crypto/pkey.rs
@@ -350,6 +350,10 @@ impl PKey {
pub unsafe fn get_handle(&self) -> *mut ffi::EVP_PKEY {
return self.evp
}
+
+ pub fn public_eq(&self, other: &PKey) -> bool {
+ unsafe { ffi::EVP_PKEY_cmp(self.evp, other.evp) == 1 }
+ }
}
impl Drop for PKey {
@@ -373,6 +377,7 @@ mod tests {
k0.gen(512);
k1.load_pub(&k0.save_pub());
assert_eq!(k0.save_pub(), k1.save_pub());
+ assert!(k0.public_eq(&k1));
assert_eq!(k0.size(), k1.size());
assert!(k0.can(super::Role::Encrypt));
assert!(k0.can(super::Role::Decrypt));
@@ -391,6 +396,7 @@ mod tests {
k0.gen(512);
k1.load_priv(&k0.save_priv());
assert_eq!(k0.save_priv(), k1.save_priv());
+ assert!(k0.public_eq(&k1));
assert_eq!(k0.size(), k1.size());
assert!(k0.can(super::Role::Encrypt));
assert!(k0.can(super::Role::Decrypt));
@@ -461,4 +467,28 @@ mod tests {
assert!(k1.verify_with_hash(&msg, &sig, MD5));
assert!(!k1.verify_with_hash(&msg, &sig, SHA1));
}
+
+ #[test]
+ fn test_eq() {
+ let mut k0 = super::PKey::new();
+ let mut p0 = super::PKey::new();
+ let mut k1 = super::PKey::new();
+ let mut p1 = super::PKey::new();
+ k0.gen(512);
+ k1.gen(512);
+ p0.load_pub(&k0.save_pub());
+ p1.load_pub(&k1.save_pub());
+
+ assert!(k0.public_eq(&k0));
+ assert!(k1.public_eq(&k1));
+ assert!(p0.public_eq(&p0));
+ assert!(p1.public_eq(&p1));
+ assert!(k0.public_eq(&p0));
+ assert!(k1.public_eq(&p1));
+
+ assert!(!k0.public_eq(&k1));
+ assert!(!p0.public_eq(&p1));
+ assert!(!k0.public_eq(&p1));
+ assert!(!p0.public_eq(&k1));
+ }
}
diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs
index 13d9572b..17228793 100644
--- a/openssl/src/ssl/mod.rs
+++ b/openssl/src/ssl/mod.rs
@@ -431,8 +431,8 @@ impl SslContext {
#[allow(non_snake_case)]
/// Specifies the file that contains trusted CA certificates.
- pub fn set_CA_file(&mut self, file: &Path) -> Result<(),SslError> {
- let file = CString::new(file.as_os_str().to_str().expect("invalid utf8")).unwrap();
+ pub fn set_CA_file<P: AsRef<Path>>(&mut self, file: P) -> Result<(),SslError> {
+ let file = CString::new(file.as_ref().as_os_str().to_str().expect("invalid utf8")).unwrap();
wrap_ssl_result(
unsafe {
ffi::SSL_CTX_load_verify_locations(self.ctx, file.as_ptr(), ptr::null())
@@ -440,9 +440,9 @@ impl SslContext {
}
/// Specifies the file that contains certificate
- pub fn set_certificate_file(&mut self, file: &Path,
- file_type: X509FileType) -> Result<(),SslError> {
- let file = CString::new(file.as_os_str().to_str().expect("invalid utf8")).unwrap();
+ pub fn set_certificate_file<P: AsRef<Path>>(&mut self, file: P, file_type: X509FileType)
+ -> Result<(),SslError> {
+ let file = CString::new(file.as_ref().as_os_str().to_str().expect("invalid utf8")).unwrap();
wrap_ssl_result(
unsafe {
ffi::SSL_CTX_use_certificate_file(self.ctx, file.as_ptr(), file_type as c_int)
@@ -467,9 +467,9 @@ impl SslContext {
}
/// Specifies the file that contains private key
- pub fn set_private_key_file(&mut self, file: &Path,
+ pub fn set_private_key_file<P: AsRef<Path>>(&mut self, file: P,
file_type: X509FileType) -> Result<(),SslError> {
- let file = CString::new(file.as_os_str().to_str().expect("invalid utf8")).unwrap();
+ let file = CString::new(file.as_ref().as_os_str().to_str().expect("invalid utf8")).unwrap();
wrap_ssl_result(
unsafe {
ffi::SSL_CTX_use_PrivateKey_file(self.ctx, file.as_ptr(), file_type as c_int)