chore: checkpoint before Python removal

This commit is contained in:
2026-03-26 22:33:59 +00:00
parent 683cec9307
commit e568ddf82a
29972 changed files with 11269302 additions and 2 deletions

1
vendor/signature/.cargo-checksum.json vendored Normal file
View File

@@ -0,0 +1 @@
{"files":{".cargo_vcs_info.json":"29818ae227fce683276a4e069e2eca656a6d23371505f04207155120df6ebddd","CHANGELOG.md":"2449de0a06c0b7cc8befcca6d8401ac054e96556f06c0b4dfd1e9048f92813f6","Cargo.toml":"9a0ed264f832101d9e2e786db0e22d90a2a2544ed19c760ec7f2d501d950a9dd","Cargo.toml.orig":"cb69cef9cac35599f182cf0fe35f31e2061addf3aa978d648c7bb8f23dcf631e","LICENSE-APACHE":"a9040321c3712d8fd0b09cf52b17445de04a23a10165049ae187cd39e5c86be5","LICENSE-MIT":"b3470648aff02beb36d7a53240fc9260ed80ed93bd43bace6b67d7ef7336ee33","README.md":"abe06adcdfc61ddd24c4a1007b6da73a9c83acf9f2cad76bcb394cdb9341ba5a","src/encoding.rs":"872ae940d329d523335d1e28379de898f25ccf98c3366a6773a6728a9e0e1992","src/error.rs":"26b85a7b2671363cd92faad5d3cc511797df2792d79f29c4373535516e91b247","src/hazmat.rs":"c662aeb812a9ce24d0e2c7dedeca7d9ae7002bd527cbd484557b04a41bab1817","src/keypair.rs":"9b2f6cda46e3fe8c29b571b912745f4dfb7c6a1186c56790f0e3fd080ab3bdf7","src/lib.rs":"9ad89b20efad0859a136f4dbee92f643e345afb3c5235a31d5b2ec72556b3b76","src/prehash_signature.rs":"74b7641cfcf5692625adec58b550ac3a12125983e12076c4e811be7f28462a0c","src/signer.rs":"20a50c3c2fc0ef678e1ca87aca9c75527794bd66cf52583aa941b13b3f1ee1da","src/verifier.rs":"4eaeb33529879b3bbfc13442a5823905ca05f8f27316192360f9bbd416822976","tests/derive.rs":"980390b69a0d0bcbbab26e086727bc91ada0fad21c38bb961a0a143260eb8375"},"package":"77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de"}

6
vendor/signature/.cargo_vcs_info.json vendored Normal file
View File

@@ -0,0 +1,6 @@
{
"git": {
"sha1": "5adcd4819b380b4aaec2b57c6bf3f2239a109060"
},
"path_in_vcs": "signature"
}

247
vendor/signature/CHANGELOG.md vendored Normal file
View File

@@ -0,0 +1,247 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## 2.2.0 (2023-11-12)
### Changed
- MSRV 1.60 ([#1387])
### Fixed
- No longer vendoring async/derive crates unintentionally ([#1391])
[#1387]: https://github.com/RustCrypto/traits/pull/1387
[#1391]: https://github.com/RustCrypto/traits/pull/1391
## 2.1.0 (2023-04-01)
### Added
- `SignatureEncoding::encoded_len` ([#1283])
[#1283]: https://github.com/RustCrypto/traits/pull/1283
## 2.0.0 (2023-01-15)
### Added
- `SignatureEncoding` trait as a replacement for `Signature` trait and the
now removed `AsRef<[u8]>` bound on signatures ([#1141])
- New `Keypair` trait which returns owned keys instead of borrowed ([#1141])
### Changed
- `derive-preview` has been renamed to `derive` and stabilized ([#1141])
- `digest-preview` renamed to `digest`, still unstable ([#1210])
- `hazmat-preview` feature stabilized and removed, always on ([#1141])
- `rand-preview` renamed to `rand_core`, still unstable ([#1210])
- `std` feature is no longer enabled by default ([#1141])
- Old `Keypair` trait renamed to `KeypairRef` ([#1141])
- Signature generic parameter removed from `Keypair`/`KeypairRef` ([#1141])
- Use `&mut impl CryptoRngCore` RNG arguments ([#1147])
### Removed
- `Signature` trait - replaced by `SignatureEncoding` ([#1141])
- `hazmat-preview` feature, now always on ([#1141])
[#1141]: https://github.com/RustCrypto/traits/pull/1141
[#1147]: https://github.com/RustCrypto/traits/pull/1147
[#1210]: https://github.com/RustCrypto/traits/pull/1141
## 1.6.4 (2022-10-06)
### Added
- `RandomizedPrehashSigner` trait in `hazmat` module ([#1130])
[#1130]: https://github.com/RustCrypto/traits/pull/1130
## 1.6.3 (2022-09-16)
### Changed
- Bump `signature_derive` to v1.0.0-pre.7 ([#1119])
[#1119]: https://github.com/RustCrypto/traits/pull/1119
## 1.6.2 (2022-09-15)
### Changed
- Relax `Keypair` type bounds ([#1107])
[#1107]: https://github.com/RustCrypto/traits/pull/1107
## 1.6.1 (2022-09-12) [YANKED]
### Added
- `hazmat-preview` feature with `PrehashSigner`/`PrehashVerifier` traits ([#1099])
### Changed
- Bump `signature_derive` to v1.0.0-pre.6 ([#1104])
[#1099]: https://github.com/RustCrypto/traits/pull/1099
[#1104]: https://github.com/RustCrypto/traits/pull/1104
## 1.6.0 (2022-08-14) [YANKED]
### Added
- `Keypair` trait ([#1080])
### Changed
- Rust 2021 edition upgrade; MSRV 1.56 ([#1081])
- Bump `signature_derive` dependency to v1.0.0-pre.5 ([#1082])
- Bump `hex-literal` dependency to v0.3 ([#1083])
[#1080]: https://github.com/RustCrypto/traits/pull/1080
[#1081]: https://github.com/RustCrypto/traits/pull/1081
[#1082]: https://github.com/RustCrypto/traits/pull/1082
[#1083]: https://github.com/RustCrypto/traits/pull/1083
## 1.5.0 (2022-01-04)
### Changed
- Bump `digest` dependency to v0.10 ([#850])
- Bump `signature-derive` dependency to v1.0.0-pre.4 ([#866])
[#850]: https://github.com/RustCrypto/traits/pull/850
[#866]: https://github.com/RustCrypto/traits/pull/866
## 1.4.0 (2021-10-20)
### Added
- Re-export `rand_core` when the `rand-preview` feature is enabled ([#683])
- `SignerMut` trait ([#734])
### Fixed
- Show error source in `Display` impl ([#791])
[#683]: https://github.com/RustCrypto/traits/pull/683
[#734]: https://github.com/RustCrypto/traits/pull/734
[#791]: https://github.com/RustCrypto/traits/pull/791
## 1.3.2 (2021-10-21)
### Fixed
- Backport changes from [#791] to the 1.3.x series.
## 1.3.1 (2021-06-29)
### Added
- `Result` alias ([#676])
[#676]: https://github.com/RustCrypto/traits/pull/676
## 1.3.0 (2021-01-06)
### Changed
- Bump `rand_core` to v0.6 ([#457])
- Bump `signature-derive` v1.0.0-pre.3 ([#459])
[#457]: https://github.com/RustCrypto/traits/pull/457
[#459]: https://github.com/RustCrypto/traits/pull/459
## 1.2.2 (2020-07-29)
### Added
- `RandomizedDigestSigner` ([#235])
[#235]: https://github.com/RustCrypto/traits/pull/235
## 1.2.1 (2020-07-29)
### Removed
- RNG generic parameter `R` from `RandomizedSigner` ([#231])
[#231]: https://github.com/RustCrypto/traits/pull/231
## 1.2.0 (2020-07-29) [YANKED]
- Note: this release was published without the intended changes
## 1.1.0 (2020-06-09)
### Changed
- Upgrade `digest` to v0.9; MSRV 1.41+ ([#186])
[#186]: https://github.com/RustCrypto/traits/pull/186
## 1.0.1 (2020-04-19)
### Changed
- Upgrade `signature_derive` to v1.0.0-pre.2 ([#98])
[#98]: https://github.com/RustCrypto/traits/pull/98
## 1.0.0 (2020-04-18)
Initial 1.0 release! 🎉
### Changed
- Rename `DigestSignature` => `PrehashSignature` ([#96])
[#96]: https://github.com/RustCrypto/traits/pull/96
## 1.0.0-pre.5 (2020-03-16)
### Changed
- Improve `Debug` impl on `Error` ([#89])
- Rename `Signature::as_slice` -> `as_bytes` ([#87])
[#89]: https://github.com/RustCrypto/traits/pull/89
[#87]: https://github.com/RustCrypto/traits/pull/87
## 1.0.0-pre.4 (2020-03-15)
### Added
- Mark preview features as unstable in `Cargo.toml` ([#82])
### Changed
- Have `Signature::from_bytes` take a byte slice ([#84])
- Ensure `Error::new()` is mandatory ([#83])
### Removed
- `BoxError` type alias ([#81])
[#84]: https://github.com/RustCrypto/traits/pull/84
[#83]: https://github.com/RustCrypto/traits/pull/83
[#82]: https://github.com/RustCrypto/traits/pull/82
[#81]: https://github.com/RustCrypto/traits/pull/81
## 1.0.0-pre.3 (2020-03-08)
### Fixed
- docs.rs rendering ([#76])
[#76]: https://github.com/RustCrypto/traits/pull/76
## 1.0.0-pre.2 (2020-03-08)
### Added
- `RandomizedSigner` trait ([#73])
- Design documentation ([#72])
### Changed
- Error cleanups ([#74])
- Crate moved to `RustCrypto/traits` ([#71])
[#74]: https://github.com/RustCrypto/traits/pull/74
[#73]: https://github.com/RustCrypto/traits/pull/73
[#72]: https://github.com/RustCrypto/traits/pull/72
[#71]: https://github.com/RustCrypto/traits/pull/71
## 1.0.0-pre.1 (2019-10-27)
### Changed
- Use `Error::source` instead of `::cause` ([RustCrypto/signatures#37])
### Removed
- Remove `alloc` feature; MSRV 1.34+ ([RustCrypto/signatures#38])
[RustCrypto/signatures#38]: https://github.com/RustCrypto/signatures/pull/38
[RustCrypto/signatures#37]: https://github.com/RustCrypto/signatures/pull/37
## 1.0.0-pre.0 (2019-10-11)
### Changed
- Revert removal of `DigestSignature` ([RustCrypto/signatures#33])
- 1.0 stabilization proposal ([RustCrypto/signatures#32])
[RustCrypto/signatures#33]: https://github.com/RustCrypto/signatures/pull/33
[RustCrypto/signatures#32]: https://github.com/RustCrypto/signatures/pull/32
## 0.3.0 (2019-10-10)
### Changed
- Simplify alloc gating; MSRV 1.36+ ([RustCrypto/signatures#28])
- Replace `DigestSignature` trait with `#[digest(...)]` attribute ([RustCrypto/signatures#27])
- signature_derive: Upgrade to 1.x proc macro crates ([RustCrypto/signatures#26])
[RustCrypto/signatures#28]: https://github.com/RustCrypto/signatures/pull/28
[RustCrypto/signatures#27]: https://github.com/RustCrypto/signatures/pull/27
[RustCrypto/signatures#26]: https://github.com/RustCrypto/signatures/pull/27
## 0.2.0 (2019-06-06)
### Added
- `signature_derive`: Custom derive support for `Signer`/`Verifier` ([RustCrypto/signatures#18])
### Changed
- Have `DigestSigner`/`DigestVerifier` take `Digest` instance ([RustCrypto/signatures#17])
[RustCrypto/signatures#18]: https://github.com/RustCrypto/signatures/pull/18
[RustCrypto/signatures#17]: https://github.com/RustCrypto/signatures/pull/17
## 0.1.0 (2019-05-25)
- Initial release

69
vendor/signature/Cargo.toml vendored Normal file
View File

@@ -0,0 +1,69 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
[package]
edition = "2021"
rust-version = "1.60"
name = "signature"
version = "2.2.0"
authors = ["RustCrypto Developers"]
description = "Traits for cryptographic signature algorithms (e.g. ECDSA, Ed25519)"
documentation = "https://docs.rs/signature"
readme = "README.md"
keywords = [
"crypto",
"ecdsa",
"ed25519",
"signature",
"signing",
]
categories = [
"cryptography",
"no-std",
]
license = "Apache-2.0 OR MIT"
repository = "https://github.com/RustCrypto/traits/tree/master/signature"
[package.metadata.docs.rs]
all-features = true
rustdoc-args = [
"--cfg",
"docsrs",
]
[dependencies.derive]
version = "2"
optional = true
package = "signature_derive"
[dependencies.digest]
version = "0.10.6"
optional = true
default-features = false
[dependencies.rand_core]
version = "0.6.4"
optional = true
default-features = false
[dev-dependencies.hex-literal]
version = "0.4"
[dev-dependencies.sha2]
version = "0.10"
default-features = false
[features]
alloc = []
std = [
"alloc",
"rand_core?/std",
]

201
vendor/signature/LICENSE-APACHE vendored Normal file
View File

@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

25
vendor/signature/LICENSE-MIT vendored Normal file
View File

@@ -0,0 +1,25 @@
Copyright (c) 2018-2023 RustCrypto Developers
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

71
vendor/signature/README.md vendored Normal file
View File

@@ -0,0 +1,71 @@
# [RustCrypto]: Digital Signature Algorithms
[![crate][crate-image]][crate-link]
[![Docs][docs-image]][docs-link]
[![Build Status][build-image]][build-link]
![Apache2/MIT licensed][license-image]
![Rust Version][rustc-image]
[![Project Chat][chat-image]][chat-link]
This crate contains traits which provide generic, object-safe APIs for
generating and verifying [digital signatures].
Used by the [`dsa`], [`ecdsa`], [`ed25519`], and [`rsa`] crates maintained by
the [RustCrypto] organization, as well as [`ed25519-dalek`].
[Documentation][docs-link]
## Minimum Supported Rust Version
Rust **1.60** or higher.
Minimum supported Rust version can be changed in the future, but it will be
done with a minor version bump.
## SemVer Policy
- All on-by-default features of this library are covered by SemVer
- MSRV is considered exempt from SemVer as noted above
- The `derive` feature is stable and covered by SemVer
- The off-by-default features `digest` and `rand_core` are unstable features
which are also considered exempt from SemVer as they correspond to pre-1.0
crates which are still subject to changes. Breaking changes to these features
will, like MSRV, be done with a minor version bump.
## License
Licensed under either of
* [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
* [MIT license](http://opensource.org/licenses/MIT)
at your option.
### Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.
[//]: # (badges)
[crate-image]: https://buildstats.info/crate/signature
[crate-link]: https://crates.io/crates/signature
[docs-image]: https://docs.rs/signature/badge.svg
[docs-link]: https://docs.rs/signature/
[build-image]: https://github.com/RustCrypto/traits/actions/workflows/signature.yml/badge.svg
[build-link]: https://github.com/RustCrypto/traits/actions/workflows/signature.yml
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
[rustc-image]: https://img.shields.io/badge/rustc-1.60+-blue.svg
[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg
[chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260048-signatures
[//]: # (links)
[RustCrypto]: https://github.com/RustCrypto/
[digital signatures]: https://en.wikipedia.org/wiki/Digital_signature
[`dsa`]: https://github.com/RustCrypto/signatures/tree/master/dsa
[`ecdsa`]: https://github.com/RustCrypto/signatures/tree/master/ecdsa
[`ed25519`]: https://github.com/RustCrypto/signatures/tree/master/ed25519
[`ed25519-dalek`]: https://github.com/dalek-cryptography/ed25519-dalek
[`rsa`]: https://github.com/RustCrypto/RSA

31
vendor/signature/src/encoding.rs vendored Normal file
View File

@@ -0,0 +1,31 @@
//! Encoding support.
#[cfg(feature = "alloc")]
use alloc::vec::Vec;
/// Support for decoding/encoding signatures as bytes.
pub trait SignatureEncoding:
Clone + Sized + for<'a> TryFrom<&'a [u8]> + TryInto<Self::Repr>
{
/// Byte representation of a signature.
type Repr: 'static + AsRef<[u8]> + Clone + Send + Sync;
/// Encode signature as its byte representation.
fn to_bytes(&self) -> Self::Repr {
self.clone()
.try_into()
.ok()
.expect("signature encoding error")
}
/// Encode signature as a byte vector.
#[cfg(feature = "alloc")]
fn to_vec(&self) -> Vec<u8> {
self.to_bytes().as_ref().to_vec()
}
/// Get the length of this signature when encoded.
fn encoded_len(&self) -> usize {
self.to_bytes().as_ref().len()
}
}

116
vendor/signature/src/error.rs vendored Normal file
View File

@@ -0,0 +1,116 @@
//! Signature error types
use core::fmt::{self, Debug, Display};
#[cfg(feature = "std")]
use std::boxed::Box;
/// Result type.
///
/// A result with the `signature` crate's [`Error`] type.
pub type Result<T> = core::result::Result<T, Error>;
/// Signature errors.
///
/// This type is deliberately opaque as to avoid sidechannel leakage which
/// could potentially be used recover signing private keys or forge signatures
/// (e.g. [BB'06]).
///
/// When the `std` feature is enabled, it impls [`std::error::Error`] and
/// supports an optional [`std::error::Error::source`], which can be used by
/// things like remote signers (e.g. HSM, KMS) to report I/O or auth errors.
///
/// [BB'06]: https://en.wikipedia.org/wiki/Daniel_Bleichenbacher
#[derive(Default)]
#[non_exhaustive]
pub struct Error {
/// Source of the error (if applicable).
#[cfg(feature = "std")]
source: Option<Box<dyn std::error::Error + Send + Sync + 'static>>,
}
impl Error {
/// Create a new error with no associated source
pub fn new() -> Self {
Self::default()
}
/// Create a new error with an associated source.
///
/// **NOTE:** The "source" should **NOT** be used to propagate cryptographic
/// errors e.g. signature parsing or verification errors. The intended use
/// cases are for propagating errors related to external signers, e.g.
/// communication/authentication errors with HSMs, KMS, etc.
#[cfg(feature = "std")]
pub fn from_source(
source: impl Into<Box<dyn std::error::Error + Send + Sync + 'static>>,
) -> Self {
Self {
source: Some(source.into()),
}
}
}
impl Debug for Error {
#[cfg(not(feature = "std"))]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("signature::Error {}")
}
#[cfg(feature = "std")]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("signature::Error { source: ")?;
if let Some(source) = &self.source {
write!(f, "Some({})", source)?;
} else {
f.write_str("None")?;
}
f.write_str(" }")
}
}
impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("signature error")?;
#[cfg(feature = "std")]
{
if let Some(source) = &self.source {
write!(f, ": {}", source)?;
}
}
Ok(())
}
}
#[cfg(feature = "std")]
impl From<Box<dyn std::error::Error + Send + Sync + 'static>> for Error {
fn from(source: Box<dyn std::error::Error + Send + Sync + 'static>) -> Error {
Self::from_source(source)
}
}
#[cfg(feature = "rand_core")]
impl From<rand_core::Error> for Error {
#[cfg(not(feature = "std"))]
fn from(_source: rand_core::Error) -> Error {
Error::new()
}
#[cfg(feature = "std")]
fn from(source: rand_core::Error) -> Error {
Error::from_source(source)
}
}
#[cfg(feature = "std")]
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
self.source
.as_ref()
.map(|source| source.as_ref() as &(dyn std::error::Error + 'static))
}
}

70
vendor/signature/src/hazmat.rs vendored Normal file
View File

@@ -0,0 +1,70 @@
//! Hazardous Materials: low-level APIs which can be insecure if misused.
//!
//! The traits in this module are not generally recommended, and should only be
//! used in special cases where they are specifically needed.
//!
//! Using them incorrectly can introduce security vulnerabilities. Please
//! carefully read the documentation before attempting to use them.
use crate::Error;
#[cfg(feature = "rand_core")]
use crate::rand_core::CryptoRngCore;
/// Sign the provided message prehash, returning a digital signature.
pub trait PrehashSigner<S> {
/// Attempt to sign the given message digest, returning a digital signature
/// on success, or an error if something went wrong.
///
/// The `prehash` parameter should be the output of a secure cryptographic
/// hash function.
///
/// This API takes a `prehash` byte slice as there can potentially be many
/// compatible lengths for the message digest for a given concrete signature
/// algorithm.
///
/// Allowed lengths are algorithm-dependent and up to a particular
/// implementation to decide.
fn sign_prehash(&self, prehash: &[u8]) -> Result<S, Error>;
}
/// Sign the provided message prehash using the provided external randomness source, returning a digital signature.
#[cfg(feature = "rand_core")]
pub trait RandomizedPrehashSigner<S> {
/// Attempt to sign the given message digest, returning a digital signature
/// on success, or an error if something went wrong.
///
/// The `prehash` parameter should be the output of a secure cryptographic
/// hash function.
///
/// This API takes a `prehash` byte slice as there can potentially be many
/// compatible lengths for the message digest for a given concrete signature
/// algorithm.
///
/// Allowed lengths are algorithm-dependent and up to a particular
/// implementation to decide.
fn sign_prehash_with_rng(
&self,
rng: &mut impl CryptoRngCore,
prehash: &[u8],
) -> Result<S, Error>;
}
/// Verify the provided message prehash using `Self` (e.g. a public key)
pub trait PrehashVerifier<S> {
/// Use `Self` to verify that the provided signature for a given message
/// `prehash` is authentic.
///
/// The `prehash` parameter should be the output of a secure cryptographic
/// hash function.
///
/// Returns `Error` if it is inauthentic or some other error occurred, or
/// otherwise returns `Ok(())`.
///
/// # ⚠️ Security Warning
///
/// If `prehash` is something other than the output of a cryptographically
/// secure hash function, an attacker can potentially forge signatures by
/// solving a system of linear equations.
fn verify_prehash(&self, prehash: &[u8], signature: &S) -> Result<(), Error>;
}

29
vendor/signature/src/keypair.rs vendored Normal file
View File

@@ -0,0 +1,29 @@
//! Signing keypairs.
/// Signing keypair with an associated verifying key.
///
/// This represents a type which holds both a signing key and a verifying key.
pub trait Keypair {
/// Verifying key type for this keypair.
type VerifyingKey: Clone;
/// Get the verifying key which can verify signatures produced by the
/// signing key portion of this keypair.
fn verifying_key(&self) -> Self::VerifyingKey;
}
/// Signing keypair with an associated verifying key.
///
/// This represents a type which holds both a signing key and a verifying key.
pub trait KeypairRef: AsRef<Self::VerifyingKey> {
/// Verifying key type for this keypair.
type VerifyingKey: Clone;
}
impl<K: KeypairRef> Keypair for K {
type VerifyingKey = <Self as KeypairRef>::VerifyingKey;
fn verifying_key(&self) -> Self::VerifyingKey {
self.as_ref().clone()
}
}

158
vendor/signature/src/lib.rs vendored Normal file
View File

@@ -0,0 +1,158 @@
#![no_std]
#![doc = include_str!("../README.md")]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg",
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg"
)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![forbid(unsafe_code)]
#![warn(
clippy::mod_module_files,
clippy::unwrap_used,
missing_docs,
rust_2018_idioms,
unused_lifetimes,
unused_qualifications
)]
//! # Design
//!
//! This crate provides a common set of traits for signing and verifying
//! digital signatures intended to be implemented by libraries which produce
//! or contain implementations of digital signature algorithms, and used by
//! libraries which want to produce or verify digital signatures while
//! generically supporting any compatible backend.
//!
//! ## Goals
//!
//! The traits provided by this crate were designed with the following goals
//! in mind:
//!
//! - Provide an easy-to-use, misuse resistant API optimized for consumers
//! (as opposed to implementers) of its traits.
//! - Support common type-safe wrappers around "bag-of-bytes" representations
//! which can be directly parsed from or written to the "wire".
//! - Expose a trait/object-safe API where signers/verifiers spanning multiple
//! homogeneous provider implementations can be seamlessly leveraged together
//! in the same logical "keyring" so long as they operate on the same
//! underlying signature type.
//! - Allow one provider type to potentially implement support (including
//! being generic over) several signature types.
//! - Keep signature algorithm customizations / "knobs" out-of-band from the
//! signing/verification APIs, ideally pushing such concerns into the type
//! system so that algorithm mismatches are caught as type errors.
//! - Opaque error type which minimizes information leaked from cryptographic
//! failures, as "rich" error types in these scenarios are often a source
//! of sidechannel information for attackers (e.g. [BB'06])
//!
//! [BB'06]: https://en.wikipedia.org/wiki/Daniel_Bleichenbacher
//!
//! ## Implementation
//!
//! To accomplish the above goals, the [`Signer`] and [`Verifier`] traits
//! provided by this are generic over a signature value, and use generic
//! parameters rather than associated types. Notably, they use such a parameter
//! for the return value, allowing it to be inferred by the type checker based
//! on the desired signature type.
//!
//! ## Alternatives considered
//!
//! This crate is based on many years of exploration of how to encapsulate
//! digital signature systems in the most flexible, developer-friendly way.
//! During that time many design alternatives were explored, tradeoffs
//! compared, and ultimately the provided API was selected.
//!
//! The tradeoffs made in this API have all been to improve simplicity,
//! ergonomics, type safety, and flexibility for *consumers* of the traits.
//! At times, this has come at a cost to implementers. Below are some concerns
//! we are cognizant of which were considered in the design of the API:
//!
//! - "Bag-of-bytes" serialization precludes signature providers from using
//! their own internal representation of a signature, which can be helpful
//! for many reasons (e.g. advanced signature system features like batch
//! verification).
//! - Associated types, rather than generic parameters of traits, could allow
//! more customization of the types used by a particular signature system,
//! e.g. using custom error types.
//!
//! It may still make sense to continue to explore the above tradeoffs, but
//! with a *new* set of traits which are intended to be implementor-friendly,
//! rather than consumer friendly. The existing [`Signer`] and [`Verifier`]
//! traits could have blanket impls for the "provider-friendly" traits.
//! However, as noted above this is a design space easily explored after
//! stabilizing the consumer-oriented traits, and thus we consider these
//! more important.
//!
//! That said, below are some caveats of trying to design such traits, and
//! why we haven't actively pursued them:
//!
//! - Generics in the return position are already used to select which trait
//! impl to use, i.e. for a particular signature algorithm/system. Avoiding
//! a unified, concrete signature type adds another dimension to complexity
//! and compiler errors, and in our experience makes them unsuitable for this
//! sort of API. We believe such an API is the natural one for signature
//! systems, reflecting the natural way they are written absent a trait.
//! - Associated types preclude multiple implementations of the same trait.
//! These parameters are common in signature systems, notably ones which
//! support different serializations of a signature (e.g. raw vs ASN.1).
//! - Digital signatures are almost always larger than the present 32-entry
//! trait impl limitation on array types, which complicates bounds
//! for these types (particularly things like `From` or `Borrow` bounds).
//!
//! ## Unstable features
//!
//! Despite being post-1.0, this crate includes off-by-default unstable
//! optional features, each of which depends on a pre-1.0
//! crate.
//!
//! These features are considered exempt from SemVer. See the
//! [SemVer policy](#semver-policy) above for more information.
//!
//! The following unstable features are presently supported:
//!
//! - `digest`: enables the [`DigestSigner`] and [`DigestVerifier`]
//! traits which are based on the [`Digest`] trait from the [`digest`] crate.
//! These traits are used for representing signature systems based on the
//! [Fiat-Shamir heuristic] which compute a random challenge value to sign
//! by computing a cryptographically secure digest of the input message.
//! - `rand_core`: enables the [`RandomizedSigner`] trait for signature
//! systems which rely on a cryptographically secure random number generator
//! for security.
//!
//! NOTE: the [`async-signature`] crate contains experimental `async` support
//! for [`Signer`] and [`DigestSigner`].
//!
//! [`async-signature`]: https://docs.rs/async-signature
//! [`digest`]: https://docs.rs/digest/
//! [`Digest`]: https://docs.rs/digest/latest/digest/trait.Digest.html
//! [Fiat-Shamir heuristic]: https://en.wikipedia.org/wiki/Fiat%E2%80%93Shamir_heuristic
#[cfg(feature = "alloc")]
extern crate alloc;
#[cfg(feature = "std")]
extern crate std;
pub mod hazmat;
mod encoding;
mod error;
mod keypair;
mod signer;
mod verifier;
#[cfg(feature = "digest")]
mod prehash_signature;
pub use crate::{encoding::*, error::*, keypair::*, signer::*, verifier::*};
#[cfg(feature = "derive")]
pub use derive::{Signer, Verifier};
#[cfg(all(feature = "derive", feature = "digest"))]
pub use derive::{DigestSigner, DigestVerifier};
#[cfg(feature = "digest")]
pub use {crate::prehash_signature::*, digest};
#[cfg(feature = "rand_core")]
pub use rand_core;

View File

@@ -0,0 +1,31 @@
//! `PrehashSignature` trait.
/// For intra-doc link resolution.
#[allow(unused_imports)]
use crate::{
signer::{DigestSigner, Signer},
verifier::{DigestVerifier, Verifier},
};
/// Marker trait for `Signature` types computable as `𝐒(𝐇(𝒎))`
/// i.e. ones which prehash a message to be signed as `𝐇(𝒎)`
///
/// Where:
///
/// - `𝐒`: signature algorithm
/// - `𝐇`: hash (a.k.a. digest) function
/// - `𝒎`: message
///
/// This approach is relatively common in signature schemes based on the
/// [Fiat-Shamir heuristic].
///
/// For signature types that implement this trait, when the `derive` crate
/// feature is enabled a custom derive for [`Signer`] is available for any
/// types that impl [`DigestSigner`], and likewise for deriving [`Verifier`] for
/// types which impl [`DigestVerifier`].
///
/// [Fiat-Shamir heuristic]: https://en.wikipedia.org/wiki/Fiat%E2%80%93Shamir_heuristic
pub trait PrehashSignature {
/// Preferred `Digest` algorithm to use when computing this signature type.
type Digest: digest::Digest;
}

118
vendor/signature/src/signer.rs vendored Normal file
View File

@@ -0,0 +1,118 @@
//! Traits for generating digital signatures
use crate::error::Error;
#[cfg(feature = "digest")]
use crate::digest::Digest;
#[cfg(feature = "rand_core")]
use crate::rand_core::CryptoRngCore;
/// Sign the provided message bytestring using `Self` (e.g. a cryptographic key
/// or connection to an HSM), returning a digital signature.
pub trait Signer<S> {
/// Sign the given message and return a digital signature
fn sign(&self, msg: &[u8]) -> S {
self.try_sign(msg).expect("signature operation failed")
}
/// Attempt to sign the given message, returning a digital signature on
/// success, or an error if something went wrong.
///
/// The main intended use case for signing errors is when communicating
/// with external signers, e.g. cloud KMS, HSMs, or other hardware tokens.
fn try_sign(&self, msg: &[u8]) -> Result<S, Error>;
}
/// Sign the provided message bytestring using `&mut Self` (e.g. an evolving
/// cryptographic key such as a stateful hash-based signature), returning a
/// digital signature.
pub trait SignerMut<S> {
/// Sign the given message, update the state, and return a digital signature.
fn sign(&mut self, msg: &[u8]) -> S {
self.try_sign(msg).expect("signature operation failed")
}
/// Attempt to sign the given message, updating the state, and returning a
/// digital signature on success, or an error if something went wrong.
///
/// Signing can fail, e.g., if the number of time periods allowed by the
/// current key is exceeded.
fn try_sign(&mut self, msg: &[u8]) -> Result<S, Error>;
}
/// Blanket impl of [`SignerMut`] for all [`Signer`] types.
impl<S, T: Signer<S>> SignerMut<S> for T {
fn try_sign(&mut self, msg: &[u8]) -> Result<S, Error> {
T::try_sign(self, msg)
}
}
/// Sign the given prehashed message [`Digest`] using `Self`.
///
/// ## Notes
///
/// This trait is primarily intended for signature algorithms based on the
/// [Fiat-Shamir heuristic], a method for converting an interactive
/// challenge/response-based proof-of-knowledge protocol into an offline
/// digital signature through the use of a random oracle, i.e. a digest
/// function.
///
/// The security of such protocols critically rests upon the inability of
/// an attacker to solve for the output of the random oracle, as generally
/// otherwise such signature algorithms are a system of linear equations and
/// therefore doing so would allow the attacker to trivially forge signatures.
///
/// To prevent misuse which would potentially allow this to be possible, this
/// API accepts a [`Digest`] instance, rather than a raw digest value.
///
/// [Fiat-Shamir heuristic]: https://en.wikipedia.org/wiki/Fiat%E2%80%93Shamir_heuristic
#[cfg(feature = "digest")]
pub trait DigestSigner<D: Digest, S> {
/// Sign the given prehashed message [`Digest`], returning a signature.
///
/// Panics in the event of a signing error.
fn sign_digest(&self, digest: D) -> S {
self.try_sign_digest(digest)
.expect("signature operation failed")
}
/// Attempt to sign the given prehashed message [`Digest`], returning a
/// digital signature on success, or an error if something went wrong.
fn try_sign_digest(&self, digest: D) -> Result<S, Error>;
}
/// Sign the given message using the provided external randomness source.
#[cfg(feature = "rand_core")]
pub trait RandomizedSigner<S> {
/// Sign the given message and return a digital signature
fn sign_with_rng(&self, rng: &mut impl CryptoRngCore, msg: &[u8]) -> S {
self.try_sign_with_rng(rng, msg)
.expect("signature operation failed")
}
/// Attempt to sign the given message, returning a digital signature on
/// success, or an error if something went wrong.
///
/// The main intended use case for signing errors is when communicating
/// with external signers, e.g. cloud KMS, HSMs, or other hardware tokens.
fn try_sign_with_rng(&self, rng: &mut impl CryptoRngCore, msg: &[u8]) -> Result<S, Error>;
}
/// Combination of [`DigestSigner`] and [`RandomizedSigner`] with support for
/// computing a signature over a digest which requires entropy from an RNG.
#[cfg(all(feature = "digest", feature = "rand_core"))]
pub trait RandomizedDigestSigner<D: Digest, S> {
/// Sign the given prehashed message `Digest`, returning a signature.
///
/// Panics in the event of a signing error.
fn sign_digest_with_rng(&self, rng: &mut impl CryptoRngCore, digest: D) -> S {
self.try_sign_digest_with_rng(rng, digest)
.expect("signature operation failed")
}
/// Attempt to sign the given prehashed message `Digest`, returning a
/// digital signature on success, or an error if something went wrong.
fn try_sign_digest_with_rng(&self, rng: &mut impl CryptoRngCore, digest: D)
-> Result<S, Error>;
}

41
vendor/signature/src/verifier.rs vendored Normal file
View File

@@ -0,0 +1,41 @@
//! Trait for verifying digital signatures
use crate::error::Error;
#[cfg(feature = "digest")]
use crate::digest::Digest;
/// Verify the provided message bytestring using `Self` (e.g. a public key)
pub trait Verifier<S> {
/// Use `Self` to verify that the provided signature for a given message
/// bytestring is authentic.
///
/// Returns `Error` if it is inauthentic, or otherwise returns `()`.
fn verify(&self, msg: &[u8], signature: &S) -> Result<(), Error>;
}
/// Verify the provided signature for the given prehashed message [`Digest`]
/// is authentic.
///
/// ## Notes
///
/// This trait is primarily intended for signature algorithms based on the
/// [Fiat-Shamir heuristic], a method for converting an interactive
/// challenge/response-based proof-of-knowledge protocol into an offline
/// digital signature through the use of a random oracle, i.e. a digest
/// function.
///
/// The security of such protocols critically rests upon the inability of
/// an attacker to solve for the output of the random oracle, as generally
/// otherwise such signature algorithms are a system of linear equations and
/// therefore doing so would allow the attacker to trivially forge signatures.
///
/// To prevent misuse which would potentially allow this to be possible, this
/// API accepts a [`Digest`] instance, rather than a raw digest value.
///
/// [Fiat-Shamir heuristic]: https://en.wikipedia.org/wiki/Fiat%E2%80%93Shamir_heuristic
#[cfg(feature = "digest")]
pub trait DigestVerifier<D: Digest, S> {
/// Verify the signature against the given [`Digest`] output.
fn verify_digest(&self, digest: D, signature: &S) -> Result<(), Error>;
}

Binary file not shown.

View File

@@ -0,0 +1 @@
{"name":"signature","vers":"2.2.0","deps":[{"name":"derive","req":"^2","features":[],"optional":true,"default_features":true,"target":null,"kind":"normal","registry":"https://github.com/rust-lang/crates.io-index","package":"signature_derive","public":null,"artifact":null,"bindep_target":null,"lib":false},{"name":"digest","req":"^0.10.6","features":[],"optional":true,"default_features":false,"target":null,"kind":"normal","registry":"https://github.com/rust-lang/crates.io-index","package":null,"public":null,"artifact":null,"bindep_target":null,"lib":false},{"name":"rand_core","req":"^0.6.4","features":[],"optional":true,"default_features":false,"target":null,"kind":"normal","registry":"https://github.com/rust-lang/crates.io-index","package":null,"public":null,"artifact":null,"bindep_target":null,"lib":false},{"name":"hex-literal","req":"^0.4","features":[],"optional":false,"default_features":true,"target":null,"kind":"dev","registry":"https://github.com/rust-lang/crates.io-index","package":null,"public":null,"artifact":null,"bindep_target":null,"lib":false},{"name":"sha2","req":"^0.10","features":[],"optional":false,"default_features":false,"target":null,"kind":"dev","registry":"https://github.com/rust-lang/crates.io-index","package":null,"public":null,"artifact":null,"bindep_target":null,"lib":false}],"features":{"alloc":[],"std":["alloc","rand_core?/std"]},"features2":null,"cksum":"1f0f4bbcfae4bbc8d914c00232d3e0e510ccf196860703ad3c4bb8c504a6df1a","yanked":null,"links":null,"rust_version":null,"v":2}

Binary file not shown.

82
vendor/signature/tests/derive.rs vendored Normal file
View File

@@ -0,0 +1,82 @@
//! Tests for code generated by `signature_derive`
#![cfg(all(feature = "derive", feature = "digest"))]
use digest::{generic_array::GenericArray, Digest, OutputSizeUser};
use hex_literal::hex;
use sha2::Sha256;
use signature::{
hazmat::{PrehashSigner, PrehashVerifier},
DigestSigner, DigestVerifier, Error, PrehashSignature, SignatureEncoding, Signer, Verifier,
};
/// Test vector to compute SHA-256 digest of
const INPUT_STRING: &[u8] = b"abc";
/// Expected SHA-256 digest for the input string
const INPUT_STRING_DIGEST: [u8; 32] =
hex!("ba7816bf 8f01cfea 414140de 5dae2223 b00361a3 96177a9c b410ff61 f20015ad");
type Repr = GenericArray<u8, <Sha256 as OutputSizeUser>::OutputSize>;
/// Dummy signature which just contains a digest output
#[derive(Clone, Debug)]
struct DummySignature(Repr);
impl PrehashSignature for DummySignature {
type Digest = Sha256;
}
impl SignatureEncoding for DummySignature {
type Repr = Repr;
}
impl TryFrom<&[u8]> for DummySignature {
type Error = Error;
fn try_from(bytes: &[u8]) -> Result<Self, Error> {
Ok(DummySignature(GenericArray::clone_from_slice(bytes)))
}
}
impl From<DummySignature> for Repr {
fn from(sig: DummySignature) -> Repr {
sig.0
}
}
/// Dummy signer which just returns the message digest as a `DummySignature`
#[derive(Signer, DigestSigner, Default)]
struct DummySigner {}
impl PrehashSigner<DummySignature> for DummySigner {
fn sign_prehash(&self, prehash: &[u8]) -> signature::Result<DummySignature> {
DummySignature::try_from(prehash)
}
}
/// Dummy verifier which ensures the `DummySignature` digest matches the
/// expected value.
///
/// Panics (via `assert_eq!`) if the value is not what is expected.
#[derive(Verifier, DigestVerifier, Default)]
struct DummyVerifier {}
impl PrehashVerifier<DummySignature> for DummyVerifier {
fn verify_prehash(&self, prehash: &[u8], signature: &DummySignature) -> signature::Result<()> {
assert_eq!(signature.to_bytes().as_slice(), prehash);
Ok(())
}
}
#[test]
fn derived_signer_impl() {
let sig: DummySignature = DummySigner::default().sign(INPUT_STRING);
assert_eq!(sig.to_bytes().as_slice(), INPUT_STRING_DIGEST.as_ref())
}
#[test]
fn derived_verifier_impl() {
let sig: DummySignature = DummySigner::default().sign(INPUT_STRING);
assert!(DummyVerifier::default().verify(INPUT_STRING, &sig).is_ok());
}