Skip to content

Commit 416dfd8

Browse files
committed
crypto-common: add KeyExport trait
Adds a companion trait to `KeyInit*` for exporting a key to a byte array sized according to `KeySizeUser`. This is needed when generating e.g. asymmetric secret keys types using the `Generate` trait and it returns an actual key type (e.g. `SigningKey`, `DecryptionKey`, `DecapsulationKey`) as opposed to its serialized byte representation.
1 parent 0780741 commit 416dfd8

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

crypto-common/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
### Added
1010
- Sealed `BlockSizes` trait implemented for types from `U1` to `U255`
1111
- `Generate` trait ([#2096])
12+
- `KeyExport` trait ([#2213])
1213

1314
### Changed
1415
- `BlockUser::BlockSize` is now bounded by the `BlockSizes` trait
@@ -20,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2021

2122
[#1759]: https://github.com/RustCrypto/traits/pull/1759
2223
[#2096]: https://github.com/RustCrypto/traits/pull/2096
24+
[#2213]: https://github.com/RustCrypto/traits/pull/2213
2325

2426
## 0.1.7 (2025-11-12)
2527
### Changed

crypto-common/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ pub trait AlgorithmName {
156156
fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result;
157157
}
158158

159+
/// Serialize a key to a byte array.
160+
pub trait KeyExport: KeySizeUser {
161+
/// Serialize this key as a byte array.
162+
fn to_bytes(&self) -> Key<Self>;
163+
}
164+
159165
/// Types which can be initialized from a key.
160166
pub trait KeyInit: KeySizeUser + Sized {
161167
/// Create new value from fixed size key.

0 commit comments

Comments
 (0)