Skip to content

Commit 60fc1c7

Browse files
committed
Match Debug traits of keys with what the "boring" crate returns
1 parent ee21a03 commit 60fc1c7

6 files changed

Lines changed: 104 additions & 8 deletions

File tree

src/algorithms/eddsa.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ pub struct Edwards25519KeyPair {
6767
metadata: Option<KeyMetadata>,
6868
}
6969

70+
impl std::fmt::Debug for Edwards25519KeyPair {
71+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
72+
f.debug_struct("PKey").field("algorithm", &"Ed25519").finish()
73+
}
74+
}
75+
7076
impl AsRef<ed25519_compact::KeyPair> for Edwards25519KeyPair {
7177
fn as_ref(&self) -> &ed25519_compact::KeyPair {
7278
&self.ed25519_kp
@@ -235,6 +241,12 @@ pub struct Ed25519KeyPair {
235241
key_id: Option<String>,
236242
}
237243

244+
impl std::fmt::Debug for Ed25519KeyPair {
245+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
246+
f.debug_struct("PKey").field("algorithm", &"Ed25519").finish()
247+
}
248+
}
249+
238250
#[derive(Debug, Clone)]
239251
pub struct Ed25519PublicKey {
240252
pk: Edwards25519PublicKey,

src/algorithms/es256.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ pub struct P256KeyPair {
7474
metadata: Option<KeyMetadata>,
7575
}
7676

77+
impl std::fmt::Debug for P256KeyPair {
78+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
79+
write!(f, "EcKey")
80+
}
81+
}
82+
7783
impl AsRef<ecdsa::SigningKey> for P256KeyPair {
7884
fn as_ref(&self) -> &ecdsa::SigningKey {
7985
&self.p256_sk
@@ -265,6 +271,12 @@ pub struct ES256KeyPair {
265271
key_id: Option<String>,
266272
}
267273

274+
impl std::fmt::Debug for ES256KeyPair {
275+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
276+
write!(f, "EcKey")
277+
}
278+
}
279+
268280
#[derive(Debug, Clone)]
269281
pub struct ES256PublicKey {
270282
pk: P256PublicKey,

src/algorithms/es256k.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ pub struct K256KeyPair {
7373
metadata: Option<KeyMetadata>,
7474
}
7575

76+
impl std::fmt::Debug for K256KeyPair {
77+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
78+
write!(f, "EcKey")
79+
}
80+
}
81+
7682
impl AsRef<ecdsa::SigningKey> for K256KeyPair {
7783
fn as_ref(&self) -> &ecdsa::SigningKey {
7884
&self.k256_sk
@@ -254,6 +260,12 @@ pub struct ES256kKeyPair {
254260
key_id: Option<String>,
255261
}
256262

263+
impl std::fmt::Debug for ES256kKeyPair {
264+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
265+
write!(f, "EcKey")
266+
}
267+
}
268+
257269
#[derive(Debug, Clone)]
258270
pub struct ES256kPublicKey {
259271
pk: K256PublicKey,

src/algorithms/es384.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ pub struct P384KeyPair {
7474
metadata: Option<KeyMetadata>,
7575
}
7676

77+
impl std::fmt::Debug for P384KeyPair {
78+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
79+
write!(f, "EcKey")
80+
}
81+
}
82+
7783
impl AsRef<ecdsa::SigningKey> for P384KeyPair {
7884
fn as_ref(&self) -> &ecdsa::SigningKey {
7985
&self.p384_sk
@@ -265,6 +271,12 @@ pub struct ES384KeyPair {
265271
key_id: Option<String>,
266272
}
267273

274+
impl std::fmt::Debug for ES384KeyPair {
275+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
276+
write!(f, "EcKey")
277+
}
278+
}
279+
268280
#[derive(Debug, Clone)]
269281
pub struct ES384PublicKey {
270282
pk: P384PublicKey,

src/algorithms/hmac.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,18 @@ use crate::jwt_header::*;
1313
use crate::token::*;
1414

1515
#[doc(hidden)]
16-
#[derive(Debug, Clone)]
16+
#[derive(Clone)]
1717
pub struct HMACKey {
1818
raw_key: Vec<u8>,
1919
metadata: Option<KeyMetadata>,
2020
}
2121

22+
impl std::fmt::Debug for HMACKey {
23+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24+
write!(f, "HMACKey")
25+
}
26+
}
27+
2228
impl Drop for HMACKey {
2329
fn drop(&mut self) {
2430
self.raw_key.zeroize();

src/algorithms/rsa.rs

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,18 @@ impl RSAPublicKey {
7676
}
7777

7878
#[doc(hidden)]
79-
#[derive(Debug, Clone)]
79+
#[derive(Clone)]
8080
pub struct RSAKeyPair {
8181
rsa_sk: Rsa<Private>,
8282
metadata: Option<KeyMetadata>,
8383
}
8484

85+
impl std::fmt::Debug for RSAKeyPair {
86+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
87+
write!(f, "Rsa")
88+
}
89+
}
90+
8591
impl AsRef<Rsa<Private>> for RSAKeyPair {
8692
fn as_ref(&self) -> &Rsa<Private> {
8793
&self.rsa_sk
@@ -255,12 +261,18 @@ pub trait RSAPublicKeyLike {
255261
}
256262
}
257263

258-
#[derive(Debug, Clone)]
264+
#[derive(Clone)]
259265
pub struct RS256KeyPair {
260266
key_pair: RSAKeyPair,
261267
key_id: Option<String>,
262268
}
263269

270+
impl std::fmt::Debug for RS256KeyPair {
271+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
272+
write!(f, "Rsa")
273+
}
274+
}
275+
264276
#[derive(Debug, Clone)]
265277
pub struct RS256PublicKey {
266278
pk: RSAPublicKey,
@@ -417,12 +429,18 @@ impl RS256PublicKey {
417429

418430
//
419431

420-
#[derive(Debug, Clone)]
432+
#[derive(Clone)]
421433
pub struct RS512KeyPair {
422434
key_pair: RSAKeyPair,
423435
key_id: Option<String>,
424436
}
425437

438+
impl std::fmt::Debug for RS512KeyPair {
439+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
440+
write!(f, "Rsa")
441+
}
442+
}
443+
426444
#[derive(Debug, Clone)]
427445
pub struct RS512PublicKey {
428446
pk: RSAPublicKey,
@@ -579,12 +597,18 @@ impl RS512PublicKey {
579597

580598
//
581599

582-
#[derive(Debug, Clone)]
600+
#[derive(Clone)]
583601
pub struct RS384KeyPair {
584602
key_pair: RSAKeyPair,
585603
key_id: Option<String>,
586604
}
587605

606+
impl std::fmt::Debug for RS384KeyPair {
607+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
608+
write!(f, "Rsa")
609+
}
610+
}
611+
588612
#[derive(Debug, Clone)]
589613
pub struct RS384PublicKey {
590614
pk: RSAPublicKey,
@@ -741,12 +765,18 @@ impl RS384PublicKey {
741765

742766
//
743767

744-
#[derive(Debug, Clone)]
768+
#[derive(Clone)]
745769
pub struct PS256KeyPair {
746770
key_pair: RSAKeyPair,
747771
key_id: Option<String>,
748772
}
749773

774+
impl std::fmt::Debug for PS256KeyPair {
775+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
776+
write!(f, "Rsa")
777+
}
778+
}
779+
750780
#[derive(Debug, Clone)]
751781
pub struct PS256PublicKey {
752782
pk: RSAPublicKey,
@@ -895,12 +925,18 @@ impl PS256PublicKey {
895925

896926
//
897927

898-
#[derive(Debug, Clone)]
928+
#[derive(Clone)]
899929
pub struct PS512KeyPair {
900930
key_pair: RSAKeyPair,
901931
key_id: Option<String>,
902932
}
903933

934+
impl std::fmt::Debug for PS512KeyPair {
935+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
936+
write!(f, "Rsa")
937+
}
938+
}
939+
904940
#[derive(Debug, Clone)]
905941
pub struct PS512PublicKey {
906942
pk: RSAPublicKey,
@@ -1057,12 +1093,18 @@ impl PS512PublicKey {
10571093

10581094
//
10591095

1060-
#[derive(Debug, Clone)]
1096+
#[derive(Clone)]
10611097
pub struct PS384KeyPair {
10621098
key_pair: RSAKeyPair,
10631099
key_id: Option<String>,
10641100
}
10651101

1102+
impl std::fmt::Debug for PS384KeyPair {
1103+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1104+
write!(f, "Rsa")
1105+
}
1106+
}
1107+
10661108
#[derive(Debug, Clone)]
10671109
pub struct PS384PublicKey {
10681110
pk: RSAPublicKey,

0 commit comments

Comments
 (0)