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

@@ -0,0 +1 @@
{"files":{".cargo_vcs_info.json":"0cbb607c92cdc7920b56befbb8eb96f741a36241f03d7f9d37c8b1dd8b9ce187","CHANGELOG.md":"9b29dc390134f5d026e29311a862559c003a5363541a674ef00e884832fc165a","Cargo.toml":"62bd1d0d66663a600c785b814f57cdf4930b95ae58df19019cc1b3886ea74453","Cargo.toml.orig":"66c14cae30e38ac9ce991c4e7c1ae50bafbf921f2d272ec60833f73bf5f56e75","LICENSE-APACHE":"cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30","LICENSE-MIT":"1264c45618bccf48df48b9e9beefdc704dc094ddedccf5ddef0243a031b9e114","README.md":"1bae85f14381957680b1b3c3849fedf21fa28def929ea6008bb19d55163618dd","src/lib.rs":"51227abd342005b263a7bef2dd21ea0fcfe677db0242be116ed3c1bb59c8baa4"},"package":"e891af845473308773346dc847b2c23ee78fe442e0472ac50e22a18a93d3ae5a"}

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

@@ -0,0 +1,6 @@
{
"git": {
"sha1": "70eaa76ea3f4bacd67f3027c4a52948485a67d32"
},
"path_in_vcs": "secrecy"
}

190
vendor/secrecy/CHANGELOG.md vendored Normal file
View File

@@ -0,0 +1,190 @@
# 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).
## 0.10.3 (2024-10-09)
### Added
- Make integer primitive `SecretSlice`s cloneable ([#1236])
- Impl `From<&str>` for `SecretString` ([#1237])
[#1236]: https://github.com/iqlusioninc/crates/pull/1236
[#1237]: https://github.com/iqlusioninc/crates/pull/1237
## 0.10.2 (2024-09-20)
### Added
- Impl `Deserialize` for `SecretString` ([#1220])
[#1220]: https://github.com/iqlusioninc/crates/pull/1220
## 0.10.1 (2024-09-18)
### Added
- Impl `Clone` for `SecretString` ([#1217])
[#1217]: https://github.com/iqlusioninc/crates/pull/1217
## 0.10.0 (2024-09-17)
This release represents a significant redesign of the `secrecy` crate. We will update this section
with upgrade instructions based on feedback from people upgrading, as it's been a long time since
the previous release, and this release includes a number of breaking changes.
The most notable change is the generic `Secret<T>` type has been removed: instead use `SecretBox<T>`
which stores secrets on the heap instead of the stack. Many of the other changes fall out of this
change and things which were previously type aliases of `Secret<T>` are now type aliases of
`SecretBox<T>`.
This unfortunately means this crate no longer has support for "heapless" `no_std` targets. We don't
have a good solution for these targets, which was a motivation for this change in the first place.
### Added
- `SecretBox::{init_with, try_init_with}` ([#1212])
- `SecretBox::init_with_mut` ([#1213])
- `?Sized` bounds for `SecretBox` ([#1213])
- `SecretSlice<T>` ([#1214])
### Changed
- Rust 2021 edition upgrade ([#889])
- MSRV 1.60 ([#1105])
- `SecretBox<T>` is now a newtype rather than a type alias of `Secret<Box<T>> ([#1140])
- `SecretString` is now a type alias for `SecretBox<str>` ([#1213])
- Disable `serde` default features ([#1194])
### Removed
- `alloc` feature: now a hard dependency ([#1140])
- `bytes` crate integration: no replacement ([#1140])
- `DebugSecret` trait: no replacement ([#1140])
- `Secret<T>`: use `SecretBox<T>` instead ([#1140])
[#889]: https://github.com/iqlusioninc/crates/pull/889
[#1105]: https://github.com/iqlusioninc/crates/pull/1105
[#1140]: https://github.com/iqlusioninc/crates/pull/1140
[#1194]: https://github.com/iqlusioninc/crates/pull/1194
[#1212]: https://github.com/iqlusioninc/crates/pull/1212
[#1213]: https://github.com/iqlusioninc/crates/pull/1213
[#1214]: https://github.com/iqlusioninc/crates/pull/1214
## 0.9.0 (Skipped)
## 0.8.0 (2021-07-18)
NOTE: This release includes an MSRV bump to Rust 1.56. Please use `secrecy = "0.7.0"`
if you would like to support older Rust versions.
### Added
- impl `From<T>` for `Secret` ([#482])
### Changed
- Bump `bytes` to v1.0 ([#592])
- Switch to `resolver = "2"`; MSRV 1.56 ([#755])
[#482]: https://github.com/iqlusioninc/crates/pull/482
[#592]: https://github.com/iqlusioninc/crates/pull/592
[#755]: https://github.com/iqlusioninc/crates/pull/755
## 0.7.0 (2020-07-08)
### Added
- Re-export zeroize ([#466])
- `rustdoc` improvements ([#464], [#465])
### Changed
- Have `DebugSecret` take a formatter ([#467])
- Make `FromStr` impl for `SecretString` be `Infallible` ([#323])
### Fixed
- Use `SerializableSecret` in `Serialize` bounds ([#463])
[#467]: https://github.com/iqlusioninc/crates/pull/467
[#466]: https://github.com/iqlusioninc/crates/pull/466
[#465]: https://github.com/iqlusioninc/crates/pull/465
[#464]: https://github.com/iqlusioninc/crates/pull/464
[#463]: https://github.com/iqlusioninc/crates/pull/463
[#323]: https://github.com/iqlusioninc/crates/pull/323
## 0.6.0 (2019-12-12)
- Impl `CloneableSecret` for `Secret<[T; N]>` where `T: Clone` ([#311])
- Impl `DebugSecret` for `[T; N]` where `N` <= 64 ([#310])
- Impl `FromStr` for `SecretString` ([#309])
- Upgrade to `bytes` v0.5 ([#301], [#308], [#312])
[#312]: https://github.com/iqlusioninc/crates/pull/312
[#311]: https://github.com/iqlusioninc/crates/pull/311
[#310]: https://github.com/iqlusioninc/crates/pull/310
[#309]: https://github.com/iqlusioninc/crates/pull/309
[#308]: https://github.com/iqlusioninc/crates/pull/308
[#301]: https://github.com/iqlusioninc/crates/pull/301
## 0.5.2 (2019-12-18)
- Backport Impl `FromStr` for `SecretString` ([#309])
[#309]: https://github.com/iqlusioninc/crates/pull/309
## 0.5.1 (2019-11-30)
- Change default `DebugSecret` string to `[REDACTED]` ([#290])
[#290]: https://github.com/iqlusioninc/crates/pull/290
## 0.5.0 (2019-10-13)
- Upgrade to `zeroize` v1.0.0 ([#279])
[#279]: https://github.com/iqlusioninc/crates/pull/279
## 0.4.1 (2019-10-13)
- Upgrade to `zeroize` v1.0.0-pre ([#268])
[#268]: https://github.com/iqlusioninc/crates/pull/268
## 0.4.0 (2019-09-03)
- Add `SerializableSecret` ([#262])
- Add (optional) concrete `SecretBytes` type ([#258], [#259], [#260], [#261])
[#262]: https://github.com/iqlusioninc/crates/pull/262
[#261]: https://github.com/iqlusioninc/crates/pull/261
[#260]: https://github.com/iqlusioninc/crates/pull/260
[#259]: https://github.com/iqlusioninc/crates/pull/259
[#258]: https://github.com/iqlusioninc/crates/pull/258
## 0.3.1 (2019-08-26)
- Impl `CloneableSecret` for `String` ([#256])
[#256]: https://github.com/iqlusioninc/crates/pull/256
## 0.3.0 (2019-08-20)
- Add support for `alloc` types ([#253])
- `zeroize` v0.10.0 ([#248])
- Add a default impl for `DebugSecret` trait ([#241])
[#253]: https://github.com/iqlusioninc/crates/pull/253
[#248]: https://github.com/iqlusioninc/crates/pull/248
[#241]: https://github.com/iqlusioninc/crates/pull/241
## 0.2.2 (2019-06-28)
- README.md: add Gitter badges; update image links ([#221])
[#221]: https://github.com/iqlusioninc/crates/pull/221
## 0.2.1 (2019-06-04)
- `zeroize` v0.9.0 ([#215])
[#215]: https://github.com/iqlusioninc/crates/pull/215
## 0.2.0 (2019-05-29)
- Add `CloneableSecret` marker trait ([#210])
[#210]: https://github.com/iqlusioninc/crates/pull/210
## 0.1.0 (2019-05-23)
- Initial release

67
vendor/secrecy/Cargo.toml vendored Normal file
View File

@@ -0,0 +1,67 @@
# 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 = "secrecy"
version = "0.10.3"
authors = ["Tony Arcieri <tony@iqlusion.io>"]
build = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = """
Wrapper types and traits for secret management which help ensure
they aren't accidentally copied, logged, or otherwise exposed
(as much as possible), and also ensure secrets are securely wiped
from memory when dropped.
"""
homepage = "https://github.com/iqlusioninc/crates/"
readme = "README.md"
keywords = [
"clear",
"memory",
"secret",
"secure",
"wipe",
]
categories = [
"cryptography",
"memory-management",
"no-std",
"os",
]
license = "Apache-2.0 OR MIT"
repository = "https://github.com/iqlusioninc/crates/tree/main/secrecy"
[package.metadata.docs.rs]
all-features = true
rustdoc-args = [
"--cfg",
"docsrs",
]
[lib]
name = "secrecy"
path = "src/lib.rs"
[dependencies.serde]
version = "1"
features = ["alloc"]
optional = true
default-features = false
[dependencies.zeroize]
version = "1.6"
features = ["alloc"]
default-features = false

202
vendor/secrecy/LICENSE-APACHE vendored Normal file
View File

@@ -0,0 +1,202 @@
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.

21
vendor/secrecy/LICENSE-MIT vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2019-2024 iqlusion
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.

78
vendor/secrecy/README.md vendored Normal file
View File

@@ -0,0 +1,78 @@
# secrecy.rs 🤐 <a href="https://www.iqlusion.io"><img src="https://storage.googleapis.com/iqlusion-production-web/img/logo/iqlusion-rings-sm.png" alt="iqlusion" width="24" height="24"></a>
[![Crate][crate-image]][crate-link]
[![Docs][docs-image]][docs-link]
![Apache 2.0/MIT Licensed][license-image]
![MSRV][rustc-image]
[![Safety Dance][safety-image]][safety-link]
[![Build Status][build-image]][build-link]
A simple secret-keeping library for Rust.
[Documentation][docs-link]
## About
**secrecy** is a *simple*, safe (i.e. `forbid(unsafe_code)` library which
provides wrapper types and traits for secret management in Rust, namely the
`Secret<T>` type for wrapping another value in a "secret cell" which attempts
to limit exposure (only available through a special `ExposeSecret` trait).
This helps to ensure secrets aren't accidentally copied, logged, or otherwise
exposed (as much as possible), and also ensures secrets are securely wiped
from memory when dropped.
## Minimum Supported Rust Version
Rust **1.60** or newer.
In the future, we reserve the right to change MSRV (i.e. MSRV is out-of-scope
for this crate's SemVer guarantees), however when we do it will be accompanied by
a minor version bump.
## serde support
Optional `serde` support for parsing owned secret values is available, gated
under the `serde` cargo feature.
It uses the `Deserialize` and `DeserializeOwned` traits to implement
deserializing secret types which also impl these traits.
This doesn't guarantee `serde` (or code providing input to `serde`) won't
accidentally make additional copies of the secret, but does the best it can
with what it is given and tries to minimize risk of exposure as much as
possible.
## License
Copyright © 2019-2024 iqlusion
**secrecy** is distributed under the terms of either the MIT license
or the Apache License (Version 2.0), at your option.
See [LICENSE] (Apache License, Version 2.0) file in the `iqlusioninc/crates`
toplevel directory of this repository or [LICENSE-MIT] for details.
## Contribution
Unless you explicitly state otherwise, any contribution intentionally
submitted for inclusion in the work by you shall be dual licensed as above,
without any additional terms or conditions.
[//]: # (badges)
[crate-image]: https://img.shields.io/crates/v/secrecy.svg?logo=rust
[crate-link]: https://crates.io/crates/secrecy
[docs-image]: https://docs.rs/secrecy/badge.svg
[docs-link]: https://docs.rs/secrecy/
[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
[safety-image]: https://img.shields.io/badge/unsafe-forbidden-success.svg
[safety-link]: https://github.com/rust-secure-code/safety-dance/
[build-image]: https://github.com/iqlusioninc/crates/actions/workflows/secrecy.yml/badge.svg
[build-link]: https://github.com/iqlusioninc/crates/actions/workflows/secrecy.yml
[//]: # (general links)
[LICENSE]: https://github.com/iqlusioninc/crates/blob/main/LICENSE
[LICENSE-MIT]: https://github.com/iqlusioninc/crates/blob/main/secrecy/LICENSE-MIT

325
vendor/secrecy/src/lib.rs vendored Normal file
View File

@@ -0,0 +1,325 @@
//! [`SecretBox`] wrapper type for more carefully handling secret values
//! (e.g. passwords, cryptographic keys, access tokens or other credentials)
//!
//! # Goals
//!
//! - Make secret access explicit and easy-to-audit via the
//! [`ExposeSecret`] and [`ExposeSecretMut`] traits.
//! - Prevent accidental leakage of secrets via channels like debug logging
//! - Ensure secrets are wiped from memory on drop securely
//! (using the [`zeroize`] crate)
//!
//! Presently this crate favors a simple, `no_std`-friendly, safe i.e.
//! `forbid(unsafe_code)`-based implementation and does not provide more advanced
//! memory protection mechanisms e.g. ones based on `mlock(2)`/`mprotect(2)`.
//! We may explore more advanced protection mechanisms in the future.
//! Those who don't mind `std` and `libc` dependencies should consider using
//! the [`secrets`](https://crates.io/crates/secrets) crate.
//!
//! # `serde` support
//!
//! When the `serde` feature of this crate is enabled, the [`SecretBox`] type will
//! receive a [`Deserialize`] impl for all `SecretBox<T>` types where
//! `T: DeserializeOwned`. This allows *loading* secret values from data
//! deserialized from `serde` (be careful to clean up any intermediate secrets
//! when doing this, e.g. the unparsed input!)
//!
//! To prevent exfiltration of secret values via `serde`, by default `SecretBox<T>`
//! does *not* receive a corresponding [`Serialize`] impl. If you would like
//! types of `SecretBox<T>` to be serializable with `serde`, you will need to impl
//! the [`SerializableSecret`] marker trait on `T`.
#![no_std]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![forbid(unsafe_code)]
#![warn(missing_docs, rust_2018_idioms, unused_qualifications)]
extern crate alloc;
use alloc::{boxed::Box, string::String, vec::Vec};
use core::{
any,
fmt::{self, Debug},
};
use zeroize::{Zeroize, ZeroizeOnDrop};
#[cfg(feature = "serde")]
use serde::{de, ser, Deserialize, Serialize};
pub use zeroize;
/// Wrapper type for values that contains secrets, which attempts to limit
/// accidental exposure and ensure secrets are wiped from memory when dropped.
/// (e.g. passwords, cryptographic keys, access tokens or other credentials)
///
/// Access to the secret inner value occurs through the [`ExposeSecret`]
/// or [`ExposeSecretMut`] traits, which provide methods for accessing the inner secret value.
pub struct SecretBox<S: Zeroize + ?Sized> {
inner_secret: Box<S>,
}
impl<S: Zeroize + ?Sized> Zeroize for SecretBox<S> {
fn zeroize(&mut self) {
self.inner_secret.as_mut().zeroize()
}
}
impl<S: Zeroize + ?Sized> Drop for SecretBox<S> {
fn drop(&mut self) {
self.zeroize()
}
}
impl<S: Zeroize + ?Sized> ZeroizeOnDrop for SecretBox<S> {}
impl<S: Zeroize + ?Sized> From<Box<S>> for SecretBox<S> {
fn from(source: Box<S>) -> Self {
Self::new(source)
}
}
impl<S: Zeroize + ?Sized> SecretBox<S> {
/// Create a secret value using a pre-boxed value.
pub fn new(boxed_secret: Box<S>) -> Self {
Self {
inner_secret: boxed_secret,
}
}
}
impl<S: Zeroize + Default> SecretBox<S> {
/// Create a secret value using a function that can initialize the value in-place.
pub fn init_with_mut(ctr: impl FnOnce(&mut S)) -> Self {
let mut secret = Self::default();
ctr(secret.expose_secret_mut());
secret
}
}
impl<S: Zeroize + Clone> SecretBox<S> {
/// Create a secret value using the provided function as a constructor.
///
/// The implementation makes an effort to zeroize the locally constructed value
/// before it is copied to the heap, and constructing it inside the closure minimizes
/// the possibility of it being accidentally copied by other code.
///
/// **Note:** using [`Self::new`] or [`Self::init_with_mut`] is preferable when possible,
/// since this method's safety relies on empiric evidence and may be violated on some targets.
pub fn init_with(ctr: impl FnOnce() -> S) -> Self {
let mut data = ctr();
let secret = Self {
inner_secret: Box::new(data.clone()),
};
data.zeroize();
secret
}
/// Same as [`Self::init_with`], but the constructor can be fallible.
///
///
/// **Note:** using [`Self::new`] or [`Self::init_with_mut`] is preferable when possible,
/// since this method's safety relies on empyric evidence and may be violated on some targets.
pub fn try_init_with<E>(ctr: impl FnOnce() -> Result<S, E>) -> Result<Self, E> {
let mut data = ctr()?;
let secret = Self {
inner_secret: Box::new(data.clone()),
};
data.zeroize();
Ok(secret)
}
}
impl<S: Zeroize + Default> Default for SecretBox<S> {
fn default() -> Self {
Self {
inner_secret: Box::<S>::default(),
}
}
}
impl<S: Zeroize + ?Sized> Debug for SecretBox<S> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "SecretBox<{}>([REDACTED])", any::type_name::<S>())
}
}
impl<S> Clone for SecretBox<S>
where
S: CloneableSecret,
{
fn clone(&self) -> Self {
SecretBox {
inner_secret: self.inner_secret.clone(),
}
}
}
impl<S: Zeroize + ?Sized> ExposeSecret<S> for SecretBox<S> {
fn expose_secret(&self) -> &S {
self.inner_secret.as_ref()
}
}
impl<S: Zeroize + ?Sized> ExposeSecretMut<S> for SecretBox<S> {
fn expose_secret_mut(&mut self) -> &mut S {
self.inner_secret.as_mut()
}
}
/// Secret slice type.
///
/// This is a type alias for [`SecretBox<[S]>`] which supports some helpful trait impls.
///
/// Notably it has a [`From<Vec<S>>`] impl which is the preferred method for construction.
pub type SecretSlice<S> = SecretBox<[S]>;
impl<S> From<Vec<S>> for SecretSlice<S>
where
S: Zeroize,
[S]: Zeroize,
{
fn from(vec: Vec<S>) -> Self {
Self::from(vec.into_boxed_slice())
}
}
impl<S> Clone for SecretSlice<S>
where
S: CloneableSecret + Zeroize,
[S]: Zeroize,
{
fn clone(&self) -> Self {
SecretBox {
inner_secret: Vec::from(&*self.inner_secret).into_boxed_slice(),
}
}
}
impl<S> Default for SecretSlice<S>
where
S: Zeroize,
[S]: Zeroize,
{
fn default() -> Self {
Vec::new().into()
}
}
/// Secret string type.
///
/// This is a type alias for [`SecretBox<str>`] which supports some helpful trait impls.
///
/// Notably it has a [`From<String>`] impl which is the preferred method for construction.
pub type SecretString = SecretBox<str>;
impl From<String> for SecretString {
fn from(s: String) -> Self {
Self::from(s.into_boxed_str())
}
}
impl From<&str> for SecretString {
fn from(s: &str) -> Self {
Self::from(String::from(s))
}
}
impl Clone for SecretString {
fn clone(&self) -> Self {
SecretBox {
inner_secret: self.inner_secret.clone(),
}
}
}
impl Default for SecretString {
fn default() -> Self {
String::default().into()
}
}
/// Marker trait for secrets which are allowed to be cloned
pub trait CloneableSecret: Clone + Zeroize {}
// Mark integer primitives as cloneable secrets
impl CloneableSecret for i8 {}
impl CloneableSecret for i16 {}
impl CloneableSecret for i32 {}
impl CloneableSecret for i64 {}
impl CloneableSecret for i128 {}
impl CloneableSecret for isize {}
impl CloneableSecret for u8 {}
impl CloneableSecret for u16 {}
impl CloneableSecret for u32 {}
impl CloneableSecret for u64 {}
impl CloneableSecret for u128 {}
impl CloneableSecret for usize {}
/// Expose a reference to an inner secret
pub trait ExposeSecret<S: ?Sized> {
/// Expose secret: this is the only method providing access to a secret.
fn expose_secret(&self) -> &S;
}
/// Expose a mutable reference to an inner secret
pub trait ExposeSecretMut<S: ?Sized> {
/// Expose secret: this is the only method providing access to a secret.
fn expose_secret_mut(&mut self) -> &mut S;
}
/// Marker trait for secret types which can be [`Serialize`]-d by [`serde`].
///
/// When the `serde` feature of this crate is enabled and types are marked with
/// this trait, they receive a [`Serialize` impl][1] for `SecretBox<T>`.
/// (NOTE: all types which impl `DeserializeOwned` receive a [`Deserialize`]
/// impl)
///
/// This is done deliberately to prevent accidental exfiltration of secrets
/// via `serde` serialization.
///
/// If you really want to have `serde` serialize those types, use the
/// [`serialize_with`][2] attribute to specify a serializer that exposes the secret.
///
/// [1]: https://docs.rs/secrecy/latest/secrecy/struct.Secret.html#implementations
/// [2]: https://serde.rs/field-attrs.html#serialize_with
#[cfg(feature = "serde")]
pub trait SerializableSecret: Serialize {}
#[cfg(feature = "serde")]
impl<'de, T> Deserialize<'de> for SecretBox<T>
where
T: Zeroize + Clone + de::DeserializeOwned + Sized,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: de::Deserializer<'de>,
{
Self::try_init_with(|| T::deserialize(deserializer))
}
}
#[cfg(feature = "serde")]
impl<'de> Deserialize<'de> for SecretString {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: de::Deserializer<'de>,
{
String::deserialize(deserializer).map(Into::into)
}
}
#[cfg(feature = "serde")]
impl<T> Serialize for SecretBox<T>
where
T: Zeroize + SerializableSecret + Serialize + Sized,
{
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: ser::Serializer,
{
self.expose_secret().serialize(serializer)
}
}

Binary file not shown.

View File

View File

@@ -0,0 +1 @@
{"name":"secrecy","vers":"0.10.3","deps":[{"name":"serde","req":"^1","features":["alloc"],"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":"zeroize","req":"^1.6","features":["alloc"],"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}],"features":{},"features2":null,"cksum":"0ce07b4ddb6ac1f1826d0df85774c4a7c89ccd1b1cb75768d3350260a62e50bc","yanked":null,"links":null,"rust_version":null,"v":2}

Binary file not shown.