Skip to content

Commit 6afba8f

Browse files
authored
Merge pull request #7 from prisma/push-sztwulwxzrnp
Merge tokio-postgres 0.7.13
2 parents 0db3436 + 432d2ea commit 6afba8f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+367
-80
lines changed

.github/workflows/ci.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,18 @@ jobs:
7373
path: target
7474
key: check-wasm32-target-${{ runner.os }}-${{ steps.rust-version.outputs.version }}-${{ hashFiles('Cargo.lock') }}
7575
- run: cargo check --target wasm32-unknown-unknown --manifest-path tokio-postgres/Cargo.toml --no-default-features --features js
76+
env:
77+
RUSTFLAGS: --cfg getrandom_backend="wasm_js"
7678

7779
test:
7880
name: test
7981
runs-on: ubuntu-latest
8082
steps:
81-
- uses: actions/checkout@v3
83+
- uses: actions/checkout@v4
8284
- run: docker compose up -d
8385
- uses: sfackler/actions/rustup@master
8486
with:
85-
version: 1.74.0
87+
version: 1.81.0
8688
- run: echo "version=$(rustc --version)" >> $GITHUB_OUTPUT
8789
id: rust-version
8890
- uses: actions/cache@v3

docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: '2'
22
services:
33
postgres:
4-
image: postgres:14
4+
image: docker.io/postgres:17
55
ports:
66
- 5433:5433
77
volumes:

postgres-native-tls/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## v0.5.1 - 2025-02-02
4+
5+
### Added
6+
7+
* Added `set_postgresql_alpn`.
8+
39
## v0.5.0 - 2020-12-25
410

511
### Changed

postgres-native-tls/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "postgres-native-tls"
3-
version = "0.5.0"
3+
version = "0.5.1"
44
authors = ["Steven Fackler <[email protected]>"]
55
edition = "2018"
66
license = "MIT OR Apache-2.0"
@@ -17,7 +17,7 @@ runtime = ["tokio-postgres/runtime"]
1717
vendored-openssl = ["tokio-native-tls/vendored", "native-tls/vendored"]
1818

1919
[dependencies]
20-
native-tls = "0.2"
20+
native-tls = { version = "0.2", features = ["alpn"] }
2121
tokio = "1.0"
2222
tokio-native-tls = "0.3"
2323
tokio-postgres = { version = "0.7.11", path = "../tokio-postgres", default-features = false }

postgres-native-tls/src/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
//! ```
5454
#![warn(rust_2018_idioms, clippy::all, missing_docs)]
5555

56+
use native_tls::TlsConnectorBuilder;
5657
use std::future::Future;
5758
use std::io;
5859
use std::pin::Pin;
@@ -180,3 +181,10 @@ where
180181
}
181182
}
182183
}
184+
185+
/// Set ALPN for `TlsConnectorBuilder`
186+
///
187+
/// This is required when using `sslnegotiation=direct`
188+
pub fn set_postgresql_alpn(builder: &mut TlsConnectorBuilder) {
189+
builder.request_alpns(&["postgresql"]);
190+
}

postgres-native-tls/src/test.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use tokio_postgres::tls::TlsConnect;
55

66
#[cfg(feature = "runtime")]
77
use crate::MakeTlsConnector;
8-
use crate::TlsConnector;
8+
use crate::{set_postgresql_alpn, TlsConnector};
99

1010
async fn smoke_test<T>(s: &str, tls: T)
1111
where
@@ -42,6 +42,21 @@ async fn require() {
4242
.await;
4343
}
4444

45+
#[tokio::test]
46+
async fn direct() {
47+
let mut builder = native_tls::TlsConnector::builder();
48+
builder.add_root_certificate(
49+
Certificate::from_pem(include_bytes!("../../test/server.crt")).unwrap(),
50+
);
51+
set_postgresql_alpn(&mut builder);
52+
let connector = builder.build().unwrap();
53+
smoke_test(
54+
"user=ssl_user dbname=postgres sslmode=require sslnegotiation=direct",
55+
TlsConnector::new(connector, "localhost"),
56+
)
57+
.await;
58+
}
59+
4560
#[tokio::test]
4661
async fn prefer() {
4762
let connector = native_tls::TlsConnector::builder()

postgres-openssl/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## v0.5.1 - 2025-02-02
4+
5+
### Added
6+
7+
* Added `set_postgresql_alpn`.
8+
39
## v0.5.0 - 2020-12-25
410

511
### Changed

postgres-openssl/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "postgres-openssl"
3-
version = "0.5.0"
3+
version = "0.5.1"
44
authors = ["Steven Fackler <[email protected]>"]
55
edition = "2018"
66
license = "MIT OR Apache-2.0"

postgres-openssl/src/lib.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ use openssl::hash::MessageDigest;
5353
use openssl::nid::Nid;
5454
#[cfg(feature = "runtime")]
5555
use openssl::ssl::SslConnector;
56-
use openssl::ssl::{self, ConnectConfiguration, SslRef};
56+
use openssl::ssl::{self, ConnectConfiguration, SslConnectorBuilder, SslRef};
5757
use openssl::x509::X509VerifyResult;
5858
use std::error::Error;
5959
use std::fmt::{self, Debug};
@@ -250,3 +250,10 @@ fn tls_server_end_point(ssl: &SslRef) -> Option<Vec<u8>> {
250250
};
251251
cert.digest(md).ok().map(|b| b.to_vec())
252252
}
253+
254+
/// Set ALPN for `SslConnectorBuilder`
255+
///
256+
/// This is required when using `sslnegotiation=direct`
257+
pub fn set_postgresql_alpn(builder: &mut SslConnectorBuilder) -> Result<(), ErrorStack> {
258+
builder.set_alpn_protos(b"\x0apostgresql")
259+
}

postgres-openssl/src/test.rs

+13
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ async fn require() {
3737
.await;
3838
}
3939

40+
#[tokio::test]
41+
async fn direct() {
42+
let mut builder = SslConnector::builder(SslMethod::tls()).unwrap();
43+
builder.set_ca_file("../test/server.crt").unwrap();
44+
set_postgresql_alpn(&mut builder).unwrap();
45+
let ctx = builder.build();
46+
smoke_test(
47+
"user=ssl_user dbname=postgres sslmode=require sslnegotiation=direct",
48+
TlsConnector::new(ctx.configure().unwrap(), "localhost"),
49+
)
50+
.await;
51+
}
52+
4053
#[tokio::test]
4154
async fn prefer() {
4255
let mut builder = SslConnector::builder(SslMethod::tls()).unwrap();

postgres-protocol/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## v0.6.8 - 2025-02-02
4+
5+
### Changed
6+
7+
* Upgraded `getrandom`.
8+
39
## v0.6.7 - 2024-07-21
410

511
### Deprecated

postgres-protocol/Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "postgres-protocol"
3-
version = "0.6.7"
3+
version = "0.6.8"
44
authors = ["Steven Fackler <[email protected]>"]
55
edition = "2018"
66
description = "Low level Postgres protocol APIs"
@@ -10,7 +10,7 @@ readme = "../README.md"
1010

1111
[features]
1212
default = []
13-
js = ["getrandom/js"]
13+
js = ["getrandom/wasm_js"]
1414

1515
[dependencies]
1616
base64 = "0.22"
@@ -20,7 +20,7 @@ fallible-iterator = "0.2"
2020
hmac = "0.12"
2121
md-5 = "0.10"
2222
memchr = "2.0"
23-
rand = "0.8"
23+
rand = "0.9"
2424
sha2 = "0.10"
2525
stringprep = "0.1"
26-
getrandom = { version = "0.2", optional = true }
26+
getrandom = { version = "0.3", optional = true }

postgres-protocol/src/authentication/sasl.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ impl ScramSha256 {
136136
/// Constructs a new instance which will use the provided password for authentication.
137137
pub fn new(password: &[u8], channel_binding: ChannelBinding) -> ScramSha256 {
138138
// rand 0.5's ThreadRng is cryptographically secure
139-
let mut rng = rand::thread_rng();
139+
let mut rng = rand::rng();
140140
let nonce = (0..NONCE_LENGTH)
141141
.map(|_| {
142-
let mut v = rng.gen_range(0x21u8..0x7e);
142+
let mut v = rng.random_range(0x21u8..0x7e);
143143
if v == 0x2c {
144144
v = 0x7e
145145
}

postgres-protocol/src/message/backend.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ pub struct ColumnFormats<'a> {
475475
remaining: u16,
476476
}
477477

478-
impl<'a> FallibleIterator for ColumnFormats<'a> {
478+
impl FallibleIterator for ColumnFormats<'_> {
479479
type Item = u16;
480480
type Error = io::Error;
481481

@@ -557,7 +557,7 @@ pub struct DataRowRanges<'a> {
557557
remaining: u16,
558558
}
559559

560-
impl<'a> FallibleIterator for DataRowRanges<'a> {
560+
impl FallibleIterator for DataRowRanges<'_> {
561561
type Item = Option<Range<usize>>;
562562
type Error = io::Error;
563563

@@ -645,7 +645,7 @@ pub struct ErrorField<'a> {
645645
value: &'a [u8],
646646
}
647647

648-
impl<'a> ErrorField<'a> {
648+
impl ErrorField<'_> {
649649
#[inline]
650650
pub fn type_(&self) -> u8 {
651651
self.type_
@@ -717,7 +717,7 @@ pub struct Parameters<'a> {
717717
remaining: u16,
718718
}
719719

720-
impl<'a> FallibleIterator for Parameters<'a> {
720+
impl FallibleIterator for Parameters<'_> {
721721
type Item = Oid;
722722
type Error = io::Error;
723723

postgres-protocol/src/password/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const SCRAM_DEFAULT_SALT_LEN: usize = 16;
2828
/// special characters that would require escaping in an SQL command.
2929
pub fn scram_sha_256(password: &[u8]) -> String {
3030
let mut salt: [u8; SCRAM_DEFAULT_SALT_LEN] = [0; SCRAM_DEFAULT_SALT_LEN];
31-
let mut rng = rand::thread_rng();
31+
let mut rng = rand::rng();
3232
rng.fill_bytes(&mut salt);
3333
scram_sha_256_salt(password, salt)
3434
}

postgres-protocol/src/types/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ impl<'a> Array<'a> {
582582
/// An iterator over the dimensions of an array.
583583
pub struct ArrayDimensions<'a>(&'a [u8]);
584584

585-
impl<'a> FallibleIterator for ArrayDimensions<'a> {
585+
impl FallibleIterator for ArrayDimensions<'_> {
586586
type Item = ArrayDimension;
587587
type Error = StdBox<dyn Error + Sync + Send>;
588588

@@ -950,7 +950,7 @@ pub struct PathPoints<'a> {
950950
buf: &'a [u8],
951951
}
952952

953-
impl<'a> FallibleIterator for PathPoints<'a> {
953+
impl FallibleIterator for PathPoints<'_> {
954954
type Item = Point;
955955
type Error = StdBox<dyn Error + Sync + Send>;
956956

postgres-types/CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
## Unreleased
44

5+
## v0.2.9 - 2025-02-02
6+
7+
### Added
8+
9+
* Added support for `cidr` 0.3 via the `with-cidr-0_3` feature.
10+
11+
### Fixed
12+
13+
* Fixed deserialization of out of bounds inputs to `time` 0.3 types to return an error rather than panic.
14+
515
## v0.2.8 - 2024-09-15
616

717
### Added

postgres-types/Cargo.toml

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "postgres-types"
3-
version = "0.2.8"
3+
version = "0.2.9"
44
authors = ["Steven Fackler <[email protected]>"]
55
edition = "2018"
66
license = "MIT OR Apache-2.0"
@@ -16,6 +16,7 @@ array-impls = ["array-init"]
1616
js = ["postgres-protocol/js"]
1717
with-bit-vec-0_6 = ["bit-vec-06"]
1818
with-cidr-0_2 = ["cidr-02"]
19+
with-cidr-0_3 = ["cidr-03"]
1920
with-chrono-0_4 = ["chrono-04"]
2021
with-eui48-0_4 = ["eui48-04"]
2122
with-eui48-1 = ["eui48-1"]
@@ -32,7 +33,7 @@ with-time-0_3 = ["time-03"]
3233
[dependencies]
3334
bytes = "1.0"
3435
fallible-iterator = "0.2"
35-
postgres-protocol = { version = "0.6.7", path = "../postgres-protocol" }
36+
postgres-protocol = { version = "0.6.8", path = "../postgres-protocol" }
3637
postgres-derive = { version = "0.4.6", optional = true, path = "../postgres-derive" }
3738

3839
array-init = { version = "2", optional = true }
@@ -41,6 +42,7 @@ chrono-04 = { version = "0.4.16", package = "chrono", default-features = false,
4142
"clock",
4243
], optional = true }
4344
cidr-02 = { version = "0.2", package = "cidr", optional = true }
45+
cidr-03 = { version = "0.3", package = "cidr", optional = true }
4446
# eui48-04 will stop compiling and support will be removed
4547
# See https://github.com/sfackler/rust-postgres/issues/1073
4648
eui48-04 = { version = "0.4", package = "eui48", optional = true }

postgres-types/src/cidr_03.rs

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
use bytes::BytesMut;
2+
use cidr_03::{IpCidr, IpInet};
3+
use postgres_protocol::types;
4+
use std::error::Error;
5+
6+
use crate::{FromSql, IsNull, ToSql, Type};
7+
8+
impl<'a> FromSql<'a> for IpCidr {
9+
fn from_sql(_: &Type, raw: &[u8]) -> Result<Self, Box<dyn Error + Sync + Send>> {
10+
let inet = types::inet_from_sql(raw)?;
11+
Ok(IpCidr::new(inet.addr(), inet.netmask())?)
12+
}
13+
14+
accepts!(CIDR);
15+
}
16+
17+
impl ToSql for IpCidr {
18+
fn to_sql(&self, _: &Type, w: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
19+
types::inet_to_sql(self.first_address(), self.network_length(), w);
20+
Ok(IsNull::No)
21+
}
22+
23+
accepts!(CIDR);
24+
to_sql_checked!();
25+
}
26+
27+
impl<'a> FromSql<'a> for IpInet {
28+
fn from_sql(_: &Type, raw: &[u8]) -> Result<Self, Box<dyn Error + Sync + Send>> {
29+
let inet = types::inet_from_sql(raw)?;
30+
Ok(IpInet::new(inet.addr(), inet.netmask())?)
31+
}
32+
33+
accepts!(INET);
34+
}
35+
36+
impl ToSql for IpInet {
37+
fn to_sql(&self, _: &Type, w: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
38+
types::inet_to_sql(self.address(), self.network_length(), w);
39+
Ok(IsNull::No)
40+
}
41+
42+
accepts!(INET);
43+
to_sql_checked!();
44+
}

0 commit comments

Comments
 (0)