sfackler/rust-openssl — pull request #99 by gkoz (2014-11-20 05:33:13+00:00)
Title: Hasher: static contract checking, context reuse

This proposal is motivated by a desire to prevent illegal (if not unsafe) use of update() and finalize() (eg calling update after finalize or finalizing twice). If deemed appropriate the approach could be used for other classes. Also demonstrates context reuse under the new model.

---

- Store EVP_MD_CTX in a separate struct.
- Add from_context() constructor that uses an existing context.
- Switch to EVP_Digest(Init|Final)_ex for efficient context reuse.
- Make update() borrow &mut self.
- Make finalize() consume self. Add finalize_reuse() that also returns the
context which can be passed to from_context() constructor for reuse.

These changes let the type system prevent illegal calls to update() and
finalize().