Skip to content

Commit dc5e818

Browse files
committed
Correct the docs on when constructing a Digest can fail
PR #92 made the `Digest` constructors partial, so construction raises when OpenSSL cannot allocate the context. The package docstring still said construction cannot fail and that the failure surfaces at the first `append` or `final`, and it left the constructors off the list of partial functions. Two unreleased release notes were wrong too. One said a digest that could not be created reports it at the first `append` or `final`; the other said construction now raises rather than returning a digest that fails on every later call. Before #92 a failed construction crashed, so both described a state that never shipped. Closes #106
1 parent b870be6 commit dc5e818

2 files changed

Lines changed: 7 additions & 8 deletions

File tree

.release-notes/next-release.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ let hash = digest.final()?
155155
let mac = HmacSha256(key, message)?
156156
```
157157

158-
Constructing a `Digest` now raises if OpenSSL cannot allocate its context, rather than returning a digest that fails on every later call. When `HmacSha256` raises, reject the message. Do not fall back to a code of your own — a code you make up is one an attacker can send you.
158+
Constructing a `Digest` now raises if OpenSSL cannot allocate its context, rather than crashing. When `HmacSha256` raises, reject the message. Do not fall back to a code of your own — a code you make up is one an attacker can send you.
159159

160160
## Fix HmacSha256 returning an all-zero code when it fails
161161

@@ -169,7 +169,7 @@ It was reachable with ordinary input: computing the code of an empty key and an
169169

170170
`final` returned a block of memory as the hash without checking that OpenSSL had written it, so a failed call returned whatever that memory held — a wrong hash, and a leak of whatever was last in it. Creating a digest crashed when OpenSSL could not allocate its working context.
171171

172-
A digest now raises rather than returning a wrong hash, and one that could not be created reports it at the first `append` or `final` rather than crashing.
172+
A digest now raises rather than returning a wrong hash, and one that OpenSSL could not create raises when you construct it rather than crashing.
173173

174174
## Fix crypto functions truncating a length too large for an int
175175

ssl/crypto/crypto.pony

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ A call here gives back a correct result or it raises. It never gives back an
1414
incorrect one, so there is no value to check for and no sentinel to compare
1515
against.
1616
17-
`Digest.append`, `Digest.final`, `HmacSha256`, `Pbkdf2Sha256` and `RandBytes`
18-
are partial. They raise when OpenSSL could not do what was asked of it.
19-
`HmacSha256`, `Pbkdf2Sha256` and `RandBytes` also raise when a length you gave
20-
them is larger than the C `int` OpenSSL takes for it. Constructing a `Digest`
21-
cannot fail; a context OpenSSL would not give you surfaces at the first
22-
`append` or `final`.
17+
The `Digest` constructors, `Digest.append`, `Digest.final`, `HmacSha256`,
18+
`Pbkdf2Sha256` and `RandBytes` are partial. They raise when OpenSSL could not
19+
do what was asked of it. Constructing a `Digest` raises when OpenSSL cannot
20+
give it a context. `HmacSha256`, `Pbkdf2Sha256` and `RandBytes` also raise when
21+
a length you gave them is larger than the C `int` OpenSSL takes for it.
2322
2423
The one-shot hash functions and `ConstantTimeCompare` cannot fail and are total.
2524

0 commit comments

Comments
 (0)