Impl NegotiateSsl for closures + rustfmt
This commit is contained in:
23
src/error.rs
23
src/error.rs
@@ -45,13 +45,17 @@ impl DbErrorNew for DbError {
|
||||
hint: map.remove(&b'H'),
|
||||
position: match map.remove(&b'P') {
|
||||
Some(pos) => Some(ErrorPosition::Normal(try!(pos.parse().map_err(|_| ())))),
|
||||
None => match map.remove(&b'p') {
|
||||
Some(pos) => Some(ErrorPosition::Internal {
|
||||
position: try!(pos.parse().map_err(|_| ())),
|
||||
query: try!(map.remove(&b'q').ok_or(())),
|
||||
}),
|
||||
None => None,
|
||||
},
|
||||
None => {
|
||||
match map.remove(&b'p') {
|
||||
Some(pos) => {
|
||||
Some(ErrorPosition::Internal {
|
||||
position: try!(pos.parse().map_err(|_| ())),
|
||||
query: try!(map.remove(&b'q').ok_or(())),
|
||||
})
|
||||
}
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
},
|
||||
where_: map.remove(&b'W'),
|
||||
schema: map.remove(&b's'),
|
||||
@@ -231,8 +235,9 @@ impl error::Error for ConnectError {
|
||||
ConnectError::BadConnectParams(_) => "Error creating `ConnectParams`",
|
||||
ConnectError::MissingUser => "User missing in `ConnectParams`",
|
||||
ConnectError::DbError(_) => "Error reported by Postgres",
|
||||
ConnectError::MissingPassword =>
|
||||
"The server requested a password but none was provided",
|
||||
ConnectError::MissingPassword => {
|
||||
"The server requested a password but none was provided"
|
||||
}
|
||||
ConnectError::UnsupportedAuthentication => {
|
||||
"The server requested an unsupported authentication method"
|
||||
}
|
||||
|
||||
@@ -25,6 +25,9 @@ pub trait StreamWrapper: Read+Write+Send {
|
||||
///
|
||||
/// If the `security-framework` Cargo feature is enabled, this trait will be
|
||||
/// implemented for `security_framework::secure_transport::ClientBuilder`.
|
||||
///
|
||||
/// It is also implemented for `Fn(&str, Stream) -> Result<Box<StreamWrapper>,
|
||||
/// Box<Error + Sync + Send>` closures.
|
||||
pub trait NegotiateSsl {
|
||||
/// Negotiates an SSL session, returning a wrapper around the provided
|
||||
/// stream.
|
||||
@@ -36,3 +39,14 @@ pub trait NegotiateSsl {
|
||||
stream: Stream)
|
||||
-> Result<Box<StreamWrapper>, Box<Error + Sync + Send>>;
|
||||
}
|
||||
|
||||
impl<F> NegotiateSsl for F
|
||||
where F: Fn(&str, Stream) -> Result<Box<StreamWrapper>, Box<Error + Sync + Send>>
|
||||
{
|
||||
fn negotiate_ssl(&self,
|
||||
host: &str,
|
||||
stream: Stream)
|
||||
-> Result<Box<StreamWrapper>, Box<Error + Sync + Send>> {
|
||||
(*self)(host, stream)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -477,7 +477,7 @@ impl InnerConnection {
|
||||
WHERE t.oid = $1") {
|
||||
Ok(..) => return Ok(()),
|
||||
Err(Error::IoError(e)) => return Err(ConnectError::IoError(e)),
|
||||
// Range types weren't added until Postgres 9.2, so pg_range may not exist
|
||||
// Range types weren't added until Postgres 9.2, so pg_range may not exist
|
||||
Err(Error::DbError(ref e)) if e.code() == &SqlState::UndefinedTable => {}
|
||||
Err(Error::DbError(e)) => return Err(ConnectError::DbError(e)),
|
||||
_ => unreachable!(),
|
||||
@@ -825,8 +825,7 @@ impl InnerConnection {
|
||||
}
|
||||
|
||||
fn _ensure_send() {
|
||||
fn _is_send<T: Send>() {
|
||||
}
|
||||
fn _is_send<T: Send>() {}
|
||||
_is_send::<Connection>();
|
||||
}
|
||||
|
||||
|
||||
10
src/md5.rs
10
src/md5.rs
@@ -21,8 +21,8 @@ struct StepUp<T> {
|
||||
ammount: T,
|
||||
}
|
||||
|
||||
impl <T> Iterator for StepUp<T> where
|
||||
T: Add<T, Output = T> + PartialOrd + Copy {
|
||||
impl<T> Iterator for StepUp<T> where T: Add<T, Output = T> + PartialOrd + Copy
|
||||
{
|
||||
type Item = T;
|
||||
|
||||
#[inline]
|
||||
@@ -41,8 +41,8 @@ trait RangeExt<T> {
|
||||
fn step_up(self, ammount: T) -> StepUp<T>;
|
||||
}
|
||||
|
||||
impl <T> RangeExt<T> for Range<T> where
|
||||
T: Add<T, Output = T> + PartialOrd + Copy {
|
||||
impl<T> RangeExt<T> for Range<T> where T: Add<T, Output = T> + PartialOrd + Copy
|
||||
{
|
||||
fn step_up(self, ammount: T) -> StepUp<T> {
|
||||
StepUp {
|
||||
next: self.start,
|
||||
@@ -108,7 +108,7 @@ trait StandardPadding {
|
||||
fn standard_padding<F: FnMut(&[u8])>(&mut self, rem: usize, func: F);
|
||||
}
|
||||
|
||||
impl <T: FixedBuffer> StandardPadding for T {
|
||||
impl<T: FixedBuffer> StandardPadding for T {
|
||||
fn standard_padding<F: FnMut(&[u8])>(&mut self, rem: usize, mut func: F) {
|
||||
let size = self.size();
|
||||
|
||||
|
||||
@@ -323,11 +323,13 @@ impl<R: BufRead + ReadTimeout> ReadMessage for R {
|
||||
b'1' => ParseComplete,
|
||||
b'2' => BindComplete,
|
||||
b'3' => CloseComplete,
|
||||
b'A' => NotificationResponse {
|
||||
pid: try!(rdr.read_u32::<BigEndian>()),
|
||||
channel: try!(rdr.read_cstr()),
|
||||
payload: try!(rdr.read_cstr()),
|
||||
},
|
||||
b'A' => {
|
||||
NotificationResponse {
|
||||
pid: try!(rdr.read_u32::<BigEndian>()),
|
||||
channel: try!(rdr.read_cstr()),
|
||||
payload: try!(rdr.read_cstr()),
|
||||
}
|
||||
}
|
||||
b'c' => BCopyDone,
|
||||
b'C' => CommandComplete { tag: try!(rdr.read_cstr()) },
|
||||
b'd' => {
|
||||
@@ -360,23 +362,29 @@ impl<R: BufRead + ReadTimeout> ReadMessage for R {
|
||||
}
|
||||
}
|
||||
b'I' => EmptyQueryResponse,
|
||||
b'K' => BackendKeyData {
|
||||
process_id: try!(rdr.read_u32::<BigEndian>()),
|
||||
secret_key: try!(rdr.read_u32::<BigEndian>()),
|
||||
},
|
||||
b'K' => {
|
||||
BackendKeyData {
|
||||
process_id: try!(rdr.read_u32::<BigEndian>()),
|
||||
secret_key: try!(rdr.read_u32::<BigEndian>()),
|
||||
}
|
||||
}
|
||||
b'n' => NoData,
|
||||
b'N' => NoticeResponse { fields: try!(read_fields(&mut rdr)) },
|
||||
b'R' => try!(read_auth_message(&mut rdr)),
|
||||
b's' => PortalSuspended,
|
||||
b'S' => ParameterStatus {
|
||||
parameter: try!(rdr.read_cstr()),
|
||||
value: try!(rdr.read_cstr()),
|
||||
},
|
||||
b'S' => {
|
||||
ParameterStatus {
|
||||
parameter: try!(rdr.read_cstr()),
|
||||
value: try!(rdr.read_cstr()),
|
||||
}
|
||||
}
|
||||
b't' => try!(read_parameter_description(&mut rdr)),
|
||||
b'T' => try!(read_row_description(&mut rdr)),
|
||||
b'Z' => ReadyForQuery { _state: try!(rdr.read_u8()) },
|
||||
t => return Err(io::Error::new(io::ErrorKind::Other,
|
||||
format!("unexpected message tag `{}`", t))),
|
||||
t => {
|
||||
return Err(io::Error::new(io::ErrorKind::Other,
|
||||
format!("unexpected message tag `{}`", t)))
|
||||
}
|
||||
};
|
||||
if rdr.limit() != 0 {
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "didn't read entire message"));
|
||||
@@ -431,8 +439,10 @@ fn read_auth_message<R: Read>(buf: &mut R) -> io::Result<BackendMessage> {
|
||||
6 => AuthenticationSCMCredential,
|
||||
7 => AuthenticationGSS,
|
||||
9 => AuthenticationSSPI,
|
||||
t => return Err(io::Error::new(io::ErrorKind::Other,
|
||||
format!("unexpected authentication tag `{}`", t))),
|
||||
t => {
|
||||
return Err(io::Error::new(io::ErrorKind::Other,
|
||||
format!("unexpected authentication tag `{}`", t)))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -28,8 +28,9 @@ pub trait ReadTimeout {
|
||||
impl ReadTimeout for BufStream<Box<StreamWrapper>> {
|
||||
fn set_read_timeout(&self, timeout: Option<Duration>) -> io::Result<()> {
|
||||
match self.get_ref().get_ref().0 {
|
||||
InternalStream::Tcp(ref s) =>
|
||||
<TcpStream as TcpStreamExt>::set_read_timeout(s, timeout),
|
||||
InternalStream::Tcp(ref s) => {
|
||||
<TcpStream as TcpStreamExt>::set_read_timeout(s, timeout)
|
||||
}
|
||||
#[cfg(feature = "unix_socket")]
|
||||
InternalStream::Unix(ref s) => s.set_read_timeout(timeout),
|
||||
}
|
||||
|
||||
@@ -827,7 +827,8 @@ pub trait ToSql: fmt::Debug {
|
||||
fn to_sql_checked(&self, ty: &Type, out: &mut Write, ctx: &SessionInfo) -> Result<IsNull>;
|
||||
}
|
||||
|
||||
impl<'a, T> ToSql for &'a T where T: ToSql {
|
||||
impl<'a, T> ToSql for &'a T where T: ToSql
|
||||
{
|
||||
to_sql_checked!();
|
||||
|
||||
fn to_sql<W: Write + ?Sized>(&self,
|
||||
|
||||
84
src/url.rs
84
src/url.rs
@@ -121,45 +121,49 @@ fn decode_inner(c: &str, full_url: bool) -> DecodeResult<String> {
|
||||
|
||||
loop {
|
||||
match iter.next() {
|
||||
Some(b) => match b as char {
|
||||
'%' => {
|
||||
let bytes = match (iter.next(), iter.next()) {
|
||||
(Some(one), Some(two)) => [one, two],
|
||||
_ => return Err(format!("Malformed input: found '%' without two \
|
||||
trailing bytes")),
|
||||
};
|
||||
Some(b) => {
|
||||
match b as char {
|
||||
'%' => {
|
||||
let bytes = match (iter.next(), iter.next()) {
|
||||
(Some(one), Some(two)) => [one, two],
|
||||
_ => {
|
||||
return Err(format!("Malformed input: found '%' without two \
|
||||
trailing bytes"))
|
||||
}
|
||||
};
|
||||
|
||||
// Only decode some characters if full_url:
|
||||
match str::from_utf8(&bytes).unwrap().from_hex().unwrap()[0] as char {
|
||||
// gen-delims:
|
||||
':' |
|
||||
'/' |
|
||||
'?' |
|
||||
'#' |
|
||||
'[' |
|
||||
']' |
|
||||
'@' |
|
||||
'!' |
|
||||
'$' |
|
||||
'&' |
|
||||
'"' |
|
||||
'(' |
|
||||
')' |
|
||||
'*' |
|
||||
'+' |
|
||||
',' |
|
||||
';' |
|
||||
'=' if full_url => {
|
||||
out.push('%');
|
||||
out.push(bytes[0] as char);
|
||||
out.push(bytes[1] as char);
|
||||
// Only decode some characters if full_url:
|
||||
match str::from_utf8(&bytes).unwrap().from_hex().unwrap()[0] as char {
|
||||
// gen-delims:
|
||||
':' |
|
||||
'/' |
|
||||
'?' |
|
||||
'#' |
|
||||
'[' |
|
||||
']' |
|
||||
'@' |
|
||||
'!' |
|
||||
'$' |
|
||||
'&' |
|
||||
'"' |
|
||||
'(' |
|
||||
')' |
|
||||
'*' |
|
||||
'+' |
|
||||
',' |
|
||||
';' |
|
||||
'=' if full_url => {
|
||||
out.push('%');
|
||||
out.push(bytes[0] as char);
|
||||
out.push(bytes[1] as char);
|
||||
}
|
||||
|
||||
ch => out.push(ch),
|
||||
}
|
||||
|
||||
ch => out.push(ch),
|
||||
}
|
||||
ch => out.push(ch),
|
||||
}
|
||||
ch => out.push(ch),
|
||||
},
|
||||
}
|
||||
None => return Ok(out),
|
||||
}
|
||||
}
|
||||
@@ -384,10 +388,12 @@ fn get_authority(rawurl: &str) -> DecodeResult<(Option<UserInfo>, &str, Option<u
|
||||
// If we have a port string, ensure it parses to u16.
|
||||
let port = match port {
|
||||
None => None,
|
||||
opt => match opt.and_then(|p| FromStr::from_str(p).ok()) {
|
||||
None => return Err(format!("Failed to parse port: {:?}", port)),
|
||||
opt => opt,
|
||||
},
|
||||
opt => {
|
||||
match opt.and_then(|p| FromStr::from_str(p).ok()) {
|
||||
None => return Err(format!("Failed to parse port: {:?}", port)),
|
||||
opt => opt,
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Ok((userinfo, host, port, rest))
|
||||
|
||||
Reference in New Issue
Block a user