Skip to content

Commit

Permalink
[signalapp#472] make crypto entities and the in-memory stores impl Debug
Browse files Browse the repository at this point in the history
- that allows clients of this library to avoid having to reimplement Debug for the complex in-memory
  stores if they produce their own wrappers around those stores and want to Debug those
  • Loading branch information
cosmicexplorer committed Jul 19, 2022
1 parent b2c39be commit 234b28b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
10 changes: 10 additions & 0 deletions rust/protocol/src/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,16 @@ impl TryFrom<&[u8]> for PrivateKey {
}
}

impl fmt::Debug for PrivateKey {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"PrivateKey {{ public_key_version={:?} }}",
self.public_key().expect("should always have a public key")
)
}
}

#[derive(Copy, Clone)]
pub struct KeyPair {
pub public_key: PublicKey,
Expand Down
4 changes: 2 additions & 2 deletions rust/protocol/src/identity_key.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2020 Signal Messenger, LLC.
// Copyright 2020-2022 Signal Messenger, LLC.
// SPDX-License-Identifier: AGPL-3.0-only
//

Expand Down Expand Up @@ -71,7 +71,7 @@ impl From<IdentityKey> for PublicKey {
}
}

#[derive(Copy, Clone)]
#[derive(Copy, Clone, Debug)]
pub struct IdentityKeyPair {
identity_key: IdentityKey,
private_key: PrivateKey,
Expand Down
12 changes: 6 additions & 6 deletions rust/protocol/src/storage/inmem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::borrow::Cow;
use std::collections::HashMap;
use uuid::Uuid;

#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct InMemIdentityKeyStore {
key_pair: IdentityKeyPair,
id: u32,
Expand Down Expand Up @@ -95,7 +95,7 @@ impl traits::IdentityKeyStore for InMemIdentityKeyStore {
}
}

#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct InMemPreKeyStore {
pre_keys: HashMap<PreKeyId, PreKeyRecord>,
}
Expand Down Expand Up @@ -142,7 +142,7 @@ impl traits::PreKeyStore for InMemPreKeyStore {
}
}

#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct InMemSignedPreKeyStore {
signed_pre_keys: HashMap<SignedPreKeyId, SignedPreKeyRecord>,
}
Expand Down Expand Up @@ -187,7 +187,7 @@ impl traits::SignedPreKeyStore for InMemSignedPreKeyStore {
}
}

#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct InMemSessionStore {
sessions: HashMap<ProtocolAddress, SessionRecord>,
}
Expand Down Expand Up @@ -249,7 +249,7 @@ impl traits::SessionStore for InMemSessionStore {
}
}

#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct InMemSenderKeyStore {
// We use Cow keys in order to store owned values but compare to referenced ones.
// See https://users.rust-lang.org/t/hashmap-with-tuple-keys/12711/6.
Expand Down Expand Up @@ -299,7 +299,7 @@ impl traits::SenderKeyStore for InMemSenderKeyStore {
}
}

#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct InMemSignalProtocolStore {
pub session_store: InMemSessionStore,
pub pre_key_store: InMemPreKeyStore,
Expand Down

0 comments on commit 234b28b

Please sign in to comment.