Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Debug for (ed25519/secp256k1)::(Keypair|SecretKey) #1285

Merged
merged 2 commits into from
Oct 28, 2019

Conversation

c410-f3r
Copy link
Contributor

Sidenote: I see a bunch of deprecated functions, Rust 2015 stuff and std::mem::uninitialized. Is anyone going to update this project?

@tomaka
Copy link
Member

tomaka commented Oct 23, 2019

We preferably don't want secret keys to be accidentally printed on stdout, ever.
If we are to implement Debug, let's have a dummy manual implementation instead.

@c410-f3r
Copy link
Contributor Author

c410-f3r commented Oct 23, 2019

@tomaka SecretKey and Keypair now have a manual Debug implementation that hides the private key content.

I never had the change to tell this but I would like thank you for all the awesome work you did for Rust, specially in the gaming ecosystem

@@ -51,6 +52,12 @@ impl Keypair {
}
}

impl fmt::Debug for Keypair {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Keypair {{ secret: \"Secret Key\", public: \"{:?}\" }}", &self.public)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Formatter has helpers for outputting structs:

Suggested change
write!(f, "Keypair {{ secret: \"Secret Key\", public: \"{:?}\" }}", &self.public)
f.debug_struct("Keypair").field("public", &self.public).finish()

@@ -135,6 +146,12 @@ impl Clone for SecretKey {
}
}

impl fmt::Debug for SecretKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Secret Key")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
write!(f, "Secret Key")
write!(f, "SecretKey")

@@ -70,6 +77,12 @@ impl From<Keypair> for SecretKey {
#[derive(Clone)]
pub struct SecretKey(secp256k1::SecretKey);

impl fmt::Debug for SecretKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Secret Key")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
write!(f, "Secret Key")
write!(f, "SecretKey")

@@ -66,6 +67,16 @@ impl Keypair {
}
}

impl fmt::Debug for Keypair {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
write!(
f.debug_struct("Keypair").field("public", &self.0.public).finish()

@tomaka
Copy link
Member

tomaka commented Oct 24, 2019

I never had the change to tell this but I would like thank you for all the awesome work you did for Rust, specially in the gaming ecosystem

Thank you!

@c410-f3r
Copy link
Contributor Author

Updated

@tomaka tomaka merged commit 54ee836 into libp2p:master Oct 28, 2019
tomaka pushed a commit to tomaka/libp2p-rs that referenced this pull request Nov 6, 2019
tomaka added a commit that referenced this pull request Nov 6, 2019
* Implement Debug for (ed25519|secp256k1)::(Keypair|SecretKey) (#1285)

* Fix possible arithmetic overflow in libp2p-kad. (#1291)

When the number of active queries exceeds the (internal)
JOBS_MAX_QUERIES limit, which is only supposed to bound
the number of concurrent queries relating to background
jobs, an arithmetic overflow occurs. This is fixed by
using saturating subtraction.

* protocols/plaintext: Add example on how to upgrade with PlainTextConfig1 (#1286)

* [mdns] - Support for long mDNS names (Bug #1232) (#1287)

* Dead code -- commenting out with a note referencing future implementation

* Adding "std" feature so that cargo can build in other directories (notably `misc/mdns`, so that I could run these tests)

* Permitting `PeerID` to be built from an `Identity` multihash

* The length limit for DNS labels is 63 characters, as per RFC1035

* Allocates the vector with capacity for the service name plus additional QNAME encoding bytes

* Added support for encoding/decoding peer IDs with an encoded length greater than 63 characters

* Removing "std" from ring features

Co-Authored-By: Pierre Krieger <pierre.krieger1708@gmail.com>

* Retaining MAX_INLINE_KEY_LENGTH with comment about future usage

* `segment_peer_id` consumes `peer_id` ... plus an early return for IDs that don't need to be segmented

* Fixing logic

* Bump most dependencies (#1268)

* Bump most dependencies

This actually builds 😊.

* Bump all dependencies

Includes the excellent work of @rschulman in #1265.

* Remove use of ed25519-dalek fork

* Monomorphize more dependencies

* Add compatibility hack for rand

Cargo allows a crate to depend on multiple versions of another, but
`cargo-web` panics in that situation.  Use a wrapper crate to work
around the panic.

* Use @tomaka’s idea for using a newer `rand`

instead of my own ugly hack.

* Switch to Parity master

as its dependency-bumping PR has been merged.

* Update some depenendencies again

* Remove unwraps and `#[allow(deprecated)]`.

* Remove spurious changes to dependencies

Bumping minor or patch versions is not needed, and increases likelyhood
of merge conflicts.

* Remove some redundant Cargo.toml changes

* Replace a retry loop with an expect

`ed25519::SecretKey::from_bytes` will never fail for 32-byte inputs.

* Revert changes that don’t belong in this PR

* Remove using void to bypass ICE (#1295)

* Publish 0.13.0 (#1294)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants