Restore a comment with doctest

This commit is contained in:
Ivan Boldyrev 2023-10-03 21:56:26 +04:00
parent 866cc1a21a
commit 2fe25c725c

View File

@ -343,36 +343,20 @@ impl Keypair {
} }
} }
#[doc = r##" /// Deterministically derive a new secret from this [`Keypair`], taking into account the provided domain.
Deterministically derive a new secret from this [`Keypair`], taking into account the provided domain. ///
/// This works for all key types except RSA where it returns `None`.
This works for all key types except RSA where it returns `None`. ///
/// # Example
# Example ///
/// ```
"##] /// # fn main() {
#[cfg_attr( /// # use libp2p_identity as identity;
feature = "rand", /// let key = identity::Keypair::generate_ed25519();
doc = r##" ///
``` /// let new_key = key.derive_secret(b"my encryption key").expect("can derive secret for ed25519");
"## /// # }
)] /// ```
#[cfg_attr(
not(feature = "rand"),
doc = r##"
```ignore
"##
)]
#[doc = r##"
# fn main() {
# use libp2p_identity as identity;
let key = identity::Keypair::generate_ed25519();
let new_key = key.derive_secret(b"my encryption key").expect("can derive secret for ed25519");
# }
```
"##
]
#[allow(unused_variables, unreachable_code)] #[allow(unused_variables, unreachable_code)]
pub fn derive_secret(&self, domain: &[u8]) -> Option<[u8; 32]> { pub fn derive_secret(&self, domain: &[u8]) -> Option<[u8; 32]> {
#[cfg(any( #[cfg(any(