dalek-cryptography / x25519-dalek

X25519 elliptic curve Diffie-Hellman key exchange in pure-Rust, using curve25519-dalek.
BSD 3-Clause "New" or "Revised" License
326 stars 132 forks source link

Show byte arrays as a hex string in Debug impls, not an expanded array #127

Open teor2345 opened 1 year ago

teor2345 commented 1 year ago

When a debug-format x25519::PublicKey, I get some very long output (see below). But it would be much easier to read and copy shorter hex-encoded output.

Expected output:

ephemeral_key: PublicKey(
    MontgomeryPoint("ed...")
)

Actual output:

ephemeral_key: PublicKey(
    MontgomeryPoint(
        [
            237,
            202,
            200,
            4,
            252,
            109,
            173,
            91,
            83,
            6,
            112,
            86,
            76,
            54,
            29,
            134,
            199,
            218,
            161,
            12,
            26,
            129,
            61,
            228,
            212,
            40,
            55,
            96,
            130,
            233,
            89,
            70,
        ],
    ),
),
rozbb commented 1 year ago

Hmm, so PublicKey wraps MontgomeryPoint which wraps [u8; 32] and all of them autoderive Debug.

What happens if you do println!("{:x?}", my_pubkey)

teor2345 commented 1 year ago

Hmm, so PublicKey wraps MontgomeryPoint which wraps [u8; 32] and all of them autoderive Debug.

What happens if you do println!("{:x?}", my_pubkey)

The "actual output" in the ticket is what happens when I debug-print a key.