Commit Graph

430 Commits

Author SHA1 Message Date
Tobin C. Harding 50c0af7138
Stop using Hash::from_slice
This function is deprecated, stop using it in favour of
`Hash::from_byte_array`.

Patch only touches test code, I'm guessing that is why lint warnings
were no showing up.
2025-02-17 12:39:11 +11:00
Tobin C. Harding 85652359e8
hashes: Derive Copy and Clone for Hkdf
Currently the `Hkdf` type does not derive any traits.

We would like to derive the common set of traits but there are a bunch
reasons we can't;

- Don't want to leak secrets in `Debug`.
- Don't want to enable timing attacks with Eq/Ord and friends.

For now just derive `Copy` and `Clone`. We will then implement `Debug`
manually.
2025-02-17 12:12:15 +11:00
Tobin C. Harding 8c2439550a
hashes: Test macros in function scope
The two main public macros can be used in function scope - prove it.

While we are at it prove that additional attributes are supported by
them both as well as visability keywords.
2025-02-17 11:34:40 +11:00
Jamil Lambert, PhD 7c12d92bc3
Only enable hex/std, alloc when hex is
`hex/std` and `hex/alloc` should only be included if optional
dependency `hex` is enabled`.

Add `?` so it is only included if the optional feature `hex` is enabled.
2025-02-14 15:22:13 +00:00
Jamil Lambert, PhD e7c6564d38
Add missing hex feature gate
`hex` was previously enabled by `alloc`, now it is optional add the
missing feature gate to tests.
2025-02-14 11:44:55 +00:00
Tobin C. Harding fd4586eaae
Invert dependency between io and hashes
Currently in order to release `hashes v1.0` we need to 1.0 `io` as well.
For multiple reasons, many out of our control, the `io` crate may not
stabalise any time soon.

Instead we can invert the dependency between the two crates.

This is an ingenious idea, props to Kixunil for coming up with it.

Notes

- `io` does not currently re-export the `hashes` crate.
- This work highlights that we cannot call `hash_reader` on a siphash.
- The `Hmac::hash_reader` uses the default key which may not be obvious.

Signed-off-by: Tobin C. Harding <me@tobin.cc>
2025-02-11 09:17:21 +11:00
Tobin C. Harding 6002ccdc56
Add a tagged sha256t hash engine
We would like it if two different pre-tagged engines were considered
different types so it is not possible to mix them up.

Add a new `sha256t::HashEngine<T>` where `T` is a tag the same as on
`sha256t::Hash<T>`.
2025-02-08 13:27:30 +11:00
Tobin C. Harding 3e8e2e46bf
Use Self::Engine in GeneralHash impl
Match the trait method signature. Internal change only.
2025-02-08 13:27:30 +11:00
Tobin C. Harding a0211906fe
sha256t: Remove standalone from_engine function
This function is meant to be used in conjunction with the
`general_hash_type` macro but the `sha256t` module does not use that
macro.

Inline the function. Internal change only.
2025-02-08 13:27:30 +11:00
Tobin C. Harding 5ce8781162
Remove the Tag::engine method
Now we have an associated const we can do away with the `engine` trait
method all together. Users can call `Hash<FooTag>::engine` instead. This
is better because its an API more similar to the other hash types and
therefor easier to discover and remember.
2025-02-08 13:27:30 +11:00
Tobin C. Harding ba6425947f
hashes: Use associated cost for pre-tagging
Instead of requiring users of the `Tag` trait to implement the `engine`
method we can have an associated const and provide an `engine` method
with a default implementation.

Use an associated const for the pre-tagged hash engine. Fro now keep the
`engine` trait method but have a default impl that returns the const. We
will remove it as a separate patch to assist review.
2025-02-08 13:27:30 +11:00
Tobin C. Harding 613fddc82b
Delete deprecated sha256t_hash_newtype macro
This macro is a maintenance burden. We would like to put a tag on the
hash engine but doing so would require breaking this macro anyway so
lets just delete it.
2025-02-08 13:27:30 +11:00
Tobin C. Harding 6263b9c6af
hashes: Derive Debug for all hash engines
Public types typically should implement `Debug`.

Derive `Debug` for all the hash engines
2025-02-07 11:16:59 +11:00
Tobin C. Harding 85e0330d7f
Run the formatter
Run `just fmt`, no other manual changes.
2025-02-06 07:12:17 +11:00
Tobin C. Harding 7be0db730a
hashes: Move bench and test code into files
We are trying to make the `hashes` crate easier to read and also
possibly parseable by machines to see what is different where.

Move the test and bench code into separate files. Make special effort to
keep formatting as is so the diff is easier to review. We will run the
formatter in the next patch.

Internal change only.
2025-02-06 07:10:02 +11:00
Tobin C. Harding 665fa9de99
hashes: Pull crypto out into submodule
There are five modules in `hashes` that implement cryptography (i.e.
have a `process_block` function). For each of them create a new
submodule called `crypto` and move the code there.

Code organisational refactor only, no logic changes.
2025-02-06 07:10:02 +11:00
Tobin C. Harding 1bfd1e071a
hashes: Make module subdirectories
In preparation for removing a bunch of macros move all the modules to
`<mod>/mod.rs`.

Do so by running the following shell:

```bash
for mod in hash160 ripemd160 sha1 sha256 sha256d sha256t \
sha384 sha512 sha512_256 siphash24 hkdf hmac; do
mkdir $mod
mv "$mod.rs" "$mod/mod.rs"
done
```

Internal change only.
2025-02-06 07:10:02 +11:00
Jamil Lambert, PhD 30132c56bb
Fix rustdoc indentation
New nightly lint picked up an incorrect indentation.

Remove extra space.
2025-02-04 16:47:43 +00:00
Tobin C. Harding 1bcfc80fe7
Add engine function to siphash24::Hash
The other hashes that require initial state (keys etc) both have an
`engine` function on the hash type because they cannot use the
`GeneralHash::engine` function.

Add an `engine` function to the `siphash24::Hash` type.
2025-02-03 13:45:11 +11:00
merge-script 4700fe7fb2
Merge rust-bitcoin/rust-bitcoin#3982: hashes: Move from_engine functions
b98c489066 hashes: Move from_engine functions (Tobin C. Harding)

Pull request description:

  In order to use the `general_hash_type` macro the must exist a standalone `from_engine` function. Currently this function is in different places in different modules. In an effort to make the `hashes` code easier to reason about put the functions right below the macro.

  Code move only, no other changes.

ACKs for top commit:
  Kixunil:
    ACK b98c489066
  apoelstra:
    ACK b98c489066e8916a383099e5037e5a24832548ba; successfully ran local tests

Tree-SHA512: 8dfbf2b422d078d687708fa94a478ca597fae141f5c1f0a318a36152ca33f4760bb0545ab67523c558a8c3b8d258356975c5e357600d0ac980d473250a2af20e
2025-02-02 03:19:45 +00:00
merge-script e45bc0056c
Merge rust-bitcoin/rust-bitcoin#3981: Do not implement `Default` for `HmacEngine`
18619a6d0b api: Run just check-api (Tobin C. Harding)
1eb8f1f9e0 Add a Hmac::engine function (Tobin C. Harding)
c352d376ed Do not implement Default for HmacEngine (Tobin C. Harding)

Pull request description:

  The `HmacEngine` should be created using a key. Currently we are providing a `Default` impl that uses `&[]` as the key. This is, I believe, a hangover from when we had a `Default` trait bound somewhere else. It is incorrect and an API footgun - remove it.

  Note this PR includes changes to the bench code in `hmac` that highlights the footgun - pity the poor user we even shot ourselves.

  Patch 2 adds a constructor `Hmac::engine` and uses it in the bench code.

ACKs for top commit:
  Kixunil:
    ACK 18619a6d0b
  apoelstra:
    ACK 18619a6d0b0bca7b7e3603e260b254b4aae6cebf; successfully ran local tests

Tree-SHA512: c96640e7ffba52d5b13b76a6dd9e1381788efcf56ee76300c5111541466bab8018d2546bcecf237c42dbd82e9372a0e43e1ecec37147508e879365d92a4c1451
2025-01-31 20:29:55 +00:00
Tobin C. Harding 1eb8f1f9e0
Add a Hmac::engine function
The `HmacEngine` cannot be constructed by way of the `GeneralHash` trait
method because it requires a key. However we can still add an inherent
function to the type to construct an engine.

Add the engine constructor and use it in bench code.
2025-01-31 11:15:42 +11:00
Tobin C. Harding c352d376ed
Do not implement Default for HmacEngine
The `HmacEngine` should be created using a key. Currently we are
providing a `Default` impl that uses `&[]` as the key. This is, I
believe, a hangover from when we had a `Default` trait bound somewhere
else. It is incorrect and an API footgun - remove it.
2025-01-31 09:58:06 +11:00
Tobin C. Harding b98c489066
hashes: Move from_engine functions
In order to use the `general_hash_type` macro the must exist a
standalone `from_engine` function. Currently this function is in
different places in different modules. In an effort to make the `hashes`
code easier to reason about put the functions right below the macro.

Code move only, no other changes.
2025-01-30 10:51:08 +11:00
Tobin C. Harding 9b81a8a2ed
hashes: Remove sha256t::Hash Default impl
The other hash types do not implement `Default` but the tagged one does
still - bad bitcoin devs, no biscuit.
2025-01-29 12:27:48 +11:00
Tobin C. Harding 81d4c2e067
Remove unnecessary doc(hidden)
This trait is private and is meant just for sealing. It already will not
show up in public docs and cannot be used by downstream users.

Resolve: #3912
2025-01-20 17:23:12 +11:00
merge-script 3b2363b2c6
Merge rust-bitcoin/rust-bitcoin#3846: Remove `test_` prefix from unit tests
85e04315d5 Remove test_ prefix from unit tests (Tobin C. Harding)

Pull request description:

  There is a loose convention in Rust to not use `test_` prefix. The reason being that `cargo test` outputs 'test <test name>' using the prefix makes the output stutter.

  This patch smells a bit like code-churn but having the prefix in some places and not others is confusing to new contributors and is leading me to explain this many times now. Lets just fix it.

  Remove the prefix unless doing so breaks the code.

ACKs for top commit:
  shinghim:
    ACK 85e04315d5
  apoelstra:
    ACK 85e04315d5eb90075ce55bf18fab8876a4583def; successfully ran local tests

Tree-SHA512: d90ae5ef75cc5e5a8f43f60819544f1a447f13cbe660ba71e84b8f27bfcc04a11d3afde0ed56e4eea5c73ebc3925024b800a1b995f73142cab892f97a414f14a
2025-01-04 00:23:46 +00:00
Tobin C. Harding 85e04315d5
Remove test_ prefix from unit tests
There is a loose convention in Rust to not use `test_` prefix. The
reason being that `cargo test` outputs 'test <test name>' using the
prefix makes the output stutter.

This patch smells a bit like code-churn but having the prefix in some
places and not others is confusing to new contributors and is leading me
to explain this many times now. Lets just fix it.

Remove the prefix unless doing so breaks the code.
2025-01-02 10:06:50 +11:00
Tobin C. Harding 0d8e9ef096
Remove usage of impl_from_infallible in leaf crates
Rust macros, while at times useful, are a maintenance nightmare. And
we have been bitten by calling macros from other crates multiple times
in the past.

In a push to just use less macros remove the usage of the
`impl_from_infallible` macro in all the leaf crates and just write the
code.
2025-01-02 07:51:21 +11:00
Tobin C. Harding ed387e5f1d
hashes: Hide both macros
We have two macro definitions feature gated on `serde`. At some stage we
added the `doc(hidden)` attribute to one of them but forgot to add it to
the other. This technically makes our features non-additive. This macro
is "internal" so its unlikely that this is being used in the wild.

Add `doc(hidden)` to the `serde_impl` macro that is missing it.

Found by `cargo semver-checks` after recent upgrade to 0.38
2024-12-29 08:23:39 +11:00
calciumbe a6a746b8c0
hashes: fix typo 2024-12-23 20:44:18 +08:00
Tobin C. Harding b5f553d866
hashes: Bump version to 0.16.0
We need to do a quick release because it turns out I was wrong in
thinking that making `hex` an optional dependency is not a breaking
change.

```
the package `bitcoin` depends on `bitcoin_hashes`, with features: `hex`
but `bitcoin_hashes` does not have these features. It has a required
dependency with that name, but only optional dependencies can be used as
features.
```

Add a changelog, bump the version, depend on the new version repo wide,
and update the lock files - like its our job.
2024-12-16 12:41:17 +11:00
Tobin C. Harding 38c329c1b7
Add additional catagories
Add `no-std` category to the soon-to-be-released leaf crates.
Also add `cryptography` to the `bitcoin_hashes` crate.

Close: #3731
2024-12-12 15:14:26 +11:00
Tobin C. Harding f4b9c06c8b
hashes: Add additional must_use
Run the linter with `must_use_candidate` enabled and check all the
warnings.
2024-12-10 10:58:11 +11:00
Tobin C. Harding b9b8ddafde
hashes: Add lint return_self_must_use
Add the lint. No additional clippy warnings are introduced.
2024-12-10 10:56:33 +11:00
Jamil Lambert, PhD 91268bba67
Examples use ?, not try!, not unwrap
To conform to Rust API guidelines examples should Examples use ?, not
try!, not unwrap (C-QUESTION-MARK).

Label the examples as `# Examples`.
Replace one `unwrap()` with `expect()` .  The others don't technically
conform to the guidelines but are warranted.
2024-11-28 22:20:57 +00:00
Tobin C. Harding ec06028f63
hashes: Make hex dependency optional
The only reason we need `hex-conservative` is to parse strings and
format them as hex. For users that do not require this functionality we
can make the `hex-conservative` crate an optional dependency.

The `serde` feature requires `Display` so we enable `hex` from the
`serde` feature.

If `hex` feature is not enabled we still need to be able to debug so
provide `fmt::Debug` functionality by way of macros.

Close: #2654
2024-11-14 09:36:55 +11:00
Tobin C. Harding 9dce0b4b8c
Remove hex string trait bounds from GeneralHash
For the `hashes` crate we would like to make `hex` an optional
dependency. In preparation for doing so do the following:

- Remove the trait bounds from `GeneralHash`
- Split the hex/string stuff out of `impl_bytelike_traits` into a
  separate macro.
2024-11-13 14:01:13 +11:00
Tobin C. Harding 766f498b33
Pull serde stuff out of impl_bytelike_traits macro
The `impl_bytelike_traits` macro is public and it is used in the
`hash_newtype` macro, also public.

Currently if a user calls the `hash_newtype` macro in a crate that
depends on `hashes` without the `serde` feature enabled and with no
`serde` dependency everything works. However if the user then adds a
dependency that happens to enable the `serde` feature in `hashes` their
build will blow up because `serde` code will start getting called from
the original crate's call to `hash_newtype`.

Pull the serde stuff out of `hash_newtype` and provide a macro to
implement it `impl_serde_for_newtype`.
2024-11-13 12:28:47 +11:00
merge-script 4797a75586
Merge rust-bitcoin/rust-bitcoin#3584: Standardize constructor type function docs
1649b68589 Standardize wording to `constructs a new` (Jamil Lambert, PhD)
27f94d5540 Replace `creates` with `constructs` (Jamil Lambert, PhD)

Pull request description:

  As discussed in issue #3575 there are various ways of saying a new object is created.

  These have all be standardized to the agreed version.

  Close #3575

ACKs for top commit:
  apoelstra:
    ACK 1649b68589834dfe9d5b63812da3e9f0e5930107; successfully ran local tests
  tcharding:
    ACK 1649b68589

Tree-SHA512: 0ed9b56819c95f1fc14da1e0fdbbe03c4af2d97a95ea6b56125f72913e8d832db5d2882d713ae139d00614e651f3834a4d72528bdf776231cceb6772bf2f9963
2024-11-06 16:05:24 +00:00
merge-script b09ce778f8
Merge rust-bitcoin/rust-bitcoin#3579: hashes: Hide error internals
fe8ca21ec2 hashes: Duplicate impl_from_infallible (Tobin C. Harding)
7652d0ddfc hashes: Hide innards of FromSliceError (Tobin C. Harding)
5232bba62b hashes: Move FromSliceError to submodule (Tobin C. Harding)

Pull request description:

  Hide the internals of the `hashes::FromSliceError`.

ACKs for top commit:
  apoelstra:
    ACK fe8ca21ec282cfe50e3f39b7f86c619d30d7f542; successfully ran local tests

Tree-SHA512: dac33777353dd81c8c86de331b2ab30d0a5268f2be7685f85405d29809ec36eeab31b0e71c9f09e820e06a93c3f05b7d675e5e729b780e8600b960cad4a02c77
2024-11-06 15:33:27 +00:00
Jamil Lambert, PhD 1649b68589
Standardize wording to `constructs a new`
There is a range of different wordings used in the docs of constructor
type functions.

Change all to start with `Constructs a new` or `Constructs an empty`.
2024-11-05 13:02:26 +00:00
Jamil Lambert, PhD 27f94d5540
Replace `creates` with `constructs`
In functions that act like constructors there is a mixture of the usage
of `creates` and `constructs`.

Replace all occurrences of `creates` with `constructs` in the first line
of docs of constructor like functions.
2024-11-05 12:47:28 +00:00
Tobin C. Harding fe8ca21ec2
hashes: Duplicate impl_from_infallible
We don't want a dependency on `internals` for `hashes` unless its really
needed.

Duplicated the `impl_from_infallible` macro into `hashes::error` and
use it to implement from infallible for `FromSliceError`.
2024-11-05 11:19:19 +11:00
Tobin C. Harding 7652d0ddfc
hashes: Hide innards of FromSliceError
In preparation for releasing 1.0 we want to hide all error internals. Do
so for the single error type in the `hashes` crate.
2024-11-05 11:17:29 +11:00
Tobin C. Harding 5232bba62b
hashes: Move FromSliceError to submodule
Add a public `error` module and move the one error for the `hashes`
crate into it.

Re-export at the crate root.

Done in preparation for adding an additional error type.
2024-11-05 11:17:29 +11:00
Tobin C. Harding ba124757c4
hashes: Default to no_std
`hashes` is `no_std` ready, lets default to `no_std`.
2024-11-05 11:16:24 +11:00
Tobin C. Harding 6a4e219c55
hashes: embedded: Remove unused import
Clear clippy warning by removing unused import statement.
2024-11-05 11:16:23 +11:00
Tobin C. Harding 915c9627f6
Put feature gate attribute under test attribute
Either way is fine, just pick one and be uniform.
2024-11-05 11:16:23 +11:00
Tobin C. Harding 90b2ac03e3
hashes: Introduce impl_bytelike_traits macro
We have a couple of problems:

1. There are two macros currently for fmt stuff that do similar things,
`arr_newtype_fmt_impl` and `hex_fmt_impl` - the difference is not
immediately obvious, its the way that the byte array is iterated.

2. Our hash types are missing `AsRef<[u8; len]>` and `Borrow<[u8; len]>`.

Introduce a new macro and remove a bunch of other macros. Include
extensive docs but hide the macro from public docs because its not
really for consumers of the library.

The macro requires `$crate::hex` to point to `hex-conservative`.

Note the macro is pretty generic (as in general purpose), `hashes` might
not be the right home for it. Potentially a better place would be in
`hex` itself?
2024-11-02 08:10:43 +11:00
merge-script 8eacfd0191
Merge rust-bitcoin/rust-bitcoin#3557: Remove needless_borrows_for_generic_args
6aa8c2b023 Remove needless_borrows_for_generic_args (Tobin C. Harding)

Pull request description:

  This has been fixed and we use nightly to lint so we have access to the merged fix.

ACKs for top commit:
  apoelstra:
    ACK 6aa8c2b023619534437043e76ec4252f27295875; successfully ran local tests

Tree-SHA512: 011677b6c1a2dc6c63097cafd1682fab5d9bdd94133b872bdd49699a55c80a01a8e6e5e844ae1cfe1ca9da47a2ba2ed6b910719b1ccbb06e60e22ecb01ec0efc
2024-11-01 13:37:27 +00:00
merge-script 5ec0e5299b
Merge rust-bitcoin/rust-bitcoin#3377: Release tracking PR: `bitcoin_hashes 0.15.0`
80b5d8b7b3 hashes: Add changelog for release 0.15.0 (Tobin C. Harding)

Pull request description:

  The version has already been bumped on `master`.

  In preparation for releasing `hashes v0.15.0` add a changelog entry.

ACKs for top commit:
  apoelstra:
    ACK 80b5d8b7b36ea97007f062971a732ec8a512cfa5; successfully ran local tests; again lots of stuff!

Tree-SHA512: ab1bbdf7df819c587dc905e4cdcda2232ede2a495a0e395e5d6f6bd730a7c3c0675e05f8ab616e5e6dee0a87836ab486d025f80608e73b713007391711ef15ba
2024-11-01 12:22:57 +00:00
Tobin C. Harding 6aa8c2b023
Remove needless_borrows_for_generic_args
This has been fixed and we use nightly to lint so we have access to the
merged fix.

Removing the attribute uncovers a bunch of real lint warnings, fix
them while we are at it.
2024-11-01 14:30:45 +11:00
Tobin C. Harding 80b5d8b7b3
hashes: Add changelog for release 0.15.0
The version has already been bumped on `master`.

In preparation for releasing `hashes v0.15.0` add a changelog entry.
2024-10-31 17:14:26 +11:00
Leo Nash 7f289a9fdf Bump hex-conservative to 0.3.0 2024-10-31 03:36:22 +00:00
Tobin C. Harding e84346644e
Run the formatter
Run `just fmt` - no other changes.
2024-10-30 11:30:24 +11:00
Tobin C. Harding abcac54078
hashes: Move public macros
Put the two "real" public macros at the top of the `macros` file and add
a module level doc to link to them because they don't show up otherwise.
2024-10-30 07:10:37 +11:00
Tobin C. Harding 2868985a91
Replace TBD with next hashes release version
We are about to release `bitcoin_hashes 0.15.0`, replace the TBD string
with the version number.

Requires changing `allow(deprecated_in_future)` attribute to
`allow(deprecated)` (in functions that are them self deprecated).
2024-10-30 07:10:36 +11:00
Tobin C. Harding baab5e580d
hashes: Move private macro
We have two files one for public macros and one for private macros. Move
the `engine_input_impl` macro to the private macros file.

Requires change to call sites because we do not have `use_macros`
attribute on the `internal_macros` file.
2024-10-29 14:06:12 +11:00
Tobin C. Harding e4486d07f0
hashes: Hide macros from docs
These three macros are solely provided to reduce code duplication, they
are only part of the public API because they are used by the "real"
public macro `hash_newtype`.
2024-10-29 14:01:50 +11:00
Tobin C. Harding 25c4c78e26
hashes: Put attribute under rustdoc
Like we do for all the other macros ptu the `macro_export` attribute
below the macro comments.
2024-10-29 13:58:50 +11:00
Tobin C. Harding 5a736edaaa
hashes: Move serde_macros code into macros
Roll the `serde_macros` module into `macros`, requires making `macros`
public but since it explicitly holds public macros this is reasonable.

Keep the original module and deprecate it.
2024-10-27 07:07:01 +11:00
Tobin C. Harding aaa78a3a09
hashes: Rename util to macros
The `utils` module holds public macros, call it `macros` instead.
2024-10-27 07:03:50 +11:00
Tobin C. Harding 34e638d40c
hashes: Separate private and public modules
The private and public modules are already grouped, add a line of
whitespace to make it _even_ more clear. Trivial I know, this patch got
smaller during rebase.
2024-10-27 07:03:50 +11:00
Jamil Lambert, PhD b22db6268c
Remove unnecessary lifetimes 2024-10-24 14:08:20 +01:00
merge-script 456bbf11d1
Merge rust-bitcoin/rust-bitcoin#3505: CI: Hobble WASM job
5ec17a2ee8 CI: Hobble WASM job (Tobin C. Harding)

Pull request description:

  The WASM job is not working. `wasm-pack build` works fine but `wasm-pack test` doesn't compile.

  Comment out the line that runs `wasm-pack test`.

ACKs for top commit:
  apoelstra:
    ACK 5ec17a2ee8c963d182777a9661b1bab786956bd4; successfully ran local tests; LGTM

Tree-SHA512: 5ea88bd99f625a8c669dc1dec02486dd549e9ac83d7670c6c7b3b25c86de3fc9a8dbc959dc39de92305dd5e254e0b8ed9424cae5e5941b66a6476ee433009fdd
2024-10-23 19:16:40 +00:00
merge-script 79ff70255b
Merge rust-bitcoin/rust-bitcoin#3477: Polish the `hashes` crate
1cb24c1f15 hashes:: Polish crate level rustdocs (Tobin C. Harding)
98691186dc hashes: Move engine functions (Tobin C. Harding)
12f261c009 hashes: Re-order from_byte_array (Tobin C. Harding)
c11587d60d hashes: Rename hash_type macro (Tobin C. Harding)
62617cf9ac hashes: Move from_engine function to other macro (Tobin C. Harding)
bb7dd2c479 hashes: Move DISPLAY_BACKWARD to top of impl block (Tobin C. Harding)
71013afe07 hashes: Put attribute under doc (Tobin C. Harding)

Pull request description:

  `hashes 1.0.0` can't be far away, here is a quick polish (done while I waited for my car to get fixed).

  Everything here is internal except stuff to docs. Note please I claim "internal change only" in a bunch of patches that do code moves but these effect the docs build because order is preserved in some instances.

ACKs for top commit:
  apoelstra:
    ACK 1cb24c1f150bc2d65d0be439f2005f41d95ad23c; successfully ran local tests

Tree-SHA512: 430c451afab8fc92fb4596bf2d4b36c086333fe72b3fe5858925b75597641b8c4f5e49f7643888fa19b675d3070ce9a3606623cd56bdba6cfc59e459fbdda440
2024-10-22 22:24:49 +00:00
Tobin C. Harding 5ec17a2ee8
CI: Hobble WASM job
The WASM job is not working. `wasm-pack build` works fine but `wasm-pack
test` doesn't compile.

Comment out the line that runs `wasm-pack test`.
2024-10-23 06:59:51 +11:00
Tobin C. Harding 1cb24c1f15
hashes:: Polish crate level rustdocs
`hashes v1.0.0` is close, make an effort to polish the crate level rustdocs.
2024-10-16 12:26:14 +11:00
Tobin C. Harding 98691186dc
hashes: Move engine functions
The `sha256t` module is unique in that it implements its methods
manually (as call throughs) instead of using the macros. To make it more
clear what is implemented re-order the engine constructor and getter to
better mirror the layout in the macros.

Internal change only.
2024-10-16 12:22:42 +11:00
Tobin C. Harding 12f261c009
hashes: Re-order from_byte_array
The `hashes` crate has a bunch of similar types defined by a bunch of
similar macros and impl blocks, all of which makes it difficult to tell
exactly what is implemented where. In an effort to make the code easier
to read order the `from_byte_array` constructor in the same place across
the crate. Note also we typically put constructors up the top, also
`from_byte_array` is the likely most used constructor so put it first.

FWIW I discovered this while polishing the HTML docs.

Internal change only.
2024-10-16 12:22:42 +11:00
Tobin C. Harding c11587d60d
hashes: Rename hash_type macro
Conceptually (and using traits) we split the hashes into "general"
hash types and more restricted hash types (`Hash`). Also we observe that
the `hash_type` macro defines all the inherent functions name
identically to the `GeneralHash` trait methods.

Rename the trait to describe better what it does.

Internal change only.
2024-10-16 12:22:42 +11:00
Tobin C. Harding 62617cf9ac
hashes: Move from_engine function to other macro
The `from_engine` function is associated with a general hash type but we
are defining it in the `hash_type` macro which holds nothing but
functions associated with the `Hash` trait. By "associated" I mean
methods on the type as opposed to trait methods.

In preparation for re-naming the `hash_type` macro move the
`from_engine` function there. Requires duplicating the code in the
`siphash` impl block, this is as expected because the `siphash` requires
a custom implementation of the general hashing functionality.

Internal change only.
2024-10-16 12:22:22 +11:00
Tobin C. Harding bb7dd2c479
hashes: Move DISPLAY_BACKWARD to top of impl block
There is no obvious reason why this const is further down the block,
move it.

Refactor only, no logic change.
2024-10-16 11:59:13 +11:00
Tobin C. Harding 71013afe07
hashes: Put attribute under doc
As is typical round here, put the attribute under the associated
rustdoc.
2024-10-16 11:59:07 +11:00
Jamil Lambert, PhD 88b53a471e
Unify deprecated note field format
All the deprecated note fields have been changed to be lower case and in
the format "use `a` instead".
2024-10-15 15:16:01 +01:00
Tobin C. Harding e68da281ff
Warn on future deprecations
We use `TBD` in our `deprecated` string and it was discovered that there
is an exception on this string so as not to warn because it is used
internally by the Rust language. However there is a special lint to
enable warnings, lets use it.

Add `#![warn(deprecated_in_future)]` to the coding conventions section
of all crates except `fuzz`.
2024-10-15 07:56:06 +11:00
Tobin C. Harding 2cc944578d
Fully deprecate Hash::from_slice
We had an initial go at this but we didn't do the `Hash` trait method.
In order to do so we need to hack the serde code a fair bit, note the
public visitor types.
2024-10-15 07:56:05 +11:00
Fmt Bot f1733309e0 2024-10-13 automated rustfmt nightly 2024-10-13 01:20:28 +00:00
merge-script fe62d94ff7
Merge rust-bitcoin/rust-bitcoin#3296: Remove the `SliceIndex` implementation from hash types
3b7ba4f977 Remove the SliceIndex implementation from hash types (Tobin C. Harding)

Pull request description:

  If folk really want to index into a hash they can us `as_byte_array` then index that.

  Includes a bump to the version number of `hashes` to `v0.15.0` - this is because otherwise `secp` won't build since we are breaking an API that is used in the current release of secp.

  Fix: #3115

ACKs for top commit:
  apoelstra:
    ACK 3b7ba4f977 successfully ran local tests

Tree-SHA512: 0ba93268cd8133fe683183c5e39ab8b3bf25c15bfa5767d2934d67a5f6a0d2f65f6c9304952315fe8a33abfce488d810a8d28400a28facfb658879ed06acca63
2024-10-10 22:39:21 +00:00
Jamil Lambert, PhD 1f8fdc6ccb
Fix type used in bytes_hashed addition
`length` was changed to `bytes_hashed` and the type changed from `usize`
to `u64`.

The addition under the `hashes_fuzz` feature flag has been changed from
`usize` to `u64` to fix the fuzz error.
2024-10-09 16:19:07 +01:00
Jamil Lambert, PhD d37b8a5dd2
Fix HashEngine.length name change to bytes_hashed
When `hashes_fuzz` is on the field `length` is refered to but it was
changed to `bytes_hashed` in a previous PR.

This has been fixed by changing `length` to `bytes_hashed`.
2024-10-09 16:17:20 +01:00
Tobin C. Harding 3b7ba4f977
Remove the SliceIndex implementation from hash types
If folk really want to index into a hash they can us `as_byte_array`
then index that.

Includes a bump to the version number of `hashes` to `v0.15.0` - this
is because otherwise `secp` won't build since we are breaking an API
that is used in the current release of secp.

Fix: #3115
2024-10-02 10:18:45 +10:00
Tobin C. Harding fed94f8899
Bump version of bitcoin-io to 0.2.0
In preparation for releasing `io v0.2.0` bump the version number,
add a changelog entry, update the lock files, and depend on the new
version in all crates that depend on `io`.
2024-10-02 09:47:10 +10:00
merge-script 66d2c0214a
Merge rust-bitcoin/rust-bitcoin#3429: Rename Midstate::into_parts to Midstate::to_parts since it derives Copy
be94c9e54b Rename Midstate::into_parts to Midstate::to_parts since it derives Copy (Shing Him Ng)

Pull request description:

  This is a follow up to #3010

  Fixes #3079

ACKs for top commit:
  tcharding:
    ACK be94c9e54b
  apoelstra:
    ACK be94c9e54b successfully ran local tests

Tree-SHA512: 0d838a2064136d050d319116f6df3d598323b04a137e7bb7cb5f3f1a87d72ad1ee4d2f3b228a2f9d68e7ca117c0f922ef6551f783eb39c8db0db1188e4732c41
2024-10-01 16:03:53 +00:00
merge-script de120de5b9
Merge rust-bitcoin/rust-bitcoin#3410: Fix buggy cfg in rustdocs
8bb0d3f667 Fix buggy cfg in rustdocs (Tobin C. Harding)

Pull request description:

  In b9643bf3e9 we introduced an incorrect `cfg` attribute, that has just shown up, no clue why clippy only just presented me with this error now. Anywho, the current code is buggy and the rustdoc tests are never being run.

  Fix `cfg` attribute to use the feature name correctly and fix the imports so the code runs.

  Maintain the explicit `main` so that we can return an error using the `?` operator. Remove the empty `main` because its not needed anymore, it is a hang-over from Rust back in the day (before main was automatically added, IIUC).

ACKs for top commit:
  apoelstra:
    ACK 8bb0d3f667 successfully ran local tests

Tree-SHA512: 27f571ac3644417c06d0b4eb6fb122b39ac1068aefa4bcfc03f1febe2d031fb30616883c55c42c2ec80d419572fe7eba9bcc239e3c0e0e178ec7eaf8533b9efe
2024-10-01 14:37:29 +00:00
Tobin C. Harding 8bb0d3f667
Fix buggy cfg in rustdocs
In b9643bf3e9 we introduced an incorrect
`cfg` attribute, that has just shown up, no clue why clippy only just
presented me with this error now. Anywho, the current code is buggy and
the rustdoc tests are never being run.

Fix `cfg` attribute to use the feature name correctly and fix the
imports so the code runs.

Maintain the explicit `main` so that we can return an error using the
`?` operator. Remove the empty `main` because its not needed anymore,
it is a hang-over from Rust back in the day (before main was
automatically added, IIUC).
2024-10-01 08:37:22 +10:00
Shing Him Ng be94c9e54b Rename Midstate::into_parts to Midstate::to_parts since it derives Copy 2024-09-30 08:13:16 -05:00
Andrew Poelstra c2674caf4c
clippy: remove some newly-detected unnecessary returns 2024-09-30 12:31:17 +00:00
Fmt Bot a65d2a0ee4 2024-09-29 automated rustfmt nightly 2024-09-29 01:21:14 +00:00
merge-script d0fc012497
Merge rust-bitcoin/rust-bitcoin#3374: hashes: Remove unused file
8b9d657667 hashes: Remove unused file (Tobin C. Harding)

Pull request description:

  Recently we moved the tests from `impls` to `tests/io.rs` but forgot to delete the original file.

  Remove the already unused `impls.rs` file.

ACKs for top commit:
  apoelstra:
    ACK 8b9d657667 successfully ran local tests

Tree-SHA512: f701825239aff18faa0cd7adf69e1a8830dfb532df9d52c6d545e6352054ae6cb8c625c9fc05b7db374822d3478acf16858bc38ffbecf45575f555eb80f010e1
2024-09-25 13:30:06 +00:00
merge-script 40ba08f369
Merge rust-bitcoin/rust-bitcoin#3395: Remove schemars all together
58704c2eff Remove schemars all together (Tobin C. Harding)

Pull request description:

  We introduced schemars as a personal favor to a user, and it broke our CI repeatedly but eventually it seemed like it was stable (mainly, our MSRV caught up with its MSRV) so we just let it slide. In the end having schemars on hashes but nowhere else in the rust-bitcoin ecosystem did not prove that useful.

  Remove schemars all together.

  Fix: #3393

ACKs for top commit:
  apoelstra:
    ACK 58704c2eff successfully ran local tests

Tree-SHA512: 11c136797f28903c7d6b5199ad55d86bc4bc29ee8dd6f0d575e029f4dbebebabed57ebce6cf773b286297ea84f18d0b6cc58e150299e99457e048226478b49cc
2024-09-24 19:21:56 +00:00
merge-script 76ea4eb400
Merge rust-bitcoin/rust-bitcoin#3298: hashes: Rename length field and use u64
cbfddb0394 hashes: Rename length field and use u64 (Tobin C. Harding)

Pull request description:

  The hash engine types have a `length` field that is used to cache the number of bytes hashed so far, as such it is an arbitrary number and could use a `u64` instead of `usize`.

  While we are at it rename `length` to `bytes_hashed` to remove any ambiguity of what this field is. Note this field is private, we already have the public getter `n_bytes_hashes` to get the value.

  Introduce a private function `incomplete_block_size`, the purpose of this function is to put all the casts in one place so they can be well documented and easily understood.

  Fix: #3016

ACKs for top commit:
  apoelstra:
    ACK cbfddb0394 successfully ran local tests

Tree-SHA512: a9d932938afcbd6dfb9db471a02fa7e3fff8f0659906627001ad241390b9af57088fd34afeae551c70c2c49783e6296f110b57ff9de6fed2609f4648ec8fd934
2024-09-23 20:10:09 +00:00
Tobin C. Harding 58704c2eff
Remove schemars all together
We introduced schemars as a personal favor to a user, and it broke our
CI repeatedly but eventually it seemed like it was stable (mainly, our
MSRV caught up with its MSRV) so we just let it slide. In the end having
schemars on hashes but nowhere else in the rust-bitcoin ecosystem did
not prove that useful.

Remove schemars all together.

Fix: #3393
2024-09-23 06:57:00 +10:00
merge-script 855c4bb754
Merge rust-bitcoin/rust-bitcoin#3364: Remove unused inports, and fix unused variables and methods in docs
f6abdcc001 Allow unused in `macros.rs` docs (Jamil Lambert, PhD)
fd89ddf401 Remove or fix unused variables and methods in docs (Jamil Lambert, PhD)
ff6b1d4f19 Remove unused variables and methods from docs (Jamil Lambert, PhD)
e58cda6f92 Remove `unused_imports` in docs (Jamil Lambert, PhD)

Pull request description:

  As mentioned in #3362 examples in documentation are not linted in the same way as other code, but should still contain correctly written code.

  #![doc(test(attr(warn(unused))))] has been added to all lib.rs files

  In the docs throughout all crates:

  - Unused imports have been removed.

  - Unused variables, structs and enums have been used e.g. with an `assert_eq!` or prefixed with `_`

  - Unused methods have been called in the example code.

ACKs for top commit:
  tcharding:
    ACK f6abdcc001
  apoelstra:
    ACK f6abdcc001 successfully ran local tests

Tree-SHA512: c3de1775ecde6971056e9fed2c9fa1621785787a6a6ccbf3a6dbd11e18d42d4956949f3f8adfc75d94fd25db998b04adb1c346cc2c2ba47f4dc37402e1388277
2024-09-20 02:10:51 +00:00
Jamil Lambert, PhD fd89ddf401
Remove or fix unused variables and methods in docs
Examples in documentation are not linted in the same way as other code,
but should still contain correctly written code.

Throughout all of the crates except internals (another commit) unused
variables have been prefixed with `_`, unused imports have been removed,
and a warn attribute added to all of the `lib.rs` files.
2024-09-18 16:37:47 +01:00
merge-script a543b45df1
Merge rust-bitcoin/rust-bitcoin#3359: Use UFCS in macros
25d906d936 Use UFCS in macros (Liam Aharon)

Pull request description:

  Closes #3304

ACKs for top commit:
  apoelstra:
    ACK 25d906d936 successfully ran local tests
  tcharding:
    ACK 25d906d936

Tree-SHA512: a02a8507bcec73dab1ec8d49e45eab327d989c276d931520e0fff312faf7d3165292c300fb9414314f9b94b1255ee49a0fb64303df6d971c9089226b6873c36a
2024-09-18 13:35:56 +00:00
Tobin C. Harding 8b9d657667
hashes: Remove unused file
Recently we moved the tests from `impls` to `tests/io.rs` but forgot to
delete the original file.

Remove the already unused `impls.rs` file.
2024-09-18 09:13:49 +10:00
Fmt Bot 7990724ff4 2024-09-15 automated rustfmt nightly 2024-09-15 01:19:55 +00:00
Liam Aharon 25d906d936
Use UFCS in macros 2024-09-14 09:46:57 +02:00