Skip to content

Commit

Permalink
Revert "README.md: use ? instead of expect` in example (#385)"
Browse files Browse the repository at this point in the history
This reverts commit 00eaa91.

Unfortunately while `#` comments work in rustdoc, they are visible when
GitHub renders the README.md, so this doesn't work.
  • Loading branch information
tarcieri committed Nov 28, 2023
1 parent 6df6d08 commit ebbbd03
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,21 @@ A portable RSA implementation in pure Rust.
## Example

```rust
# fn main() -> Result<(), rsa::Error> {
use rsa::{Pkcs1v15Encrypt, RsaPrivateKey, RsaPublicKey};

let mut rng = rand::thread_rng();
let bits = 2048;
let priv_key = RsaPrivateKey::new(&mut rng, bits)?;
let priv_key = RsaPrivateKey::new(&mut rng, bits).expect("failed to generate a key");
let pub_key = RsaPublicKey::from(&priv_key);

// Encrypt
let data = b"hello world";
let enc_data = pub_key.encrypt(&mut rng, Pkcs1v15Encrypt, &data[..])?;
let enc_data = pub_key.encrypt(&mut rng, Pkcs1v15Encrypt, &data[..]).expect("failed to encrypt");
assert_ne!(&data[..], &enc_data[..]);

// Decrypt
let dec_data = priv_key.decrypt(Pkcs1v15Encrypt, &enc_data)?;
let dec_data = priv_key.decrypt(Pkcs1v15Encrypt, &enc_data).expect("failed to decrypt");
assert_eq!(&data[..], &dec_data[..]);
# Ok(())
# }
```

> **Note:** If you encounter unusually slow key generation time while using `RsaPrivateKey::new` you can try to compile in release mode or add the following to your `Cargo.toml`. Key generation is much faster when building with higher optimization levels, but this will increase the compile time a bit.
Expand Down

0 comments on commit ebbbd03

Please sign in to comment.