Skip to content

Commit 84502bc

Browse files
committed
Revert "allow arbitrary config params with more efficient repr (#30)"
This reverts commit cff6927.
1 parent cff6927 commit 84502bc

File tree

10 files changed

+156
-159
lines changed

10 files changed

+156
-159
lines changed

postgres-protocol/src/authentication/sasl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ enum Credentials<const N: usize> {
117117
/// A regular password as a vector of bytes.
118118
Password(Vec<u8>),
119119
/// A precomputed pair of keys.
120-
Keys(ScramKeys<N>),
120+
Keys(Box<ScramKeys<N>>),
121121
}
122122

123123
enum State {
@@ -176,7 +176,7 @@ impl ScramSha256 {
176176

177177
/// Constructs a new instance which will use the provided key pair for authentication.
178178
pub fn new_with_keys(keys: ScramKeys<32>, channel_binding: ChannelBinding) -> ScramSha256 {
179-
let password = Credentials::Keys(keys);
179+
let password = Credentials::Keys(keys.into());
180180
ScramSha256::new_inner(password, channel_binding, nonce())
181181
}
182182

postgres-protocol/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ macro_rules! from_usize {
6868
impl FromUsize for $t {
6969
#[inline]
7070
fn from_usize(x: usize) -> io::Result<$t> {
71-
if x > <$t>::MAX as usize {
71+
if x > <$t>::max_value() as usize {
7272
Err(io::Error::new(
7373
io::ErrorKind::InvalidInput,
7474
"value too large to transmit",

postgres-protocol/src/message/frontend.rs

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -271,66 +271,6 @@ where
271271
})
272272
}
273273

274-
#[inline]
275-
pub fn startup_message_cstr(
276-
parameters: &StartupMessageParams,
277-
buf: &mut BytesMut,
278-
) -> io::Result<()> {
279-
write_body(buf, |buf| {
280-
// postgres protocol version 3.0(196608) in bigger-endian
281-
buf.put_i32(0x00_03_00_00);
282-
buf.put_slice(&parameters.params);
283-
buf.put_u8(0);
284-
Ok(())
285-
})
286-
}
287-
288-
#[derive(Debug, Clone, Default, PartialEq, Eq)]
289-
pub struct StartupMessageParams {
290-
params: BytesMut,
291-
}
292-
293-
impl StartupMessageParams {
294-
/// Set parameter's value by its name.
295-
pub fn insert(&mut self, name: &str, value: &str) -> Result<(), io::Error> {
296-
if name.contains('\0') | value.contains('\0') {
297-
return Err(io::Error::new(
298-
io::ErrorKind::InvalidInput,
299-
"string contains embedded null",
300-
));
301-
}
302-
self.params.put(name.as_bytes());
303-
self.params.put(&b"\0"[..]);
304-
self.params.put(value.as_bytes());
305-
self.params.put(&b"\0"[..]);
306-
Ok(())
307-
}
308-
309-
pub fn str_iter(&self) -> impl Iterator<Item = (&str, &str)> {
310-
let params =
311-
std::str::from_utf8(&self.params).expect("should be validated as utf8 already");
312-
StrParamsIter(params)
313-
}
314-
315-
/// Get parameter's value by its name.
316-
pub fn get(&self, name: &str) -> Option<&str> {
317-
self.str_iter().find_map(|(k, v)| (k == name).then_some(v))
318-
}
319-
}
320-
321-
struct StrParamsIter<'a>(&'a str);
322-
323-
impl<'a> Iterator for StrParamsIter<'a> {
324-
type Item = (&'a str, &'a str);
325-
326-
fn next(&mut self) -> Option<Self::Item> {
327-
let (key, r) = self.0.split_once('\0')?;
328-
let (value, r) = r.split_once('\0')?;
329-
self.0 = r;
330-
Some((key, value))
331-
}
332-
}
333-
334274
#[inline]
335275
pub fn sync(buf: &mut BytesMut) {
336276
buf.put_u8(b'S');

postgres-types/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,7 @@ impl ToSql for IpAddr {
11721172
}
11731173

11741174
fn downcast(len: usize) -> Result<i32, Box<dyn Error + Sync + Send>> {
1175-
if len > i32::MAX as usize {
1175+
if len > i32::max_value() as usize {
11761176
Err("value too large to transmit".into())
11771177
} else {
11781178
Ok(len as i32)

postgres-types/src/special.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use bytes::BytesMut;
22
use postgres_protocol::types;
33
use std::error::Error;
4+
use std::{i32, i64};
45

56
use crate::{FromSql, IsNull, ToSql, Type};
67

postgres/src/config.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ impl Config {
145145
self
146146
}
147147

148+
/// Gets the password to authenticate with, if one has been configured with
149+
/// the `password` method.
150+
pub fn get_password(&self) -> Option<&[u8]> {
151+
self.config.get_password()
152+
}
153+
148154
/// Sets precomputed protocol-specific keys to authenticate with.
149155
/// When set, this option will override `password`.
150156
/// See [`AuthKeys`] for more information.
@@ -153,6 +159,12 @@ impl Config {
153159
self
154160
}
155161

162+
/// Gets precomputed protocol-specific keys to authenticate with.
163+
/// if one has been configured with the `auth_keys` method.
164+
pub fn get_auth_keys(&self) -> Option<AuthKeys> {
165+
self.config.get_auth_keys()
166+
}
167+
156168
/// Sets the name of the database to connect to.
157169
///
158170
/// Defaults to the user.
@@ -173,12 +185,24 @@ impl Config {
173185
self
174186
}
175187

188+
/// Gets the command line options used to configure the server, if the
189+
/// options have been set with the `options` method.
190+
pub fn get_options(&self) -> Option<&str> {
191+
self.config.get_options()
192+
}
193+
176194
/// Sets the value of the `application_name` runtime parameter.
177195
pub fn application_name(&mut self, application_name: &str) -> &mut Config {
178196
self.config.application_name(application_name);
179197
self
180198
}
181199

200+
/// Gets the value of the `application_name` runtime parameter, if it has
201+
/// been set with the `application_name` method.
202+
pub fn get_application_name(&self) -> Option<&str> {
203+
self.config.get_application_name()
204+
}
205+
182206
/// Sets the SSL configuration.
183207
///
184208
/// Defaults to `prefer`.

0 commit comments

Comments
 (0)