Commit 245f5f3a authored by Steven Fackler's avatar Steven Fackler
Browse files

Impl Sync and Send for various types

Closes #865
parent f645165e
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -11,6 +11,9 @@ use pkey::{HasPrivate, HasPublic, PKeyRef};
/// A type used to derive a shared secret between two keys.
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> {
    /// Creates a new `Deriver` using the provided private key.
    ///
+6 −0
Original line number Diff line number Diff line
@@ -49,6 +49,9 @@ impl MessageDigest {
    }
}

unsafe impl Sync for MessageDigest {}
unsafe impl Send for MessageDigest {}

#[derive(PartialEq, Copy, Clone)]
enum State {
    Reset,
@@ -99,6 +102,9 @@ pub struct Hasher {
    state: State,
}

unsafe impl Sync for Hasher {}
unsafe impl Send for Hasher {}

impl Hasher {
    /// Creates a new `Hasher` with the specified hash type.
    pub fn new(ty: MessageDigest) -> Result<Hasher, ErrorStack> {
+6 −0
Original line number Diff line number Diff line
@@ -85,6 +85,9 @@ pub struct Signer<'a> {
    _p: PhantomData<&'a ()>,
}

unsafe impl<'a> Sync for Signer<'a> {}
unsafe impl<'a> Send for Signer<'a> {}

impl<'a> Drop for Signer<'a> {
    fn drop(&mut self) {
        // 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 ()>,
}

unsafe impl<'a> Sync for Verifier<'a> {}
unsafe impl<'a> Send for Verifier<'a> {}

impl<'a> Drop for Verifier<'a> {
    fn drop(&mut self) {
        // pkey_ctx is owned by the md_ctx, so no need to explicitly free it.
+6 −1
Original line number Diff line number Diff line
@@ -223,6 +223,9 @@ impl Cipher {
    }
}

unsafe impl Sync for Cipher {}
unsafe impl Send for Cipher {}

/// Represents a symmetric cipher context.
///
/// Padding is enabled by default.
@@ -288,6 +291,9 @@ pub struct Crypter {
    block_size: usize,
}

unsafe impl Sync for Crypter {}
unsafe impl Send for Crypter {}

impl Crypter {
    /// Creates a new `Crypter`.  The initialisation vector, `iv`, is not necesarry for certain
    /// types of `Cipher`.
@@ -963,7 +969,6 @@ mod tests {

    #[test]
    fn test_des_ede3_cbc() {

        let pt = "54686973206973206120746573742e";
        let ct = "6f2867cfefda048a4046ef7e556c7132";
        let key = "7cb66337f3d3c0fe7cb66337f3d3c0fe7cb66337f3d3c0fe";