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/ed25519/.cargo-checksum.json vendored Normal file
View File

@@ -0,0 +1 @@
{"files":{".cargo_vcs_info.json":"77591943d2d2b66d7017b38acc7e72accf36a2041214eeb8e847cc36d9cf53b9","CHANGELOG.md":"48959783c47dda29c9c9a31b25a027ac47434d0283304a51ae46901adb66c318","Cargo.toml":"c6fffc86c6297739753fd78ad9ccb9c15385704329259a986530e09732957c82","Cargo.toml.orig":"3f788d5558fe6db65d6847d75c4c59161959d4d11140e2df5746955af100bc89","LICENSE-APACHE":"78779d420019e6b4630376af8e86b6b335ee8a2f89ede6e0411e0469a326aaa4","LICENSE-MIT":"b3470648aff02beb36d7a53240fc9260ed80ed93bd43bace6b67d7ef7336ee33","README.md":"ff72e7e62e3baa89106f854a4dd3fe29be43c6a16549d768a94ae920f5024485","src/hex.rs":"1a73417e4945e73627379dcc69d444044985c5aa60410c3d2edaff2198160692","src/lib.rs":"7407dd37d37865f43a346f4e156c492800a9992e8ab54bf49f95f5b7a42bd71c","src/pkcs8.rs":"bac999d6e9f48790857e63299c6cf6d570eda1a570e383813725ff8507a38fd8","src/serde.rs":"45f292387bf613e726302dfd87a5d05be706fac4603facccc9bc6c93157c6b77","tests/examples/pkcs8-v1.der":"80b885d1af82668ad76d1c5a1a916b5bfc23d247e2f7f450e45b5c1024843e96","tests/examples/pkcs8-v1.pem":"4b4fc44435f8d20dd4e915752db1019d3936877152b95d5f39414f422b1110cd","tests/examples/pkcs8-v2.der":"78f1cd2051065b209431249093f218b0e01a5fd0b9e756db820d4893d9dbbf55","tests/examples/pkcs8-v2.pem":"4e571bdf609198461c86e479f323dee566d9c2beda5d9e45fcc792f8297b041e","tests/examples/pubkey.der":"a1e9156054e04fac899ae9f275132cdc07a5dbc4ea2c2ad3a1ffc6e0d253681f","tests/examples/pubkey.pem":"f7a7c27ec5c95e97c8f2c4bc8483dad6b086101d7ce86272e09521ca25b32ead","tests/hex.rs":"ac79a35db758794e86a6f91fa93a8c74533881337b2f4f563eb344f6f8e263c0","tests/pkcs8.rs":"33449ad1f438e5415f4c97f8a2a64613b84f2850c1e03133261f0fc36cb095fa","tests/serde.rs":"9d06fd11f4164e63c577b5dffec94b4274bb9b206cbfc29f6b6566957eeb3858"},"package":"115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53"}

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

@@ -0,0 +1,6 @@
{
"git": {
"sha1": "07b095c32a3527ee47da5c4878bf203557b36e5e"
},
"path_in_vcs": "ed25519"
}

249
vendor/ed25519/CHANGELOG.md vendored Normal file
View File

@@ -0,0 +1,249 @@
# 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.3 (2023-10-15)
### Changed
- Bump `ring-compat` from 0.7 to 0.8 ([#744])
- Enable `pkcs8/std` feature when `std` feature is enabled ([#746])
- Hex-format `Signature` components in `Debug` impl ([#747])
[#744]: https://github.com/RustCrypto/signatures/pull/744
[#746]: https://github.com/RustCrypto/signatures/pull/746
[#747]: https://github.com/RustCrypto/signatures/pull/747
## 2.2.2 (2023-08-13)
### Changed
- Bump `ed25519-dalek` to v2 ([#738])
[#738]: https://github.com/RustCrypto/signatures/pull/738
## 2.2.1 (2023-04-03)
### Changed
- Bump `ring-compat` dev-dependency to v0.7 ([#692])
- Bump `ed25519-dalek` to v2.0.0-rc.2 ([#693])
[#692]: https://github.com/RustCrypto/signatures/pull/692
[#693]: https://github.com/RustCrypto/signatures/pull/693
## 2.2.0 (2023-03-01)
### Changed
- Bump `pkcs8` dependency to v0.10 ([#665])
[#665]: https://github.com/RustCrypto/signatures/pull/665
## 2.1.0 (2023-01-21)
### Changed
- Use namespaced features for `serde_bytes`; MSRV 1.60 ([#628])
[#628]: https://github.com/RustCrypto/signatures/pull/628
## 2.0.1 (2023-01-21)
### Changed
- Make `Signature` parsing infallible ([#623])
[#623]: https://github.com/RustCrypto/signatures/pull/623
## 2.0.0 (2023-01-15) [YANKED]
### Added
- `pkcs8` re-exports ([#589], [#590], [#591], [#592])
- `Signature::from_components` method ([#600])
- Impl `TryFrom<SignatureBytes>` for `Signature` ([#601])
### Changed
- Use `PublicKeyBytes` as `KeypairBytes::public_key` ([#570])
- `Signature::from_bytes` takes `SignatureBytes` as an argument ([#593])
- Store `R` and `s` components separately ([#595])
- Bump `signature` crate dependency to v2.0 ([#614])
### Removed
- Deprecated `From<[u8; 64]>` conversion for signature ([#564])
- `AsRef<[u8]>` impl on `signature` ([#595])
[#564]: https://github.com/RustCrypto/signatures/pull/564
[#570]: https://github.com/RustCrypto/signatures/pull/570
[#589]: https://github.com/RustCrypto/signatures/pull/589
[#590]: https://github.com/RustCrypto/signatures/pull/590
[#591]: https://github.com/RustCrypto/signatures/pull/591
[#592]: https://github.com/RustCrypto/signatures/pull/592
[#593]: https://github.com/RustCrypto/signatures/pull/593
[#595]: https://github.com/RustCrypto/signatures/pull/595
[#600]: https://github.com/RustCrypto/signatures/pull/600
[#601]: https://github.com/RustCrypto/signatures/pull/601
[#614]: https://github.com/RustCrypto/signatures/pull/614
## 1.5.3 (2023-01-15)
### Changed
- Fix `signature` version requirement which accidentally matched v2 or above ([#616])
[#616]: https://github.com/RustCrypto/signatures/pull/616
## 1.5.2 (2022-05-16) [YANKED]
### Fixed
- Overflow handling in `serde` deserializers ([#482])
[#482]: https://github.com/RustCrypto/signatures/pull/482
## 1.5.1 (2022-05-15) [YANKED]
### Fixed
- Use `TryInto` in `serde` deserializers ([#479])
[#479]: https://github.com/RustCrypto/signatures/pull/479
## 1.5.0 (2022-05-09) [YANKED]
### Changed
- Bump `pkcs8` dependency to v0.9 ([#473])
[#473]: https://github.com/RustCrypto/signatures/pull/473
## 1.4.1 (2022-03-18) [YANKED]
### Added
- License files ([#447])
- `pkcs8::PublicKeyBytes` type ([#455])
[#447]: https://github.com/RustCrypto/signatures/pull/447
[#455]: https://github.com/RustCrypto/signatures/pull/455
## 1.4.0 (2022-02-25) [YANKED]
This crate now requires **Rust 1.56** at a minimum as the Rust edition has been
upgraded to 2021.
Previous 1.x releases of this crate supported an MSRV of 1.47. If you would
like to use this crate with earlier releases of Rust, add the following version
constraint in your project's Cargo.toml to constrain it to the supported
version range:
```toml
[dependencies]
ed25519 = ">=1, <1.4" # ed25519 1.4 requires MSRV 1.56
```
Note that is our policy that we may change the MSRV in the future, but it will
be accompanied by a minor version bump.
### Added
- `Signature::to_vec` ([#428])
### Changed
- Rust 2021 edition upgrade ([#412])
[#412]: https://github.com/RustCrypto/signatures/pull/412
[#428]: https://github.com/RustCrypto/signatures/pull/428
## 1.3.0 (2021-11-18) [YANKED]
### Added
- `Signature::BYTE_SIZE` constant ([#380])
- PKCS#8 support via `KeypairBytes` type ([#381])
- `zeroize` feature ([#400])
- Impl `Display`/`LowerHex`/`UpperHex`/`FromStr` for `Signature` ([#402])
### Changed
- Deprecate `SIGNATURE_LENGTH` constant in favor of `Signature::BYTE_SIZE` ([#380])
- Deprecate `Signature::new` in favor of `Signature::from_bytes`/`TryFrom` ([#401])
- `Signature::new` now panics on invalid signatures ([#403])
[#380]: https://github.com/RustCrypto/signatures/pull/380
[#381]: https://github.com/RustCrypto/signatures/pull/381
[#400]: https://github.com/RustCrypto/signatures/pull/400
[#401]: https://github.com/RustCrypto/signatures/pull/401
[#402]: https://github.com/RustCrypto/signatures/pull/402
[#403]: https://github.com/RustCrypto/signatures/pull/403
## 1.2.0 (2021-07-21)
### Added
- `serde_bytes` optional dependency ([#337])
[#337]: https://github.com/RustCrypto/signatures/pull/337
## 1.1.1 (2021-04-30)
### Changed
- Updates for `ring-compat` v0.2.1 ([#291])
[#291]: https://github.com/RustCrypto/signatures/pull/291
## 1.1.0 (2021-04-30)
### Changed
- Bump `ring-compat` to v0.2; MSRV 1.47+ ([#289])
### Fixed
- Compile error in example ([#246])
[#246]: https://github.com/RustCrypto/signatures/pull/246
[#289]: https://github.com/RustCrypto/signatures/pull/289
## 1.0.3 (2020-10-12)
### Added
- `ring-compat` usage example ([#187])
[#187]: https://github.com/RustCrypto/signatures/pull/187
## 1.0.2 (2020-09-11)
### Added
- `ed25519-dalek` usage example ([#167])
[#167]: https://github.com/RustCrypto/signatures/pull/167
## 1.0.1 (2020-04-20)
### Added
- Usage documentation ([#83])
[#83]: https://github.com/RustCrypto/signatures/pull/83
## 1.0.0 (2020-04-18)
### Changed
- Upgrade `signature` crate to v1.0 final release ([#80])
[#80]: https://github.com/RustCrypto/signatures/pull/80
## 1.0.0-pre.4 (2020-03-17)
### Changed
- Avoid serializing a length prefix with `serde` ([#78])
[#78]: https://github.com/RustCrypto/signatures/pull/78
## 1.0.0-pre.3 (2020-03-16)
### Changed
- Upgrade `signature` crate to v1.0.0-pre.3 ([#74])
- Bump MSRV to 1.40 ([#75])
[#74]: https://github.com/RustCrypto/signatures/pull/74
[#75]: https://github.com/RustCrypto/signatures/pull/75
## 1.0.0-pre.2 (2020-03-08)
### Changed
- Upgrade to `signature` crate v1.0.0-pre.3 ([#71])
- Bump MSRV to 1.37 ([#63])
[#71]: https://github.com/RustCrypto/signatures/pull/71
[#63]: https://github.com/RustCrypto/signatures/pull/63
## 1.0.0-pre.1 (2019-10-11)
### Added
- Optional `serde` support ([#40])
- Add `TryFrom` impl for `Signature` ([#39])
### Changed
- Upgrade to `signature` 1.0.0-pre.1 ([#41])
[#41]: https://github.com/RustCrypto/signatures/pull/41
[#40]: https://github.com/RustCrypto/signatures/pull/40
[#39]: https://github.com/RustCrypto/signatures/pull/39
## 1.0.0-pre.0 (2019-10-11)
### Changed
- Upgrade to `signature` 1.0.0-pre.0 ([#34])
[#34]: https://github.com/RustCrypto/signatures/pull/34
## 0.2.0 (2019-10-10)
### Changed
- Upgrade to `signature` v0.3; MSRV 1.36+ ([#29])
[#29]: https://github.com/RustCrypto/signatures/pull/29
## 0.1.0 (2019-08-10)
- Initial release

101
vendor/ed25519/Cargo.toml vendored Normal file
View File

@@ -0,0 +1,101 @@
# 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 = "ed25519"
version = "2.2.3"
authors = ["RustCrypto Developers"]
description = """
Edwards Digital Signature Algorithm (EdDSA) over Curve25519 (as specified in RFC 8032)
support library providing signature type definitions and PKCS#8 private key
decoding/encoding support
"""
documentation = "https://docs.rs/ed25519"
readme = "README.md"
keywords = [
"crypto",
"curve25519",
"ecc",
"signature",
"signing",
]
categories = [
"cryptography",
"no-std",
]
license = "Apache-2.0 OR MIT"
repository = "https://github.com/RustCrypto/signatures/tree/master/ed25519"
[package.metadata.docs.rs]
all-features = true
rustdoc-args = [
"--cfg",
"docsrs",
]
[dependencies.pkcs8]
version = "0.10"
optional = true
[dependencies.serde]
version = "1"
optional = true
default-features = false
[dependencies.serde_bytes]
version = "0.11"
optional = true
[dependencies.signature]
version = "2"
default-features = false
[dependencies.zeroize]
version = "1"
optional = true
default-features = false
[dev-dependencies.bincode]
version = "1"
[dev-dependencies.ed25519-dalek]
version = "2"
features = ["rand_core"]
[dev-dependencies.hex-literal]
version = "0.4"
[dev-dependencies.rand_core]
version = "0.6"
features = ["std"]
[dev-dependencies.ring-compat]
version = "0.8"
features = ["signature"]
default-features = false
[features]
alloc = ["pkcs8?/alloc"]
default = ["std"]
pem = [
"alloc",
"pkcs8/pem",
]
serde_bytes = [
"serde",
"dep:serde_bytes",
]
std = [
"pkcs8?/std",
"signature/std",
]

201
vendor/ed25519/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 2018-2022 RustCrypto Developers
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/ed25519/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.

81
vendor/ed25519/README.md vendored Normal file
View File

@@ -0,0 +1,81 @@
# [RustCrypto]: Ed25519
[![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]
[Edwards Digital Signature Algorithm (EdDSA)][1] over Curve25519 as specified
in [RFC 8032][2].
[Documentation][docs-link]
## About
This crate doesn't contain an implementation of Ed25519, but instead
contains an [`ed25519::Signature`][3] type which other crates can use in
conjunction with the [`signature::Signer`][4] and [`signature::Verifier`][5]
traits.
These traits allow crates which produce and consume Ed25519 signatures
to be written abstractly in such a way that different signer/verifier
providers can be plugged in, enabling support for using different
Ed25519 implementations, including HSMs or Cloud KMS services.
## Minimum Supported Rust Version
This crate requires **Rust 1.60** at a minimum.
Our policy is to allow MSRV to be raised in future released without that
qualifing as a SemVer-breaking change, but it will be accompanied by a minor
version bump, ensuring if you lock to a minor version MSRV will be preserved
for the default feature set.
## SemVer Policy
- All on-by-default features of this library are covered by SemVer
- MSRV is considered exempt from SemVer as noted above
- The `pkcs8` module is exempted as it uses a pre-1.0 dependency, however,
breaking changes to this module will be accompanied by a minor version bump.
## License
All crates 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/ed25519
[crate-link]: https://crates.io/crates/ed25519
[docs-image]: https://docs.rs/ed25519/badge.svg
[docs-link]: https://docs.rs/ed25519/
[build-image]: https://github.com/RustCrypto/signatures/actions/workflows/ed25519.yml/badge.svg
[build-link]: https://github.com/RustCrypto/signatures/actions/workflows/ed25519.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
[//]: # (footnotes)
[1]: https://en.wikipedia.org/wiki/EdDSA#Ed25519
[2]: https://tools.ietf.org/html/rfc8032
[3]: https://docs.rs/ed25519/latest/ed25519/struct.Signature.html
[4]: https://docs.rs/signature/latest/signature/trait.Signer.html
[5]: https://docs.rs/signature/latest/signature/trait.Verifier.html

87
vendor/ed25519/src/hex.rs vendored Normal file
View File

@@ -0,0 +1,87 @@
//! Hexadecimal encoding support
// TODO(tarcieri): use `base16ct`?
use crate::{ComponentBytes, Error, Signature};
use core::{fmt, str};
/// Format a signature component as hex.
pub(crate) struct ComponentFormatter<'a>(pub(crate) &'a ComponentBytes);
impl fmt::Debug for ComponentFormatter<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "0x")?;
for byte in self.0 {
write!(f, "{:02x}", byte)?;
}
Ok(())
}
}
impl fmt::LowerHex for Signature {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
for component in [&self.R, &self.s] {
for byte in component {
write!(f, "{:02x}", byte)?;
}
}
Ok(())
}
}
impl fmt::UpperHex for Signature {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
for component in [&self.R, &self.s] {
for byte in component {
write!(f, "{:02X}", byte)?;
}
}
Ok(())
}
}
/// Decode a signature from hexadecimal.
///
/// Upper and lower case hexadecimal are both accepted, however mixed case is
/// rejected.
// TODO(tarcieri): use `base16ct`?
impl str::FromStr for Signature {
type Err = Error;
fn from_str(hex: &str) -> signature::Result<Self> {
if hex.as_bytes().len() != Signature::BYTE_SIZE * 2 {
return Err(Error::new());
}
let mut upper_case = None;
// Ensure all characters are valid and case is not mixed
for &byte in hex.as_bytes() {
match byte {
b'0'..=b'9' => (),
b'a'..=b'z' => match upper_case {
Some(true) => return Err(Error::new()),
Some(false) => (),
None => upper_case = Some(false),
},
b'A'..=b'Z' => match upper_case {
Some(true) => (),
Some(false) => return Err(Error::new()),
None => upper_case = Some(true),
},
_ => return Err(Error::new()),
}
}
let mut result = [0u8; Self::BYTE_SIZE];
for (digit, byte) in hex.as_bytes().chunks_exact(2).zip(result.iter_mut()) {
*byte = str::from_utf8(digit)
.ok()
.and_then(|s| u8::from_str_radix(s, 16).ok())
.ok_or_else(Error::new)?;
}
Self::try_from(&result[..])
}
}

419
vendor/ed25519/src/lib.rs vendored Normal file
View File

@@ -0,0 +1,419 @@
#![no_std]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![doc = include_str!("../README.md")]
#![doc(html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo_small.png")]
#![allow(non_snake_case)]
#![forbid(unsafe_code)]
#![warn(
clippy::unwrap_used,
missing_docs,
rust_2018_idioms,
unused_lifetimes,
unused_qualifications
)]
//! # Using Ed25519 generically over algorithm implementations/providers
//!
//! By using the `ed25519` crate, you can write code which signs and verifies
//! messages using the Ed25519 signature algorithm generically over any
//! supported Ed25519 implementation (see the next section for available
//! providers).
//!
//! This allows consumers of your code to plug in whatever implementation they
//! want to use without having to add all potential Ed25519 libraries you'd
//! like to support as optional dependencies.
//!
//! ## Example
//!
//! ```
//! use ed25519::signature::{Signer, Verifier};
//!
//! pub struct HelloSigner<S>
//! where
//! S: Signer<ed25519::Signature>
//! {
//! pub signing_key: S
//! }
//!
//! impl<S> HelloSigner<S>
//! where
//! S: Signer<ed25519::Signature>
//! {
//! pub fn sign(&self, person: &str) -> ed25519::Signature {
//! // NOTE: use `try_sign` if you'd like to be able to handle
//! // errors from external signing services/devices (e.g. HSM/KMS)
//! // <https://docs.rs/signature/latest/signature/trait.Signer.html#tymethod.try_sign>
//! self.signing_key.sign(format_message(person).as_bytes())
//! }
//! }
//!
//! pub struct HelloVerifier<V> {
//! pub verifying_key: V
//! }
//!
//! impl<V> HelloVerifier<V>
//! where
//! V: Verifier<ed25519::Signature>
//! {
//! pub fn verify(
//! &self,
//! person: &str,
//! signature: &ed25519::Signature
//! ) -> Result<(), ed25519::Error> {
//! self.verifying_key.verify(format_message(person).as_bytes(), signature)
//! }
//! }
//!
//! fn format_message(person: &str) -> String {
//! format!("Hello, {}!", person)
//! }
//! ```
//!
//! ## Using above example with `ed25519-dalek`
//!
//! The [`ed25519-dalek`] crate natively supports the [`ed25519::Signature`][`Signature`]
//! type defined in this crate along with the [`signature::Signer`] and
//! [`signature::Verifier`] traits.
//!
//! Below is an example of how a hypothetical consumer of the code above can
//! instantiate and use the previously defined `HelloSigner` and `HelloVerifier`
//! types with [`ed25519-dalek`] as the signing/verification provider:
//!
//! *NOTE: requires [`ed25519-dalek`] v2 or newer for compatibility with
//! `ed25519` v2.2+*.
//!
//! ```
//! use ed25519_dalek::{Signer, Verifier, Signature};
//! #
//! # pub struct HelloSigner<S>
//! # where
//! # S: Signer<Signature>
//! # {
//! # pub signing_key: S
//! # }
//! #
//! # impl<S> HelloSigner<S>
//! # where
//! # S: Signer<Signature>
//! # {
//! # pub fn sign(&self, person: &str) -> Signature {
//! # // NOTE: use `try_sign` if you'd like to be able to handle
//! # // errors from external signing services/devices (e.g. HSM/KMS)
//! # // <https://docs.rs/signature/latest/signature/trait.Signer.html#tymethod.try_sign>
//! # self.signing_key.sign(format_message(person).as_bytes())
//! # }
//! # }
//! #
//! # pub struct HelloVerifier<V> {
//! # pub verifying_key: V
//! # }
//! #
//! # impl<V> HelloVerifier<V>
//! # where
//! # V: Verifier<Signature>
//! # {
//! # pub fn verify(
//! # &self,
//! # person: &str,
//! # signature: &Signature
//! # ) -> Result<(), ed25519::Error> {
//! # self.verifying_key.verify(format_message(person).as_bytes(), signature)
//! # }
//! # }
//! #
//! # fn format_message(person: &str) -> String {
//! # format!("Hello, {}!", person)
//! # }
//! use rand_core::OsRng; // Requires the `std` feature of `rand_core`
//!
//! /// `HelloSigner` defined above instantiated with `ed25519-dalek` as
//! /// the signing provider.
//! pub type DalekHelloSigner = HelloSigner<ed25519_dalek::SigningKey>;
//!
//! let signing_key = ed25519_dalek::SigningKey::generate(&mut OsRng);
//! let signer = DalekHelloSigner { signing_key };
//! let person = "Joe"; // Message to sign
//! let signature = signer.sign(person);
//!
//! /// `HelloVerifier` defined above instantiated with `ed25519-dalek`
//! /// as the signature verification provider.
//! pub type DalekHelloVerifier = HelloVerifier<ed25519_dalek::VerifyingKey>;
//!
//! let verifying_key: ed25519_dalek::VerifyingKey = signer.signing_key.verifying_key();
//! let verifier = DalekHelloVerifier { verifying_key };
//! assert!(verifier.verify(person, &signature).is_ok());
//! ```
//!
//! ## Using above example with `ring-compat`
//!
//! The [`ring-compat`] crate provides wrappers for [*ring*] which implement
//! the [`signature::Signer`] and [`signature::Verifier`] traits for
//! [`ed25519::Signature`][`Signature`].
//!
//! Below is an example of how a hypothetical consumer of the code above can
//! instantiate and use the previously defined `HelloSigner` and `HelloVerifier`
//! types with [`ring-compat`] as the signing/verification provider:
//!
//! ```
//! use ring_compat::signature::{
//! ed25519::{Signature, SigningKey, VerifyingKey},
//! Signer, Verifier
//! };
//! #
//! # pub struct HelloSigner<S>
//! # where
//! # S: Signer<Signature>
//! # {
//! # pub signing_key: S
//! # }
//! #
//! # impl<S> HelloSigner<S>
//! # where
//! # S: Signer<Signature>
//! # {
//! # pub fn sign(&self, person: &str) -> Signature {
//! # // NOTE: use `try_sign` if you'd like to be able to handle
//! # // errors from external signing services/devices (e.g. HSM/KMS)
//! # // <https://docs.rs/signature/latest/signature/trait.Signer.html#tymethod.try_sign>
//! # self.signing_key.sign(format_message(person).as_bytes())
//! # }
//! # }
//! #
//! # pub struct HelloVerifier<V> {
//! # pub verifying_key: V
//! # }
//! #
//! # impl<V> HelloVerifier<V>
//! # where
//! # V: Verifier<Signature>
//! # {
//! # pub fn verify(
//! # &self,
//! # person: &str,
//! # signature: &Signature
//! # ) -> Result<(), ed25519::Error> {
//! # self.verifying_key.verify(format_message(person).as_bytes(), signature)
//! # }
//! # }
//! #
//! # fn format_message(person: &str) -> String {
//! # format!("Hello, {}!", person)
//! # }
//! use rand_core::{OsRng, RngCore}; // Requires the `std` feature of `rand_core`
//!
//! /// `HelloSigner` defined above instantiated with *ring* as
//! /// the signing provider.
//! pub type RingHelloSigner = HelloSigner<SigningKey>;
//!
//! let mut ed25519_seed = [0u8; 32];
//! OsRng.fill_bytes(&mut ed25519_seed);
//!
//! let signing_key = SigningKey::from_bytes(&ed25519_seed);
//! let verifying_key = signing_key.verifying_key();
//!
//! let signer = RingHelloSigner { signing_key };
//! let person = "Joe"; // Message to sign
//! let signature = signer.sign(person);
//!
//! /// `HelloVerifier` defined above instantiated with *ring*
//! /// as the signature verification provider.
//! pub type RingHelloVerifier = HelloVerifier<VerifyingKey>;
//!
//! let verifier = RingHelloVerifier { verifying_key };
//! assert!(verifier.verify(person, &signature).is_ok());
//! ```
//!
//! # Available Ed25519 providers
//!
//! The following libraries support the types/traits from the `ed25519` crate:
//!
//! - [`ed25519-dalek`] - mature pure Rust implementation of Ed25519
//! - [`ring-compat`] - compatibility wrapper for [*ring*]
//! - [`yubihsm`] - host-side client library for YubiHSM2 devices from Yubico
//!
//! [`ed25519-dalek`]: https://docs.rs/ed25519-dalek
//! [`ring-compat`]: https://docs.rs/ring-compat
//! [*ring*]: https://github.com/briansmith/ring
//! [`yubihsm`]: https://github.com/iqlusioninc/yubihsm.rs/blob/develop/README.md
//!
//! # Features
//!
//! The following features are presently supported:
//!
//! - `pkcs8`: support for decoding/encoding PKCS#8-formatted private keys using the
//! [`KeypairBytes`] type.
//! - `std` *(default)*: Enable `std` support in [`signature`], which currently only affects whether
//! [`signature::Error`] implements `std::error::Error`.
//! - `serde`: Implement `serde::Deserialize` and `serde::Serialize` for [`Signature`]. Signatures
//! are serialized as their bytes.
//! - `serde_bytes`: Implement `serde_bytes::Deserialize` and `serde_bytes::Serialize` for
//! [`Signature`]. This enables more compact representations for formats with an efficient byte
//! array representation. As per the `serde_bytes` documentation, this can most easily be realised
//! using the `#[serde(with = "serde_bytes")]` annotation, e.g.:
//!
//! ```ignore
//! # use ed25519::Signature;
//! # use serde::{Deserialize, Serialize};
//! #[derive(Deserialize, Serialize)]
//! #[serde(transparent)]
//! struct SignatureAsBytes(#[serde(with = "serde_bytes")] Signature);
//! ```
#[cfg(feature = "alloc")]
extern crate alloc;
mod hex;
#[cfg(feature = "pkcs8")]
pub mod pkcs8;
#[cfg(feature = "serde")]
mod serde;
pub use signature::{self, Error, SignatureEncoding};
#[cfg(feature = "pkcs8")]
pub use crate::pkcs8::{KeypairBytes, PublicKeyBytes};
use core::fmt;
#[cfg(feature = "alloc")]
use alloc::vec::Vec;
/// Size of a single component of an Ed25519 signature.
const COMPONENT_SIZE: usize = 32;
/// Size of an `R` or `s` component of an Ed25519 signature when serialized
/// as bytes.
pub type ComponentBytes = [u8; COMPONENT_SIZE];
/// Ed25519 signature serialized as a byte array.
pub type SignatureBytes = [u8; Signature::BYTE_SIZE];
/// Ed25519 signature.
///
/// This type represents a container for the byte serialization of an Ed25519
/// signature, and does not necessarily represent well-formed field or curve
/// elements.
///
/// Signature verification libraries are expected to reject invalid field
/// elements at the time a signature is verified.
#[derive(Copy, Clone, Eq, PartialEq)]
#[repr(C)]
pub struct Signature {
R: ComponentBytes,
s: ComponentBytes,
}
impl Signature {
/// Size of an encoded Ed25519 signature in bytes.
pub const BYTE_SIZE: usize = COMPONENT_SIZE * 2;
/// Parse an Ed25519 signature from a byte slice.
pub fn from_bytes(bytes: &SignatureBytes) -> Self {
let mut R = ComponentBytes::default();
let mut s = ComponentBytes::default();
let components = bytes.split_at(COMPONENT_SIZE);
R.copy_from_slice(components.0);
s.copy_from_slice(components.1);
Self { R, s }
}
/// Parse an Ed25519 signature from its `R` and `s` components.
pub fn from_components(R: ComponentBytes, s: ComponentBytes) -> Self {
Self { R, s }
}
/// Parse an Ed25519 signature from a byte slice.
///
/// # Returns
/// - `Ok` on success
/// - `Err` if the input byte slice is not 64-bytes
pub fn from_slice(bytes: &[u8]) -> signature::Result<Self> {
SignatureBytes::try_from(bytes)
.map(Into::into)
.map_err(|_| Error::new())
}
/// Bytes for the `R` component of a signature.
pub fn r_bytes(&self) -> &ComponentBytes {
&self.R
}
/// Bytes for the `s` component of a signature.
pub fn s_bytes(&self) -> &ComponentBytes {
&self.s
}
/// Return the inner byte array.
pub fn to_bytes(&self) -> SignatureBytes {
let mut ret = [0u8; Self::BYTE_SIZE];
let (R, s) = ret.split_at_mut(COMPONENT_SIZE);
R.copy_from_slice(&self.R);
s.copy_from_slice(&self.s);
ret
}
/// Convert this signature into a byte vector.
#[cfg(feature = "alloc")]
pub fn to_vec(&self) -> Vec<u8> {
self.to_bytes().to_vec()
}
}
impl SignatureEncoding for Signature {
type Repr = SignatureBytes;
fn to_bytes(&self) -> SignatureBytes {
self.to_bytes()
}
}
impl From<Signature> for SignatureBytes {
fn from(sig: Signature) -> SignatureBytes {
sig.to_bytes()
}
}
impl From<&Signature> for SignatureBytes {
fn from(sig: &Signature) -> SignatureBytes {
sig.to_bytes()
}
}
impl From<SignatureBytes> for Signature {
fn from(bytes: SignatureBytes) -> Self {
Signature::from_bytes(&bytes)
}
}
impl From<&SignatureBytes> for Signature {
fn from(bytes: &SignatureBytes) -> Self {
Signature::from_bytes(bytes)
}
}
impl TryFrom<&[u8]> for Signature {
type Error = Error;
fn try_from(bytes: &[u8]) -> signature::Result<Self> {
Self::from_slice(bytes)
}
}
impl fmt::Debug for Signature {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("ed25519::Signature")
.field("R", &hex::ComponentFormatter(self.r_bytes()))
.field("s", &hex::ComponentFormatter(self.s_bytes()))
.finish()
}
}
impl fmt::Display for Signature {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:X}", self)
}
}

356
vendor/ed25519/src/pkcs8.rs vendored Normal file
View File

@@ -0,0 +1,356 @@
//! PKCS#8 private key support.
//!
//! Implements Ed25519 PKCS#8 private keys as described in RFC8410 Section 7:
//! <https://datatracker.ietf.org/doc/html/rfc8410#section-7>
//!
//! ## SemVer Notes
//!
//! The `pkcs8` module of this crate is exempted from SemVer as it uses a
//! pre-1.0 dependency (the `pkcs8` crate).
//!
//! However, breaking changes to this module will be accompanied by a minor
//! version bump.
//!
//! Please lock to a specific minor version of the `ed25519` crate to avoid
//! breaking changes when using this module.
pub use pkcs8::{
spki, DecodePrivateKey, DecodePublicKey, Error, ObjectIdentifier, PrivateKeyInfo, Result,
};
#[cfg(feature = "alloc")]
pub use pkcs8::{spki::EncodePublicKey, EncodePrivateKey};
#[cfg(feature = "alloc")]
pub use pkcs8::der::{asn1::BitStringRef, Document, SecretDocument};
use core::fmt;
#[cfg(feature = "pem")]
use {
alloc::string::{String, ToString},
core::str,
};
#[cfg(feature = "zeroize")]
use zeroize::Zeroize;
/// Algorithm [`ObjectIdentifier`] for the Ed25519 digital signature algorithm
/// (`id-Ed25519`).
///
/// <http://oid-info.com/get/1.3.101.112>
pub const ALGORITHM_OID: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.3.101.112");
/// Ed25519 Algorithm Identifier.
pub const ALGORITHM_ID: pkcs8::AlgorithmIdentifierRef<'static> = pkcs8::AlgorithmIdentifierRef {
oid: ALGORITHM_OID,
parameters: None,
};
/// Ed25519 keypair serialized as bytes.
///
/// This type is primarily useful for decoding/encoding PKCS#8 private key
/// files (either DER or PEM) encoded using the following traits:
///
/// - [`DecodePrivateKey`]: decode DER or PEM encoded PKCS#8 private key.
/// - [`EncodePrivateKey`]: encode DER or PEM encoded PKCS#8 private key.
///
/// PKCS#8 private key files encoded with PEM begin with:
///
/// ```text
/// -----BEGIN PRIVATE KEY-----
/// ```
///
/// Note that this type operates on raw bytes and performs no validation that
/// keys represent valid Ed25519 field elements.
pub struct KeypairBytes {
/// Ed25519 secret key.
///
/// Little endian serialization of an element of the Curve25519 scalar
/// field, prior to "clamping" (i.e. setting/clearing bits to ensure the
/// scalar is actually a valid field element)
pub secret_key: [u8; Self::BYTE_SIZE / 2],
/// Ed25519 public key (if available).
///
/// Compressed Edwards-y encoded curve point.
pub public_key: Option<PublicKeyBytes>,
}
impl KeypairBytes {
/// Size of an Ed25519 keypair when serialized as bytes.
const BYTE_SIZE: usize = 64;
/// Parse raw keypair from a 64-byte input.
pub fn from_bytes(bytes: &[u8; Self::BYTE_SIZE]) -> Self {
let (sk, pk) = bytes.split_at(Self::BYTE_SIZE / 2);
Self {
secret_key: sk.try_into().expect("secret key size error"),
public_key: Some(PublicKeyBytes(
pk.try_into().expect("public key size error"),
)),
}
}
/// Serialize as a 64-byte keypair.
///
/// # Returns
///
/// - `Some(bytes)` if the `public_key` is present.
/// - `None` if the `public_key` is absent (i.e. `None`).
pub fn to_bytes(&self) -> Option<[u8; Self::BYTE_SIZE]> {
if let Some(public_key) = &self.public_key {
let mut result = [0u8; Self::BYTE_SIZE];
let (sk, pk) = result.split_at_mut(Self::BYTE_SIZE / 2);
sk.copy_from_slice(&self.secret_key);
pk.copy_from_slice(public_key.as_ref());
Some(result)
} else {
None
}
}
}
impl Drop for KeypairBytes {
fn drop(&mut self) {
#[cfg(feature = "zeroize")]
self.secret_key.zeroize()
}
}
#[cfg(feature = "alloc")]
impl EncodePrivateKey for KeypairBytes {
fn to_pkcs8_der(&self) -> Result<SecretDocument> {
// Serialize private key as nested OCTET STRING
let mut private_key = [0u8; 2 + (Self::BYTE_SIZE / 2)];
private_key[0] = 0x04;
private_key[1] = 0x20;
private_key[2..].copy_from_slice(&self.secret_key);
let private_key_info = PrivateKeyInfo {
algorithm: ALGORITHM_ID,
private_key: &private_key,
public_key: self.public_key.as_ref().map(|pk| pk.0.as_slice()),
};
let result = SecretDocument::encode_msg(&private_key_info)?;
#[cfg(feature = "zeroize")]
private_key.zeroize();
Ok(result)
}
}
impl TryFrom<PrivateKeyInfo<'_>> for KeypairBytes {
type Error = Error;
fn try_from(private_key: PrivateKeyInfo<'_>) -> Result<Self> {
private_key.algorithm.assert_algorithm_oid(ALGORITHM_OID)?;
if private_key.algorithm.parameters.is_some() {
return Err(Error::ParametersMalformed);
}
// Ed25519 PKCS#8 keys are represented as a nested OCTET STRING
// (i.e. an OCTET STRING within an OCTET STRING).
//
// This match statement checks and removes the inner OCTET STRING
// header value:
//
// - 0x04: OCTET STRING tag
// - 0x20: 32-byte length
let secret_key = match private_key.private_key {
[0x04, 0x20, rest @ ..] => rest.try_into().map_err(|_| Error::KeyMalformed),
_ => Err(Error::KeyMalformed),
}?;
let public_key = private_key
.public_key
.map(|bytes| bytes.try_into().map_err(|_| Error::KeyMalformed))
.transpose()?
.map(PublicKeyBytes);
Ok(Self {
secret_key,
public_key,
})
}
}
impl TryFrom<&[u8]> for KeypairBytes {
type Error = Error;
fn try_from(der_bytes: &[u8]) -> Result<Self> {
Self::from_pkcs8_der(der_bytes)
}
}
impl fmt::Debug for KeypairBytes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("KeypairBytes")
.field("public_key", &self.public_key)
.finish_non_exhaustive()
}
}
#[cfg(feature = "pem")]
impl str::FromStr for KeypairBytes {
type Err = Error;
fn from_str(pem: &str) -> Result<Self> {
Self::from_pkcs8_pem(pem)
}
}
/// Ed25519 public key serialized as bytes.
///
/// This type is primarily useful for decoding/encoding SPKI public key
/// files (either DER or PEM) encoded using the following traits:
///
/// - [`DecodePublicKey`]: decode DER or PEM encoded PKCS#8 private key.
/// - [`EncodePublicKey`]: encode DER or PEM encoded PKCS#8 private key.
///
/// SPKI public key files encoded with PEM begin with:
///
/// ```text
/// -----BEGIN PUBLIC KEY-----
/// ```
///
/// Note that this type operates on raw bytes and performs no validation that
/// public keys represent valid compressed Ed25519 y-coordinates.
#[derive(Clone, Copy, Eq, PartialEq)]
pub struct PublicKeyBytes(pub [u8; Self::BYTE_SIZE]);
impl PublicKeyBytes {
/// Size of an Ed25519 public key when serialized as bytes.
const BYTE_SIZE: usize = 32;
/// Returns the raw bytes of the public key.
pub fn to_bytes(&self) -> [u8; Self::BYTE_SIZE] {
self.0
}
}
impl AsRef<[u8; Self::BYTE_SIZE]> for PublicKeyBytes {
fn as_ref(&self) -> &[u8; Self::BYTE_SIZE] {
&self.0
}
}
#[cfg(feature = "alloc")]
impl EncodePublicKey for PublicKeyBytes {
fn to_public_key_der(&self) -> spki::Result<Document> {
pkcs8::SubjectPublicKeyInfoRef {
algorithm: ALGORITHM_ID,
subject_public_key: BitStringRef::new(0, &self.0)?,
}
.try_into()
}
}
impl TryFrom<spki::SubjectPublicKeyInfoRef<'_>> for PublicKeyBytes {
type Error = spki::Error;
fn try_from(spki: spki::SubjectPublicKeyInfoRef<'_>) -> spki::Result<Self> {
spki.algorithm.assert_algorithm_oid(ALGORITHM_OID)?;
if spki.algorithm.parameters.is_some() {
return Err(spki::Error::KeyMalformed);
}
spki.subject_public_key
.as_bytes()
.ok_or(spki::Error::KeyMalformed)?
.try_into()
.map(Self)
.map_err(|_| spki::Error::KeyMalformed)
}
}
impl TryFrom<&[u8]> for PublicKeyBytes {
type Error = spki::Error;
fn try_from(der_bytes: &[u8]) -> spki::Result<Self> {
Self::from_public_key_der(der_bytes)
}
}
impl TryFrom<KeypairBytes> for PublicKeyBytes {
type Error = spki::Error;
fn try_from(keypair: KeypairBytes) -> spki::Result<PublicKeyBytes> {
PublicKeyBytes::try_from(&keypair)
}
}
impl TryFrom<&KeypairBytes> for PublicKeyBytes {
type Error = spki::Error;
fn try_from(keypair: &KeypairBytes) -> spki::Result<PublicKeyBytes> {
keypair.public_key.ok_or(spki::Error::KeyMalformed)
}
}
impl fmt::Debug for PublicKeyBytes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("PublicKeyBytes(")?;
for &byte in self.as_ref() {
write!(f, "{:02X}", byte)?;
}
f.write_str(")")
}
}
#[cfg(feature = "pem")]
impl str::FromStr for PublicKeyBytes {
type Err = spki::Error;
fn from_str(pem: &str) -> spki::Result<Self> {
Self::from_public_key_pem(pem)
}
}
#[cfg(feature = "pem")]
impl ToString for PublicKeyBytes {
fn to_string(&self) -> String {
self.to_public_key_pem(Default::default())
.expect("PEM serialization error")
}
}
#[cfg(feature = "pem")]
#[cfg(test)]
mod tests {
use super::{KeypairBytes, PublicKeyBytes};
use hex_literal::hex;
const SECRET_KEY_BYTES: [u8; 32] =
hex!("D4EE72DBF913584AD5B6D8F1F769F8AD3AFE7C28CBF1D4FBE097A88F44755842");
const PUBLIC_KEY_BYTES: [u8; 32] =
hex!("19BF44096984CDFE8541BAC167DC3B96C85086AA30B6B6CB0C5C38AD703166E1");
#[test]
fn to_bytes() {
let valid_keypair = KeypairBytes {
secret_key: SECRET_KEY_BYTES,
public_key: Some(PublicKeyBytes(PUBLIC_KEY_BYTES)),
};
assert_eq!(
valid_keypair.to_bytes().unwrap(),
hex!("D4EE72DBF913584AD5B6D8F1F769F8AD3AFE7C28CBF1D4FBE097A88F4475584219BF44096984CDFE8541BAC167DC3B96C85086AA30B6B6CB0C5C38AD703166E1")
);
let invalid_keypair = KeypairBytes {
secret_key: SECRET_KEY_BYTES,
public_key: None,
};
assert_eq!(invalid_keypair.to_bytes(), None);
}
}

121
vendor/ed25519/src/serde.rs vendored Normal file
View File

@@ -0,0 +1,121 @@
//! `serde` support.
use crate::{Signature, SignatureBytes};
use ::serde::{de, ser, Deserialize, Serialize};
use core::fmt;
impl Serialize for Signature {
fn serialize<S: ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
use ser::SerializeTuple;
let mut seq = serializer.serialize_tuple(Signature::BYTE_SIZE)?;
for byte in self.to_bytes() {
seq.serialize_element(&byte)?;
}
seq.end()
}
}
// serde lacks support for deserializing arrays larger than 32-bytes
// see: <https://github.com/serde-rs/serde/issues/631>
impl<'de> Deserialize<'de> for Signature {
fn deserialize<D: de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
struct ByteArrayVisitor;
impl<'de> de::Visitor<'de> for ByteArrayVisitor {
type Value = [u8; Signature::BYTE_SIZE];
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("bytestring of length 64")
}
fn visit_seq<A>(self, mut seq: A) -> Result<[u8; Signature::BYTE_SIZE], A::Error>
where
A: de::SeqAccess<'de>,
{
use de::Error;
let mut arr = [0u8; Signature::BYTE_SIZE];
for (i, byte) in arr.iter_mut().enumerate() {
*byte = seq
.next_element()?
.ok_or_else(|| Error::invalid_length(i, &self))?;
}
Ok(arr)
}
}
deserializer
.deserialize_tuple(Signature::BYTE_SIZE, ByteArrayVisitor)
.map(Into::into)
}
}
#[cfg(feature = "serde_bytes")]
impl serde_bytes::Serialize for Signature {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_bytes(&self.to_bytes())
}
}
#[cfg(feature = "serde_bytes")]
impl<'de> serde_bytes::Deserialize<'de> for Signature {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: de::Deserializer<'de>,
{
struct ByteArrayVisitor;
impl<'de> de::Visitor<'de> for ByteArrayVisitor {
type Value = SignatureBytes;
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("bytestring of length 64")
}
fn visit_bytes<E>(self, bytes: &[u8]) -> Result<Self::Value, E>
where
E: de::Error,
{
use de::Error;
bytes
.try_into()
.map_err(|_| Error::invalid_length(bytes.len(), &self))
}
}
deserializer
.deserialize_bytes(ByteArrayVisitor)
.map(Into::into)
}
}
#[cfg(test)]
mod tests {
use crate::{Signature, SignatureBytes};
use hex_literal::hex;
const SIGNATURE_BYTES: SignatureBytes = hex!(
"
e5564300c360ac729086e2cc806e828a
84877f1eb8e5d974d873e06522490155
5fb8821590a33bacc61e39701cf9b46b
d25bf5f0595bbe24655141438e7a100b
"
);
#[test]
fn round_trip() {
let signature = Signature::from_bytes(&SIGNATURE_BYTES);
let serialized = bincode::serialize(&signature).unwrap();
let deserialized = bincode::deserialize(&serialized).unwrap();
assert_eq!(signature, deserialized);
}
}

Binary file not shown.

View File

Binary file not shown.

View File

@@ -0,0 +1 @@
{"name":"ed25519","vers":"2.2.3","deps":[{"name":"pkcs8","req":"^0.10","features":[],"optional":true,"default_features":true,"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":"serde","req":"^1","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":"serde_bytes","req":"^0.11","features":[],"optional":true,"default_features":true,"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":"signature","req":"^2","features":[],"optional":false,"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":"zeroize","req":"^1","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":"bincode","req":"^1","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":"ed25519-dalek","req":"^2","features":["rand_core"],"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":"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":"rand_core","req":"^0.6","features":["std"],"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":"ring-compat","req":"^0.8","features":["signature"],"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":["pkcs8?/alloc"],"default":["std"],"pem":["alloc","pkcs8/pem"],"serde_bytes":["serde","dep:serde_bytes"],"std":["pkcs8?/std","signature/std"]},"features2":null,"cksum":"5e3c97967ac336c86e87195c5a12018e4ee86a8fbb884f2ca423e1e63e032073","yanked":null,"links":null,"rust_version":null,"v":2}

Binary file not shown.

View File

@@ -0,0 +1,3 @@
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEINTuctv5E1hK1bbY8fdp+K06/nwoy/HU++CXqI9EdVhC
-----END PRIVATE KEY-----

Binary file not shown.

View File

@@ -0,0 +1,5 @@
-----BEGIN PRIVATE KEY-----
MHICAQEwBQYDK2VwBCIEINTuctv5E1hK1bbY8fdp+K06/nwoy/HU++CXqI9EdVhC
oB8wHQYKKoZIhvcNAQkJFDEPDA1DdXJkbGUgQ2hhaXJzgSEAGb9ECWmEzf6FQbrB
Z9w7lshQhqowtrbLDFw4rXAxZuE=
-----END PRIVATE KEY------

BIN
vendor/ed25519/tests/examples/pubkey.der vendored Normal file

Binary file not shown.

View File

@@ -0,0 +1,3 @@
-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEAGb9ECWmEzf6FQbrBZ9w7lshQhqowtrbLDFw4rXAxZuE=
-----END PUBLIC KEY-----

50
vendor/ed25519/tests/hex.rs vendored Normal file
View File

@@ -0,0 +1,50 @@
//! Hexadecimal display/serialization tests.
use ed25519::Signature;
use hex_literal::hex;
use std::str::FromStr;
/// Test 1 signature from RFC 8032 § 7.1
/// <https://datatracker.ietf.org/doc/html/rfc8032#section-7.1>
const TEST_1_SIGNATURE: [u8; Signature::BYTE_SIZE] = hex!(
"e5564300c360ac729086e2cc806e828a
84877f1eb8e5d974d873e06522490155
5fb8821590a33bacc61e39701cf9b46b
d25bf5f0595bbe24655141438e7a100b"
);
#[test]
fn display() {
let sig = Signature::from_bytes(&TEST_1_SIGNATURE);
assert_eq!(sig.to_string(), "E5564300C360AC729086E2CC806E828A84877F1EB8E5D974D873E065224901555FB8821590A33BACC61E39701CF9B46BD25BF5F0595BBE24655141438E7A100B")
}
#[test]
fn lower_hex() {
let sig = Signature::from_bytes(&TEST_1_SIGNATURE);
assert_eq!(format!("{:x}", sig), "e5564300c360ac729086e2cc806e828a84877f1eb8e5d974d873e065224901555fb8821590a33bacc61e39701cf9b46bd25bf5f0595bbe24655141438e7a100b")
}
#[test]
fn upper_hex() {
let sig = Signature::from_bytes(&TEST_1_SIGNATURE);
assert_eq!(format!("{:X}", sig), "E5564300C360AC729086E2CC806E828A84877F1EB8E5D974D873E065224901555FB8821590A33BACC61E39701CF9B46BD25BF5F0595BBE24655141438E7A100B")
}
#[test]
fn from_str_lower() {
let sig = Signature::from_str("e5564300c360ac729086e2cc806e828a84877f1eb8e5d974d873e065224901555fb8821590a33bacc61e39701cf9b46bd25bf5f0595bbe24655141438e7a100b").unwrap();
assert_eq!(sig.to_bytes(), TEST_1_SIGNATURE);
}
#[test]
fn from_str_upper() {
let sig = Signature::from_str("E5564300C360AC729086E2CC806E828A84877F1EB8E5D974D873E065224901555FB8821590A33BACC61E39701CF9B46BD25BF5F0595BBE24655141438E7A100B").unwrap();
assert_eq!(sig.to_bytes(), TEST_1_SIGNATURE);
}
#[test]
fn from_str_rejects_mixed_case() {
let result = Signature::from_str("E5564300c360ac729086e2cc806e828a84877f1eb8e5d974d873e065224901555fb8821590a33bacc61e39701cf9b46bd25bf5f0595bbe24655141438e7a100b");
assert!(result.is_err());
}

86
vendor/ed25519/tests/pkcs8.rs vendored Normal file
View File

@@ -0,0 +1,86 @@
//! PKCS#8 private key tests
#![cfg(feature = "pkcs8")]
use ed25519::pkcs8::{DecodePrivateKey, DecodePublicKey, KeypairBytes, PublicKeyBytes};
use hex_literal::hex;
#[cfg(feature = "alloc")]
use ed25519::pkcs8::{EncodePrivateKey, EncodePublicKey};
/// Ed25519 PKCS#8 v1 private key encoded as ASN.1 DER.
const PKCS8_V1_DER: &[u8] = include_bytes!("examples/pkcs8-v1.der");
/// Ed25519 PKCS#8 v2 private key + public key encoded as ASN.1 DER.
const PKCS8_V2_DER: &[u8] = include_bytes!("examples/pkcs8-v2.der");
/// Ed25519 SubjectPublicKeyInfo encoded as ASN.1 DER.
const PUBLIC_KEY_DER: &[u8] = include_bytes!("examples/pubkey.der");
#[test]
fn decode_pkcs8_v1() {
let keypair = KeypairBytes::from_pkcs8_der(PKCS8_V1_DER).unwrap();
// Extracted with:
// $ openssl asn1parse -inform der -in tests/examples/pkcs8-v1.der
assert_eq!(
keypair.secret_key,
&hex!("D4EE72DBF913584AD5B6D8F1F769F8AD3AFE7C28CBF1D4FBE097A88F44755842")[..]
);
assert_eq!(keypair.public_key, None);
}
#[test]
fn decode_pkcs8_v2() {
let keypair = KeypairBytes::from_pkcs8_der(PKCS8_V2_DER).unwrap();
// Extracted with:
// $ openssl asn1parse -inform der -in tests/examples/pkcs8-v2.der
assert_eq!(
keypair.secret_key,
&hex!("D4EE72DBF913584AD5B6D8F1F769F8AD3AFE7C28CBF1D4FBE097A88F44755842")[..]
);
assert_eq!(
keypair.public_key.unwrap().0,
hex!("19BF44096984CDFE8541BAC167DC3B96C85086AA30B6B6CB0C5C38AD703166E1")
);
}
#[test]
fn decode_public_key() {
let public_key = PublicKeyBytes::from_public_key_der(PUBLIC_KEY_DER).unwrap();
// Extracted with:
// $ openssl pkey -inform der -in tests/examples/pkcs8-v1.der -pubout -text
assert_eq!(
public_key.as_ref(),
&hex!("19BF44096984CDFE8541BAC167DC3B96C85086AA30B6B6CB0C5C38AD703166E1")
);
}
#[cfg(feature = "alloc")]
#[test]
fn encode_pkcs8_v1() {
let pk = KeypairBytes::from_pkcs8_der(PKCS8_V1_DER).unwrap();
let pk_der = pk.to_pkcs8_der().unwrap();
assert_eq!(pk_der.as_bytes(), PKCS8_V1_DER);
}
#[cfg(feature = "alloc")]
#[test]
fn encode_pkcs8_v2() {
let pk = KeypairBytes::from_pkcs8_der(PKCS8_V2_DER).unwrap();
let pk2 = KeypairBytes::from_pkcs8_der(pk.to_pkcs8_der().unwrap().as_bytes()).unwrap();
assert_eq!(pk.secret_key, pk2.secret_key);
assert_eq!(pk.public_key, pk2.public_key);
}
#[cfg(feature = "alloc")]
#[test]
fn encode_public_key() {
let pk = PublicKeyBytes::from_public_key_der(PUBLIC_KEY_DER).unwrap();
let pk_der = pk.to_public_key_der().unwrap();
assert_eq!(pk_der.as_ref(), PUBLIC_KEY_DER);
}

62
vendor/ed25519/tests/serde.rs vendored Normal file
View File

@@ -0,0 +1,62 @@
//! Tests for serde serializers/deserializers
#![cfg(feature = "serde")]
use ed25519::{Signature, SignatureBytes};
use hex_literal::hex;
const EXAMPLE_SIGNATURE: SignatureBytes = hex!(
"3f3e3d3c3b3a393837363534333231302f2e2d2c2b2a29282726252423222120"
"1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100"
);
#[test]
fn test_serialize() {
let signature = Signature::try_from(&EXAMPLE_SIGNATURE[..]).unwrap();
dbg!(&signature);
let encoded_signature: Vec<u8> = bincode::serialize(&signature).unwrap();
assert_eq!(&EXAMPLE_SIGNATURE[..], &encoded_signature[..]);
}
#[test]
fn test_deserialize() {
let signature = bincode::deserialize::<Signature>(&EXAMPLE_SIGNATURE).unwrap();
assert_eq!(EXAMPLE_SIGNATURE, signature.to_bytes());
}
#[cfg(feature = "serde_bytes")]
#[test]
fn test_serialize_bytes() {
use bincode::Options;
let signature = Signature::try_from(&EXAMPLE_SIGNATURE[..]).unwrap();
let mut encoded_signature = Vec::new();
let options = bincode::DefaultOptions::new()
.with_fixint_encoding()
.allow_trailing_bytes();
let mut serializer = bincode::Serializer::new(&mut encoded_signature, options);
serde_bytes::serialize(&signature, &mut serializer).unwrap();
let mut expected = Vec::from(Signature::BYTE_SIZE.to_le_bytes());
expected.extend(&EXAMPLE_SIGNATURE[..]);
assert_eq!(&expected[..], &encoded_signature[..]);
}
#[cfg(feature = "serde_bytes")]
#[test]
fn test_deserialize_bytes() {
use bincode::Options;
let mut encoded_signature = Vec::from(Signature::BYTE_SIZE.to_le_bytes());
encoded_signature.extend(&EXAMPLE_SIGNATURE[..]);
let options = bincode::DefaultOptions::new()
.with_fixint_encoding()
.allow_trailing_bytes();
let mut deserializer = bincode::de::Deserializer::from_slice(&encoded_signature[..], options);
let signature: Signature = serde_bytes::deserialize(&mut deserializer).unwrap();
assert_eq!(EXAMPLE_SIGNATURE, signature.to_bytes());
}