This is a direct port of zcash/librustzcash#317, with minor tweaks to account for the missing `std::error::Error` impls that the original PR included, and removing the `src/init.rs` file left over from a previous rebase of the PR.