Skip to content

Commit 39934e6

Browse files
committed
Docs and cleanup
1 parent 7e4f7b2 commit 39934e6

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/authentication.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ use md5::Context;
44

55
/// Hashes authentication information in a way suitable for use in response
66
/// to an `AuthenticationMd5Password` message.
7+
///
8+
/// The resulting string should be sent back to the database in a
9+
/// `PasswordMessage` message.
710
#[inline]
811
pub fn md5_hash(username: &[u8], password: &[u8], salt: [u8; 4]) -> String {
912
let mut context = Context::new();

src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
//! Low level Postgres protocol APIs.
2+
//!
3+
//! This crate implements the low level components of Postgres's communication
4+
//! protocol, including message and value serialization and deserialization.
5+
//! It is designed to be used as a building block by higher level APIs such as
6+
//! `rust-postgres`, and should not typically be used directly.
7+
//!
8+
//! # Note
9+
//!
10+
//! This library assumes that the `client_encoding` backend parameter has been
11+
//! set to `UTF8`. It will most likely not behave properly if that is not the case.
212
#![warn(missing_docs)]
313
extern crate byteorder;
414
extern crate fallible_iterator;

src/types.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,10 @@ pub fn empty_range_to_sql(buf: &mut Vec<u8>) {
625625
}
626626

627627
/// Serializes a range value.
628-
pub fn range_to_sql<F, G>(lower: F, upper: G, buf: &mut Vec<u8>) -> Result<(), Box<Error + Sync + Send>>
628+
pub fn range_to_sql<F, G>(lower: F,
629+
upper: G,
630+
buf: &mut Vec<u8>)
631+
-> Result<(), Box<Error + Sync + Send>>
629632
where F: FnOnce(&mut Vec<u8>) -> Result<RangeBound<IsNull>, Box<Error + Sync + Send>>,
630633
G: FnOnce(&mut Vec<u8>) -> Result<RangeBound<IsNull>, Box<Error + Sync + Send>>
631634
{
@@ -701,11 +704,19 @@ pub fn range_from_sql<'a>(mut buf: &'a [u8]) -> Result<Range<'a>, Box<Error + Sy
701704
let lower = try!(read_bound(&mut buf, tag, RANGE_LOWER_UNBOUNDED, RANGE_LOWER_INCLUSIVE));
702705
let upper = try!(read_bound(&mut buf, tag, RANGE_UPPER_UNBOUNDED, RANGE_UPPER_INCLUSIVE));
703706

707+
if !buf.is_empty() {
708+
return Err("invalid message size".into());
709+
}
710+
704711
Ok(Range::Nonempty(lower, upper))
705712
}
706713

707714
#[inline]
708-
fn read_bound<'a>(buf: &mut &'a [u8], tag: u8, unbounded: u8, inclusive: u8) -> Result<RangeBound<Option<&'a [u8]>>, Box<Error + Sync + Send>> {
715+
fn read_bound<'a>(buf: &mut &'a [u8],
716+
tag: u8,
717+
unbounded: u8,
718+
inclusive: u8)
719+
-> Result<RangeBound<Option<&'a [u8]>>, Box<Error + Sync + Send>> {
709720
if tag & unbounded != 0 {
710721
Ok(RangeBound::Unbounded)
711722
} else {

0 commit comments

Comments
 (0)