mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-26 16:21:39 +00:00
Provides a debug instance for an RSA public key... (#1421)
* Provides a debug instance for an RSA public key... that is a bit easier on the eyes than the raw Vec<u8> * Move to_hex into the fmt method PR feedback * Remove to_hex altogether
This commit is contained in:
@ -26,7 +26,7 @@ use super::error::*;
|
|||||||
use ring::rand::SystemRandom;
|
use ring::rand::SystemRandom;
|
||||||
use ring::signature::{self, RsaKeyPair, RSA_PKCS1_SHA256, RSA_PKCS1_2048_8192_SHA256};
|
use ring::signature::{self, RsaKeyPair, RSA_PKCS1_SHA256, RSA_PKCS1_2048_8192_SHA256};
|
||||||
use ring::signature::KeyPair;
|
use ring::signature::KeyPair;
|
||||||
use std::sync::Arc;
|
use std::{fmt::{self, Write}, sync::Arc};
|
||||||
use zeroize::Zeroize;
|
use zeroize::Zeroize;
|
||||||
|
|
||||||
/// An RSA keypair.
|
/// An RSA keypair.
|
||||||
@ -62,7 +62,7 @@ impl Keypair {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// An RSA public key.
|
/// An RSA public key.
|
||||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
#[derive(Clone, PartialEq, Eq)]
|
||||||
pub struct PublicKey(Vec<u8>);
|
pub struct PublicKey(Vec<u8>);
|
||||||
|
|
||||||
impl PublicKey {
|
impl PublicKey {
|
||||||
@ -107,6 +107,21 @@ impl PublicKey {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for PublicKey {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
let bytes = &self.0;
|
||||||
|
let mut hex = String::with_capacity(bytes.len() * 2);
|
||||||
|
|
||||||
|
for byte in bytes {
|
||||||
|
write!(hex, "{:02x}", byte).expect("Can't fail on writing to string");
|
||||||
|
}
|
||||||
|
|
||||||
|
f.debug_struct("PublicKey")
|
||||||
|
.field("pkcs1", &hex)
|
||||||
|
.finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
// DER encoding / decoding of public keys
|
// DER encoding / decoding of public keys
|
||||||
//
|
//
|
||||||
|
Reference in New Issue
Block a user