Boxed traits need to be Send and sometimes Sync

This commit is contained in:
Joseph Birr-Pixton 2016-10-04 00:46:39 +01:00
parent 0046940179
commit 76408b78f6
4 changed files with 15 additions and 15 deletions

View File

@ -86,7 +86,7 @@ pub trait ResolvesCert {
server_name: Option<&ServerNameRequest>,
sigalgs: &SupportedSignatureAlgorithms,
ec_curves: &EllipticCurveList,
ec_pointfmts: &ECPointFormatList) -> Result<(CertificatePayload, Arc<Box<sign::Signer>>), ()>;
ec_pointfmts: &ECPointFormatList) -> Result<(CertificatePayload, Arc<Box<sign::Signer + Send + Sync>>), ()>;
}
/// Common configuration for a set of server sessions.
@ -103,13 +103,13 @@ pub struct ServerConfig {
pub ignore_client_order: bool,
/// How to store client sessions.
pub session_storage: Mutex<Box<StoresServerSessions>>,
pub session_storage: Mutex<Box<StoresServerSessions + Send>>,
/// How to produce tickets.
pub ticketer: Box<ProducesTickets>,
pub ticketer: Box<ProducesTickets + Send + Sync>,
/// How to choose a server cert and key.
pub cert_resolver: Box<ResolvesCert>,
pub cert_resolver: Box<ResolvesCert + Send + Sync>,
/// Protocol names we support, most preferred first.
/// If empty we don't do ALPN at all.
@ -202,7 +202,7 @@ impl ResolvesCert for FailResolveChain {
_server_name: Option<&ServerNameRequest>,
_sigalgs: &SupportedSignatureAlgorithms,
_ec_curves: &EllipticCurveList,
_ec_pointfmts: &ECPointFormatList) -> Result<(CertificatePayload, Arc<Box<sign::Signer>>), ()> {
_ec_pointfmts: &ECPointFormatList) -> Result<(CertificatePayload, Arc<Box<sign::Signer + Send + Sync>>), ()> {
Err(())
}
}
@ -210,7 +210,7 @@ impl ResolvesCert for FailResolveChain {
/// Something which always resolves to the same cert chain.
struct AlwaysResolvesChain {
chain: CertificatePayload,
key: Arc<Box<sign::Signer>>
key: Arc<Box<sign::Signer + Send + Sync>>
}
impl AlwaysResolvesChain {
@ -230,7 +230,7 @@ impl ResolvesCert for AlwaysResolvesChain {
_server_name: Option<&ServerNameRequest>,
_sigalgs: &SupportedSignatureAlgorithms,
_ec_curves: &EllipticCurveList,
_ec_pointfmts: &ECPointFormatList) -> Result<(CertificatePayload, Arc<Box<sign::Signer>>), ()> {
_ec_pointfmts: &ECPointFormatList) -> Result<(CertificatePayload, Arc<Box<sign::Signer + Send + Sync>>), ()> {
Ok((self.chain.clone(), self.key.clone()))
}
}

View File

@ -153,7 +153,7 @@ fn emit_certificate(sess: &mut ServerSessionImpl) {
fn emit_server_kx(sess: &mut ServerSessionImpl,
sigalg: &SignatureAndHashAlgorithm,
curve: &NamedCurve,
signer: Arc<Box<sign::Signer>>) -> Result<(), TLSError> {
signer: Arc<Box<sign::Signer + Send + Sync>>) -> Result<(), TLSError> {
let kx = try!({
let scs = sess.handshake_data.ciphersuite.as_ref().unwrap();
scs.start_server_kx(curve)

View File

@ -18,7 +18,7 @@ use std::io;
use std::collections::VecDeque;
/// Generalises ClientSession and ServerSession
pub trait Session : Read + Write {
pub trait Session : Read + Write + Send {
/// Read TLS content from `rd`. This method does internal
/// buffering, so `rd` can supply TLS messages in arbitrary-
/// sized chunks (like a socket or pipe might).

View File

@ -98,8 +98,8 @@ impl ProducesTickets for AEADTicketer {
}
struct TicketSwitcherState {
current: Box<ProducesTickets>,
previous: Option<Box<ProducesTickets>>,
current: Box<ProducesTickets + Send + Sync>,
previous: Option<Box<ProducesTickets + Send + Sync>>,
next_switch_time: i64
}
@ -107,7 +107,7 @@ struct TicketSwitcherState {
/// 'previous' ticketer. It creates a new ticketer every so
/// often, demoting the current ticketer.
pub struct TicketSwitcher {
generator: fn() -> Box<ProducesTickets>,
generator: fn() -> Box<ProducesTickets + Send + Sync>,
lifetime: u32,
state: Mutex<TicketSwitcherState>
}
@ -117,7 +117,7 @@ impl TicketSwitcher {
/// is used to generate new tickets. Tickets are accepted for no
/// longer than twice this duration. `generator` produces a new
/// `ProducesTickets` implementation.
pub fn new(lifetime: u32, generator: fn() -> Box<ProducesTickets>) -> TicketSwitcher {
pub fn new(lifetime: u32, generator: fn() -> Box<ProducesTickets + Send + Sync>) -> TicketSwitcher {
TicketSwitcher {
generator: generator,
lifetime: lifetime,
@ -176,14 +176,14 @@ impl ProducesTickets for TicketSwitcher {
pub struct Ticketer {}
fn generate_inner() -> Box<ProducesTickets> {
fn generate_inner() -> Box<ProducesTickets + Send + Sync> {
Box::new(AEADTicketer::new())
}
impl Ticketer {
/// Make the recommended Ticketer. This produces tickets
/// with a 12 hour life and randomly generated keys.
pub fn new() -> Box<ProducesTickets> {
pub fn new() -> Box<ProducesTickets + Send + Sync> {
Box::new(
TicketSwitcher::new(6 * 60 * 60, generate_inner)
)