Commit Graph

14 Commits

Author SHA1 Message Date
Elichai Turkel 626835f540
Update secp256k1 to edition 2018 and fix imports 2022-06-07 23:59:25 +03:00
Tobin Harding c612130864 Borrow secret key
`SecretKey` implements `Copy` and it is fine to take owneship of it; we
have multiple methods called `from_secret_key` and they all borrow the
secret key parameter. Favour consistency over perfection.

Borrow secret key parameter as is done in other `from_secret_key`
methods.
2022-04-04 12:50:52 +10:00
Tobin Harding cf6badf96a
Obfuscate SharedSecret when printing
Currently printing the `SharedSecret` using `Display` or `Debug` prints
the real secret, this is sub-optimal. We have a solution for other
secrets in the project where printing is obfuscated and we provide a
`display_secret` method for explicitly printing.

Mirror the logic for other secrets and obfuscate the `SharedSecret` when printing.
2022-02-28 07:22:17 +00:00
Tobin Harding e4be664d97
Improve rustdocs for displaying secrets
Improve rustdocs on `display_secret` by doing:

- Minor improvements to the rustdocs to aid readability in the editor.
- Do not guarantee (`assert_eq!`) debug output
2022-02-28 07:16:41 +00:00
Tobin Harding 5c7c76eb74
Rename serialize_secret -> secret_bytes
The `serialize_secret` method is a getter method, it does not do any
serialisation. However we use the method on secret keys and key types so
in order for the name to be uniform use the descriptive name
`secret_bytes`.

Rename `serialize_secret` to be `secret_bytes`.
2022-02-28 07:11:24 +00:00
Tobin Harding 4ded2c0478
Use byte instead of i
The identifier `i` is predominantly used for indexing an array but we
are using it as a place holder for the iterated value of an array that
is then printed. The identifier `byte` is more descriptive.

Done in preparation for adding similar code to the `ecdh` module.
2022-02-24 19:48:23 +00:00
Tobin Harding 91106f5685
Remove magic number
In array initialisation we use magic number 64, this is the secret bytes
length multiplied by 2.

Please note; we still use the magic number 32, left as such because it
is used in various ways and its not immediately clear that using a
single const would be any more descriptive.

Use `SECRET_KEY_SIZE * 2` instead of magic number 64.
2022-02-24 19:48:19 +00:00
Tobin Harding 6dca99631f
Mention bitcoin_hashes in obfuscated secret msg
Hashing the debug output for secrets can be done with `bitcoin_hashes`
not just `std`. Mention this in the obfuscated string output when
neither are available.
2022-02-24 19:48:15 +00:00
Tobin Harding 433c350424 Add multiple implementations of Debug for secrets
The `Debug` implementation for secrets is feature gated on `std` because
it uses a hasher from `std`. If `bitcoin_hashes` is enabled we can use
it for hashing. If neither `std` nor `bitcoin_hashes` is enabled fall
back to outputting:

<secret requires std or bitcoin_hashes feature to display>

Remove the docs conditional since we now implement `Debug` always.
2022-02-01 14:51:40 +11:00
Tobin Harding 26921a31b8 Add lints to catch missing traits
Rustc can warn us when we forget to add `Copy` and `Deubg` trait
implementations to types.

Add lint directives to enable warnings for missing `Copy` and `Debug`
implementations. Use the newly emitted warnings to find types that do
not implement our 'standard' traits. These 'standard' traits are defined
as the set of attributes that it has been found beneficial to
opportunistically add to all types, these are

- Copy
- Clone
- Debug
- PartialEq and Eq
- PartialOrd and Ord
- Hash
2022-01-07 10:28:10 +11:00
Martin Habovstiak 1bf05523f0 Documented features
This documents the Cargo features making sure docs.rs shows warning for
feature-gated items. They are also explicitly spelled out in the crate
documentation.
2022-01-04 16:55:01 +01:00
Thomas Eizinger 2e0e731664
Move `KeyPair` to `key` module
The `KeyPair` type is semantically unrelated to the schnorr signature
algorithm.
2021-11-11 13:43:48 +11:00
Thomas Eizinger 8e96abae39
Make `key` module private
We re-export all structs residing in that module. There is no reason
to expose the internal module structure of the library publicly.
2021-11-11 13:38:49 +11:00
Dr Maxim Orlovsky 6810c2b547
Dedicated display_secret fn for secret-containing types
Debug-print secrets as tagged hashes

Refactoring Display/Debug for secret values with display_secret
2021-09-27 14:03:58 +02:00