aboutsummaryrefslogtreecommitdiff
path: root/openssl/src/x509/mod.rs
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2017-12-31 10:21:23 -0800
committerGitHub <[email protected]>2017-12-31 10:21:23 -0800
commitd3fff74ae8ab092a77050ba210b942e86c3bd9ff (patch)
treef5646108131916584291141407696ef894f2ff1e /openssl/src/x509/mod.rs
parentMerge pull request #809 from sfackler/issuer-name (diff)
parentParameterize keys over what they contain (diff)
downloadrust-openssl-d3fff74ae8ab092a77050ba210b942e86c3bd9ff.tar.xz
rust-openssl-d3fff74ae8ab092a77050ba210b942e86c3bd9ff.zip
Merge pull request #810 from sfackler/key-tag
Parameterize keys over what they contain
Diffstat (limited to 'openssl/src/x509/mod.rs')
-rw-r--r--openssl/src/x509/mod.rs24
1 files changed, 18 insertions, 6 deletions
diff --git a/openssl/src/x509/mod.rs b/openssl/src/x509/mod.rs
index 52becf10..9491afce 100644
--- a/openssl/src/x509/mod.rs
+++ b/openssl/src/x509/mod.rs
@@ -19,7 +19,7 @@ use error::ErrorStack;
use ex_data::Index;
use hash::MessageDigest;
use nid::Nid;
-use pkey::{PKey, PKeyRef};
+use pkey::{HasPrivate, HasPublic, PKey, PKeyRef, Public};
use stack::{Stack, StackRef, Stackable};
use string::OpensslString;
use ssl::SslRef;
@@ -196,7 +196,10 @@ impl X509Builder {
}
/// Sets the public key associated with the certificate.
- pub fn set_pubkey(&mut self, key: &PKeyRef) -> Result<(), ErrorStack> {
+ pub fn set_pubkey<T>(&mut self, key: &PKeyRef<T>) -> Result<(), ErrorStack>
+ where
+ T: HasPublic,
+ {
unsafe { cvt(ffi::X509_set_pubkey(self.0.as_ptr(), key.as_ptr())).map(|_| ()) }
}
@@ -244,7 +247,10 @@ impl X509Builder {
}
/// Signs the certificate with a private key.
- pub fn sign(&mut self, key: &PKeyRef, hash: MessageDigest) -> Result<(), ErrorStack> {
+ pub fn sign<T>(&mut self, key: &PKeyRef<T>, hash: MessageDigest) -> Result<(), ErrorStack>
+ where
+ T: HasPrivate,
+ {
unsafe { cvt(ffi::X509_sign(self.0.as_ptr(), key.as_ptr(), hash.as_ptr())).map(|_| ()) }
}
@@ -331,7 +337,7 @@ impl X509Ref {
}
}
- pub fn public_key(&self) -> Result<PKey, ErrorStack> {
+ pub fn public_key(&self) -> Result<PKey<Public>, ErrorStack> {
unsafe {
let pkey = cvt_p(ffi::X509_get_pubkey(self.as_ptr()))?;
Ok(PKey::from_ptr(pkey))
@@ -700,7 +706,10 @@ impl X509ReqBuilder {
}
}
- pub fn set_pubkey(&mut self, key: &PKeyRef) -> Result<(), ErrorStack> {
+ pub fn set_pubkey<T>(&mut self, key: &PKeyRef<T>) -> Result<(), ErrorStack>
+ where
+ T: HasPublic,
+ {
unsafe { cvt(ffi::X509_REQ_set_pubkey(self.0.as_ptr(), key.as_ptr())).map(|_| ()) }
}
@@ -738,7 +747,10 @@ impl X509ReqBuilder {
}
}
- pub fn sign(&mut self, key: &PKeyRef, hash: MessageDigest) -> Result<(), ErrorStack> {
+ pub fn sign<T>(&mut self, key: &PKeyRef<T>, hash: MessageDigest) -> Result<(), ErrorStack>
+ where
+ T: HasPrivate,
+ {
unsafe {
cvt(ffi::X509_REQ_sign(
self.0.as_ptr(),