Skip to content

Commit 8bf088c

Browse files
committed
Fixes
1 parent 55ba0c5 commit 8bf088c

3 files changed

Lines changed: 12 additions & 10 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "nss-rs"
3-
version = "0.9.0"
3+
version = "0.10.0"
44
authors = ["Martin Thomson <mt@lowentropy.net>", "Andy Leiserson <aleiserson@mozilla.com>", "John M. Schanck <jschanck@mozilla.com>", "Benjamin Beurdouche <beurdouche@mozilla.com>", "Anna Weine <anna.weine@mozilla.com>"]
55
categories = ["network-programming", "web-programming"]
66
keywords = ["nss", "crypto", "mozilla", "firefox"]

src/hp.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ fn make_aes_ctx(key: &SymKey) -> Res<Context> {
5656

5757
pub enum Key {
5858
/// AES-ECB header-protection context. `PK11_CloneContext` is not supported for
59-
/// AES-ECB, so we store the `SymKey` and recreate `ctx` lazily on first use after
60-
/// a clone. `ctx` is `None` only between `clone()` and the first call to `mask`.
59+
/// AES-ECB, so we store the `SymKey` and recreate `ctx` lazily: `mask` initialises
60+
/// it on first use when `ctx` is `None`.
6161
Aes { ctx: Option<Context>, key: SymKey },
6262
/// The `ChaCha20` mask invokes `PK11_Encrypt` on each call because the counter
6363
/// and nonce change per invocation.
@@ -160,13 +160,15 @@ impl Key {
160160

161161
match self {
162162
Self::Aes { ctx, key } => {
163-
if ctx.is_none() {
164-
*ctx = Some(make_aes_ctx(key)?);
165-
}
166-
let ctx = ctx.as_ref().expect("context initialized above");
163+
let ctx = if let Some(c) = ctx {
164+
c
165+
} else {
166+
ctx.insert(make_aes_ctx(key)?)
167+
};
167168
let mut output_len: c_int = 0;
168-
// SAFETY: AES-ECB is stateless — no IV or counter is mutated between
169-
// calls — so using a raw pointer from &ctx is sound.
169+
// SAFETY: `Deref` on `Context` yields a copy of the raw `*mut PK11Context`;
170+
// no Rust reference to the pointee is created, and `&mut self` guarantees
171+
// exclusive access to this `Key`.
170172
secstatus_to_res(unsafe {
171173
PK11_CipherOp(
172174
**ctx,

0 commit comments

Comments
 (0)