From f6d84d5277f7904bf214c9e941ba97422cacc2ee Mon Sep 17 00:00:00 2001 From: David Rickard Date: Sat, 25 Feb 2023 09:29:33 -0800 Subject: [PATCH] Documentation fixes Made some changes to the example code so it compiles. * It's necessary to call `keypair.raw_components()` and pass the `EcKeyComponents` instance to the decrypt methods. Passing in the keypair directly to the decrypt methods does not work. Updated the usage notes accordingly. * AesGcmEncryptedBlock was moved to the `legacy` module, reflected that. * Fixed parameter order on `AesGcmEncryptedBlock::new` --- README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index df5f6ae..2094186 100644 --- a/README.md +++ b/README.md @@ -38,8 +38,10 @@ then distribute the public key and authentication secret to the sender: ```rust let (keypair, auth_secret) = ece::generate_keypair_and_auth_secret()?; -let pubkey = keypair.pub_as_raw(); -// Base64-encode the `pubkey` and `auth_secret` bytes and distribute them to the sender. +let components: EcKeyComponents = keypair.raw_components()?; +let public_key: &[u8] = components.public_key(); +// Base64-encode `public_key` and `auth_secret` bytes and distribute them to the sender. +// Save `components` and use it to decode messages. ``` The sender can encrypt a Web Push message to the receiver's public key: @@ -51,7 +53,7 @@ let ciphertext = ece::encrypt(&pubkey, &auth_secret, b"payload")?; And the receiver can decrypt it using their private key: ```rust -let plaintext = ece::decrypt(&keypair, &auth_secret, &ciphertext)?; +let plaintext = ece::decrypt(&components, &auth_secret, &ciphertext)?; ``` That's pretty much all there is to it! It's up to the higher-level library to manage distributing the encrypted payload, @@ -77,8 +79,8 @@ and `Crypto-Key` fields: ```rust // Parse `rs`, `salt` and `dh` from the `Encryption` and `Crypto-Key` headers. // You'll need to consult the spec for how to do this; we might add some helpers one day. -let encrypted_block = ece::AesGcmEncryptedBlock::new(dh, rs, salt, ciphertext); -let plaintext = ece::legacy::decrypt_aesgcm(keypair, auth_secret, encrypted_block)?; +let encrypted_block = ece::legacy::AesGcmEncryptedBlock::new(dh, salt, rs, ciphertext); +let plaintext = ece::legacy::decrypt_aesgcm(components, auth_secret, encrypted_block)?; ``` ### Unimplemented Features