Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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,
Expand All @@ -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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it doesn't matter for the complier, but why did you change the order of salt and rs?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is the order of the parameters in AesGcmEncryptedBlock::new. The code doesn't compile if you use the old order.

let plaintext = ece::legacy::decrypt_aesgcm(components, auth_secret, encrypted_block)?;
```

### Unimplemented Features
Expand Down