Impl Sync and Send for various types

Closes #865
This commit is contained in:
Steven Fackler 2018-03-09 22:14:50 -08:00
parent f645165ee2
commit 245f5f3a11
4 changed files with 21 additions and 1 deletions

View File

@ -11,6 +11,9 @@ use pkey::{HasPrivate, HasPublic, PKeyRef};
/// A type used to derive a shared secret between two keys. /// A type used to derive a shared secret between two keys.
pub struct Deriver<'a>(*mut ffi::EVP_PKEY_CTX, PhantomData<&'a ()>); pub struct Deriver<'a>(*mut ffi::EVP_PKEY_CTX, PhantomData<&'a ()>);
unsafe impl<'a> Sync for Deriver<'a> {}
unsafe impl<'a> Send for Deriver<'a> {}
impl<'a> Deriver<'a> { impl<'a> Deriver<'a> {
/// Creates a new `Deriver` using the provided private key. /// Creates a new `Deriver` using the provided private key.
/// ///

View File

@ -49,6 +49,9 @@ impl MessageDigest {
} }
} }
unsafe impl Sync for MessageDigest {}
unsafe impl Send for MessageDigest {}
#[derive(PartialEq, Copy, Clone)] #[derive(PartialEq, Copy, Clone)]
enum State { enum State {
Reset, Reset,
@ -99,6 +102,9 @@ pub struct Hasher {
state: State, state: State,
} }
unsafe impl Sync for Hasher {}
unsafe impl Send for Hasher {}
impl Hasher { impl Hasher {
/// Creates a new `Hasher` with the specified hash type. /// Creates a new `Hasher` with the specified hash type.
pub fn new(ty: MessageDigest) -> Result<Hasher, ErrorStack> { pub fn new(ty: MessageDigest) -> Result<Hasher, ErrorStack> {

View File

@ -85,6 +85,9 @@ pub struct Signer<'a> {
_p: PhantomData<&'a ()>, _p: PhantomData<&'a ()>,
} }
unsafe impl<'a> Sync for Signer<'a> {}
unsafe impl<'a> Send for Signer<'a> {}
impl<'a> Drop for Signer<'a> { impl<'a> Drop for Signer<'a> {
fn drop(&mut self) { fn drop(&mut self) {
// pkey_ctx is owned by the md_ctx, so no need to explicitly free it. // pkey_ctx is owned by the md_ctx, so no need to explicitly free it.
@ -244,6 +247,9 @@ pub struct Verifier<'a> {
pkey_pd: PhantomData<&'a ()>, pkey_pd: PhantomData<&'a ()>,
} }
unsafe impl<'a> Sync for Verifier<'a> {}
unsafe impl<'a> Send for Verifier<'a> {}
impl<'a> Drop for Verifier<'a> { impl<'a> Drop for Verifier<'a> {
fn drop(&mut self) { fn drop(&mut self) {
// pkey_ctx is owned by the md_ctx, so no need to explicitly free it. // pkey_ctx is owned by the md_ctx, so no need to explicitly free it.

View File

@ -223,6 +223,9 @@ impl Cipher {
} }
} }
unsafe impl Sync for Cipher {}
unsafe impl Send for Cipher {}
/// Represents a symmetric cipher context. /// Represents a symmetric cipher context.
/// ///
/// Padding is enabled by default. /// Padding is enabled by default.
@ -288,6 +291,9 @@ pub struct Crypter {
block_size: usize, block_size: usize,
} }
unsafe impl Sync for Crypter {}
unsafe impl Send for Crypter {}
impl Crypter { impl Crypter {
/// Creates a new `Crypter`. The initialisation vector, `iv`, is not necesarry for certain /// Creates a new `Crypter`. The initialisation vector, `iv`, is not necesarry for certain
/// types of `Cipher`. /// types of `Cipher`.
@ -963,7 +969,6 @@ mod tests {
#[test] #[test]
fn test_des_ede3_cbc() { fn test_des_ede3_cbc() {
let pt = "54686973206973206120746573742e"; let pt = "54686973206973206120746573742e";
let ct = "6f2867cfefda048a4046ef7e556c7132"; let ct = "6f2867cfefda048a4046ef7e556c7132";
let key = "7cb66337f3d3c0fe7cb66337f3d3c0fe7cb66337f3d3c0fe"; let key = "7cb66337f3d3c0fe7cb66337f3d3c0fe7cb66337f3d3c0fe";