summaryrefslogtreecommitdiff
path: root/openssl/src/pkey.rs
diff options
context:
space:
mode:
authorJacob Hoffman-Andrews <github@hoffman-andrews.com>2020-05-29 21:34:20 -0700
committerJacob Hoffman-Andrews <github@hoffman-andrews.com>2020-05-30 17:20:55 -0700
commit6482f419b859c146467f06b63fb937dfab5f5caa (patch)
tree31618092100d82c022139bec742a60e8f46d1d76 /openssl/src/pkey.rs
parent7446f9fa683c6c2e173a98125fd5445eae9e481e (diff)
downloadrust-openssl-6482f419b859c146467f06b63fb937dfab5f5caa.zip
Add Debug trait for X509 and other types.
This currently leaves out at least two useful things: - The detailed SubjectPublicKeyInfo, e.g. the modulus of RSA keys. - Extensions.
Diffstat (limited to 'openssl/src/pkey.rs')
-rw-r--r--openssl/src/pkey.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/openssl/src/pkey.rs b/openssl/src/pkey.rs
index 2dfa95c6..7af13c09 100644
--- a/openssl/src/pkey.rs
+++ b/openssl/src/pkey.rs
@@ -49,6 +49,7 @@ use ffi;
use foreign_types::{ForeignType, ForeignTypeRef};
use libc::{c_int, c_long};
use std::ffi::CString;
+use std::fmt;
use std::mem;
use std::ptr;
@@ -286,6 +287,27 @@ where
}
}
+impl<T> fmt::Debug for PKey<T> {
+ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+ let alg = match self.id() {
+ Id::RSA => "RSA",
+ Id::HMAC => "HMAC",
+ Id::DSA => "DSA",
+ Id::DH => "DH",
+ Id::EC => "EC",
+ #[cfg(ossl111)]
+ Id::ED25519 => "Ed25519",
+ #[cfg(ossl111)]
+ Id::ED448 => "Ed448",
+ _ => "unknown",
+ };
+ fmt.debug_struct("public_key")
+ .field("algorithm", &alg)
+ .finish()
+ // TODO: Print details for each specific type of key
+ }
+}
+
impl<T> Clone for PKey<T> {
fn clone(&self) -> PKey<T> {
PKeyRef::to_owned(self)