aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Alessandro Ghedini <alessandro@ghedini.me> 2020-12-16 13:39:16 +0000
committerGravatar Alessandro Ghedini <alessandro@ghedini.me> 2021-01-21 14:11:19 +0000
commitc4786c06a71cd6b41d9f49d6a055800e19f96a57 (patch)
tree65ce40def20b20bdd274286dbcde9f31d392e640 /src
parent9d0c677ef1411b24d720b5c8b73bcc94b5535c29 (diff)
downloadquiche-c4786c06a71cd6b41d9f49d6a055800e19f96a57.tar.gz
quiche-c4786c06a71cd6b41d9f49d6a055800e19f96a57.tar.zst
quiche-c4786c06a71cd6b41d9f49d6a055800e19f96a57.zip
use ConnectionId in public functions
This changes the remaining public APIs to use the ConnectionId type for connection ID values, instead of slices. The FFI API is left as-is, as there isn't much point to introduce a new type there.
Diffstat (limited to 'src')
-rw-r--r--src/ffi.rs31
-rw-r--r--src/h3/mod.rs10
-rw-r--r--src/lib.rs77
-rw-r--r--src/packet.rs4
4 files changed, 76 insertions, 46 deletions
diff --git a/src/ffi.rs b/src/ffi.rs
index f2e88574..4120e350 100644
--- a/src/ffi.rs
+++ b/src/ffi.rs
@@ -332,14 +332,17 @@ pub extern fn quiche_accept(
config: &mut Config,
) -> *mut Connection {
let scid = unsafe { slice::from_raw_parts(scid, scid_len) };
+ let scid = ConnectionId::from_ref(scid);
let odcid = if !odcid.is_null() && odcid_len > 0 {
- Some(unsafe { slice::from_raw_parts(odcid, odcid_len) })
+ Some(ConnectionId::from_ref(unsafe {
+ slice::from_raw_parts(odcid, odcid_len)
+ }))
} else {
None
};
- match accept(scid, odcid, config) {
+ match accept(&scid, odcid.as_ref(), config) {
Ok(c) => Box::into_raw(Pin::into_inner(c)),
Err(_) => ptr::null_mut(),
@@ -358,8 +361,9 @@ pub extern fn quiche_connect(
};
let scid = unsafe { slice::from_raw_parts(scid, scid_len) };
+ let scid = ConnectionId::from_ref(scid);
- match connect(server_name, scid, config) {
+ match connect(server_name, &scid, config) {
Ok(c) => Box::into_raw(Pin::into_inner(c)),
Err(_) => ptr::null_mut(),
@@ -372,10 +376,14 @@ pub extern fn quiche_negotiate_version(
out: *mut u8, out_len: size_t,
) -> ssize_t {
let scid = unsafe { slice::from_raw_parts(scid, scid_len) };
+ let scid = ConnectionId::from_ref(scid);
+
let dcid = unsafe { slice::from_raw_parts(dcid, dcid_len) };
+ let dcid = ConnectionId::from_ref(dcid);
+
let out = unsafe { slice::from_raw_parts_mut(out, out_len) };
- match negotiate_version(scid, dcid, out) {
+ match negotiate_version(&scid, &dcid, out) {
Ok(v) => v as ssize_t,
Err(e) => e.to_c(),
@@ -394,12 +402,18 @@ pub extern fn quiche_retry(
token_len: size_t, version: u32, out: *mut u8, out_len: size_t,
) -> ssize_t {
let scid = unsafe { slice::from_raw_parts(scid, scid_len) };
+ let scid = ConnectionId::from_ref(scid);
+
let dcid = unsafe { slice::from_raw_parts(dcid, dcid_len) };
+ let dcid = ConnectionId::from_ref(dcid);
+
let new_scid = unsafe { slice::from_raw_parts(new_scid, new_scid_len) };
+ let new_scid = ConnectionId::from_ref(new_scid);
+
let token = unsafe { slice::from_raw_parts(token, token_len) };
let out = unsafe { slice::from_raw_parts_mut(out, out_len) };
- match retry(scid, dcid, new_scid, token, version, out) {
+ match retry(&scid, &dcid, &new_scid, token, version, out) {
Ok(v) => v as ssize_t,
Err(e) => e.to_c(),
@@ -412,16 +426,19 @@ pub extern fn quiche_conn_new_with_tls(
config: &mut Config, ssl: *mut c_void, is_server: bool,
) -> *mut Connection {
let scid = unsafe { slice::from_raw_parts(scid, scid_len) };
+ let scid = ConnectionId::from_ref(scid);
let odcid = if !odcid.is_null() && odcid_len > 0 {
- Some(unsafe { slice::from_raw_parts(odcid, odcid_len) })
+ Some(ConnectionId::from_ref(unsafe {
+ slice::from_raw_parts(odcid, odcid_len)
+ }))
} else {
None
};
let tls = unsafe { tls::Handshake::from_ptr(ssl) };
- match Connection::with_tls(scid, odcid, config, tls, is_server) {
+ match Connection::with_tls(&scid, odcid.as_ref(), config, tls, is_server) {
Ok(c) => Box::into_raw(Pin::into_inner(c)),
Err(_) => ptr::null_mut(),
diff --git a/src/h3/mod.rs b/src/h3/mod.rs
index ce72ff8e..98204a90 100644
--- a/src/h3/mod.rs
+++ b/src/h3/mod.rs
@@ -59,7 +59,7 @@
//!
//! ```no_run
//! # let mut config = quiche::Config::new(quiche::PROTOCOL_VERSION).unwrap();
-//! # let scid = [0xba; 16];
+//! # let scid = quiche::ConnectionId::from_ref(&[0xba; 16]);
//! # let mut conn = quiche::connect(None, &scid, &mut config).unwrap();
//! # let h3_config = quiche::h3::Config::new()?;
//! let h3_conn = quiche::h3::Connection::with_transport(&mut conn, &h3_config)?;
@@ -74,7 +74,7 @@
//!
//! ```no_run
//! # let mut config = quiche::Config::new(quiche::PROTOCOL_VERSION).unwrap();
-//! # let scid = [0xba; 16];
+//! # let scid = quiche::ConnectionId::from_ref(&[0xba; 16]);
//! # let mut conn = quiche::connect(None, &scid, &mut config).unwrap();
//! # let h3_config = quiche::h3::Config::new()?;
//! # let mut h3_conn = quiche::h3::Connection::with_transport(&mut conn, &h3_config)?;
@@ -95,7 +95,7 @@
//!
//! ```no_run
//! # let mut config = quiche::Config::new(quiche::PROTOCOL_VERSION).unwrap();
-//! # let scid = [0xba; 16];
+//! # let scid = quiche::ConnectionId::from_ref(&[0xba; 16]);
//! # let mut conn = quiche::connect(None, &scid, &mut config).unwrap();
//! # let h3_config = quiche::h3::Config::new()?;
//! # let mut h3_conn = quiche::h3::Connection::with_transport(&mut conn, &h3_config)?;
@@ -125,7 +125,7 @@
//! use quiche::h3::NameValue;
//!
//! # let mut config = quiche::Config::new(quiche::PROTOCOL_VERSION).unwrap();
-//! # let scid = [0xba; 16];
+//! # let scid = quiche::ConnectionId::from_ref(&[0xba; 16]);
//! # let mut conn = quiche::accept(&scid, None, &mut config).unwrap();
//! # let h3_config = quiche::h3::Config::new()?;
//! # let mut h3_conn = quiche::h3::Connection::with_transport(&mut conn, &h3_config)?;
@@ -186,7 +186,7 @@
//! use quiche::h3::NameValue;
//!
//! # let mut config = quiche::Config::new(quiche::PROTOCOL_VERSION).unwrap();
-//! # let scid = [0xba; 16];
+//! # let scid = quiche::ConnectionId::from_ref(&[0xba; 16]);
//! # let mut conn = quiche::connect(None, &scid, &mut config).unwrap();
//! # let h3_config = quiche::h3::Config::new()?;
//! # let mut h3_conn = quiche::h3::Connection::with_transport(&mut conn, &h3_config)?;
diff --git a/src/lib.rs b/src/lib.rs
index cb291a9d..865a4a66 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -54,7 +54,7 @@
//! ```
//! # let mut config = quiche::Config::new(quiche::PROTOCOL_VERSION)?;
//! # let server_name = "quic.tech";
-//! # let scid = [0xba; 16];
+//! # let scid = quiche::ConnectionId::from_ref(&[0xba; 16]);
//! // Client connection.
//! let conn = quiche::connect(Some(&server_name), &scid, &mut config)?;
//!
@@ -72,7 +72,7 @@
//! # let mut buf = [0; 512];
//! # let socket = std::net::UdpSocket::bind("127.0.0.1:0").unwrap();
//! # let mut config = quiche::Config::new(quiche::PROTOCOL_VERSION)?;
-//! # let scid = [0xba; 16];
+//! # let scid = quiche::ConnectionId::from_ref(&[0xba; 16]);
//! # let mut conn = quiche::accept(&scid, None, &mut config)?;
//! loop {
//! let read = socket.recv(&mut buf).unwrap();
@@ -103,7 +103,7 @@
//! # let mut out = [0; 512];
//! # let socket = std::net::UdpSocket::bind("127.0.0.1:0").unwrap();
//! # let mut config = quiche::Config::new(quiche::PROTOCOL_VERSION)?;
-//! # let scid = [0xba; 16];
+//! # let scid = quiche::ConnectionId::from_ref(&[0xba; 16]);
//! # let mut conn = quiche::accept(&scid, None, &mut config)?;
//! loop {
//! let write = match conn.send(&mut out) {
@@ -131,7 +131,7 @@
//!
//! ```
//! # let mut config = quiche::Config::new(quiche::PROTOCOL_VERSION)?;
-//! # let scid = [0xba; 16];
+//! # let scid = quiche::ConnectionId::from_ref(&[0xba; 16]);
//! # let mut conn = quiche::accept(&scid, None, &mut config)?;
//! let timeout = conn.timeout();
//! # Ok::<(), quiche::Error>(())
@@ -146,7 +146,7 @@
//! # let mut out = [0; 512];
//! # let socket = std::net::UdpSocket::bind("127.0.0.1:0").unwrap();
//! # let mut config = quiche::Config::new(quiche::PROTOCOL_VERSION)?;
-//! # let scid = [0xba; 16];
+//! # let scid = quiche::ConnectionId::from_ref(&[0xba; 16]);
//! # let mut conn = quiche::accept(&scid, None, &mut config)?;
//! // Timeout expired, handle it.
//! conn.on_timeout();
@@ -181,7 +181,7 @@
//!
//! ```no_run
//! # let mut config = quiche::Config::new(quiche::PROTOCOL_VERSION)?;
-//! # let scid = [0xba; 16];
+//! # let scid = quiche::ConnectionId::from_ref(&[0xba; 16]);
//! # let mut conn = quiche::accept(&scid, None, &mut config)?;
//! if conn.is_established() {
//! // Handshake completed, send some data on stream 0.
@@ -200,7 +200,7 @@
//! ```no_run
//! # let mut buf = [0; 512];
//! # let mut config = quiche::Config::new(quiche::PROTOCOL_VERSION)?;
-//! # let scid = [0xba; 16];
+//! # let scid = quiche::ConnectionId::from_ref(&[0xba; 16]);
//! # let mut conn = quiche::accept(&scid, None, &mut config)?;
//! if conn.is_established() {
//! // Iterate over readable streams.
@@ -1003,13 +1003,13 @@ pub struct Connection {
///
/// ```no_run
/// # let mut config = quiche::Config::new(0xbabababa)?;
-/// # let scid = [0xba; 16];
+/// # let scid = quiche::ConnectionId::from_ref(&[0xba; 16]);
/// let conn = quiche::accept(&scid, None, &mut config)?;
/// # Ok::<(), quiche::Error>(())
/// ```
#[inline]
pub fn accept(
- scid: &[u8], odcid: Option<&[u8]>, config: &mut Config,
+ scid: &ConnectionId, odcid: Option<&ConnectionId>, config: &mut Config,
) -> Result<Pin<Box<Connection>>> {
let conn = Connection::new(scid, odcid, config, true)?;
@@ -1027,13 +1027,13 @@ pub fn accept(
/// ```no_run
/// # let mut config = quiche::Config::new(0xbabababa)?;
/// # let server_name = "quic.tech";
-/// # let scid = [0xba; 16];
+/// # let scid = quiche::ConnectionId::from_ref(&[0xba; 16]);
/// let conn = quiche::connect(Some(&server_name), &scid, &mut config)?;
/// # Ok::<(), quiche::Error>(())
/// ```
#[inline]
pub fn connect(
- server_name: Option<&str>, scid: &[u8], config: &mut Config,
+ server_name: Option<&str>, scid: &ConnectionId, config: &mut Config,
) -> Result<Pin<Box<Connection>>> {
let conn = Connection::new(scid, None, config, false)?;
@@ -1069,7 +1069,7 @@ pub fn connect(
/// ```
#[inline]
pub fn negotiate_version(
- scid: &[u8], dcid: &[u8], out: &mut [u8],
+ scid: &ConnectionId, dcid: &ConnectionId, out: &mut [u8],
) -> Result<usize> {
packet::negotiate_version(scid, dcid, out)
}
@@ -1095,12 +1095,12 @@ pub fn negotiate_version(
/// # let mut config = quiche::Config::new(0xbabababa)?;
/// # let mut buf = [0; 512];
/// # let mut out = [0; 512];
-/// # let scid = [0xba; 16];
+/// # let scid = quiche::ConnectionId::from_ref(&[0xba; 16]);
/// # let socket = std::net::UdpSocket::bind("127.0.0.1:0").unwrap();
/// # fn mint_token(hdr: &quiche::Header, src: &std::net::SocketAddr) -> Vec<u8> {
/// # vec![]
/// # }
-/// # fn validate_token<'a>(src: &std::net::SocketAddr, token: &'a [u8]) -> Option<&'a [u8]> {
+/// # fn validate_token<'a>(src: &std::net::SocketAddr, token: &'a [u8]) -> Option<quiche::ConnectionId<'a>> {
/// # None
/// # }
/// let (len, src) = socket.recv_from(&mut buf).unwrap();
@@ -1124,18 +1124,18 @@ pub fn negotiate_version(
/// // Client sent token, validate it.
/// let odcid = validate_token(&src, token);
///
-/// if odcid == None {
+/// if odcid.is_none() {
/// // Invalid address validation token.
/// return Ok(());
/// }
///
-/// let conn = quiche::accept(&scid, odcid, &mut config)?;
+/// let conn = quiche::accept(&scid, odcid.as_ref(), &mut config)?;
/// # Ok::<(), quiche::Error>(())
/// ```
#[inline]
pub fn retry(
- scid: &[u8], dcid: &[u8], new_scid: &[u8], token: &[u8], version: u32,
- out: &mut [u8],
+ scid: &ConnectionId, dcid: &ConnectionId, new_scid: &ConnectionId,
+ token: &[u8], version: u32, out: &mut [u8],
) -> Result<usize> {
packet::retry(scid, dcid, new_scid, token, version, out)
}
@@ -1189,14 +1189,15 @@ macro_rules! qlog_with {
impl Connection {
fn new(
- scid: &[u8], odcid: Option<&[u8]>, config: &mut Config, is_server: bool,
+ scid: &ConnectionId, odcid: Option<&ConnectionId>, config: &mut Config,
+ is_server: bool,
) -> Result<Pin<Box<Connection>>> {
let tls = config.tls_ctx.lock().unwrap().new_handshake()?;
Connection::with_tls(scid, odcid, config, tls, is_server)
}
fn with_tls(
- scid: &[u8], odcid: Option<&[u8]>, config: &mut Config,
+ scid: &ConnectionId, odcid: Option<&ConnectionId>, config: &mut Config,
tls: tls::Handshake, is_server: bool,
) -> Result<Pin<Box<Connection>>> {
let max_rx_data = config.local_transport_params.initial_max_data;
@@ -1445,7 +1446,7 @@ impl Connection {
/// # let mut buf = [0; 512];
/// # let socket = std::net::UdpSocket::bind("127.0.0.1:0").unwrap();
/// # let mut config = quiche::Config::new(quiche::PROTOCOL_VERSION)?;
- /// # let scid = [0xba; 16];
+ /// # let scid = quiche::ConnectionId::from_ref(&[0xba; 16]);
/// # let mut conn = quiche::accept(&scid, None, &mut config)?;
/// loop {
/// let read = socket.recv(&mut buf).unwrap();
@@ -2016,7 +2017,7 @@ impl Connection {
/// # let mut out = [0; 512];
/// # let socket = std::net::UdpSocket::bind("127.0.0.1:0").unwrap();
/// # let mut config = quiche::Config::new(quiche::PROTOCOL_VERSION)?;
- /// # let scid = [0xba; 16];
+ /// # let scid = quiche::ConnectionId::from_ref(&[0xba; 16]);
/// # let mut conn = quiche::accept(&scid, None, &mut config)?;
/// loop {
/// let write = match conn.send(&mut out) {
@@ -2864,7 +2865,7 @@ impl Connection {
/// # let mut buf = [0; 512];
/// # let socket = std::net::UdpSocket::bind("127.0.0.1:0").unwrap();
/// # let mut config = quiche::Config::new(quiche::PROTOCOL_VERSION)?;
- /// # let scid = [0xba; 16];
+ /// # let scid = quiche::ConnectionId::from_ref(&[0xba; 16]);
/// # let mut conn = quiche::accept(&scid, None, &mut config)?;
/// # let stream_id = 0;
/// while let Ok((read, fin)) = conn.stream_recv(stream_id, &mut buf) {
@@ -2969,7 +2970,7 @@ impl Connection {
/// # let mut buf = [0; 512];
/// # let socket = std::net::UdpSocket::bind("127.0.0.1:0").unwrap();
/// # let mut config = quiche::Config::new(quiche::PROTOCOL_VERSION)?;
- /// # let scid = [0xba; 16];
+ /// # let scid = quiche::ConnectionId::from_ref(&[0xba; 16]);
/// # let mut conn = quiche::accept(&scid, None, &mut config)?;
/// # let stream_id = 0;
/// conn.stream_send(stream_id, b"hello", true)?;
@@ -3248,7 +3249,7 @@ impl Connection {
/// # let mut buf = [0; 512];
/// # let socket = std::net::UdpSocket::bind("127.0.0.1:0").unwrap();
/// # let mut config = quiche::Config::new(quiche::PROTOCOL_VERSION)?;
- /// # let scid = [0xba; 16];
+ /// # let scid = quiche::ConnectionId::from_ref(&[0xba; 16]);
/// # let mut conn = quiche::accept(&scid, None, &mut config)?;
/// // Iterate over readable streams.
/// for stream_id in conn.readable() {
@@ -3282,7 +3283,7 @@ impl Connection {
/// # let mut buf = [0; 512];
/// # let socket = std::net::UdpSocket::bind("127.0.0.1:0").unwrap();
/// # let mut config = quiche::Config::new(quiche::PROTOCOL_VERSION)?;
- /// # let scid = [0xba; 16];
+ /// # let scid = quiche::ConnectionId::from_ref(&[0xba; 16]);
/// # let mut conn = quiche::accept(&scid, None, &mut config)?;
/// // Iterate over writable streams.
/// for stream_id in conn.writable() {
@@ -3322,7 +3323,7 @@ impl Connection {
/// # let mut buf = [0; 512];
/// # let socket = std::net::UdpSocket::bind("127.0.0.1:0").unwrap();
/// # let mut config = quiche::Config::new(quiche::PROTOCOL_VERSION)?;
- /// # let scid = [0xba; 16];
+ /// # let scid = quiche::ConnectionId::from_ref(&[0xba; 16]);
/// # let mut conn = quiche::accept(&scid, None, &mut config)?;
/// let mut dgram_buf = [0; 512];
/// while let Ok((len)) = conn.dgram_recv(&mut dgram_buf) {
@@ -3395,7 +3396,7 @@ impl Connection {
/// # let mut buf = [0; 512];
/// # let socket = std::net::UdpSocket::bind("127.0.0.1:0").unwrap();
/// # let mut config = quiche::Config::new(quiche::PROTOCOL_VERSION)?;
- /// # let scid = [0xba; 16];
+ /// # let scid = quiche::ConnectionId::from_ref(&[0xba; 16]);
/// # let mut conn = quiche::accept(&scid, None, &mut config)?;
/// conn.dgram_send(b"hello")?;
/// # Ok::<(), quiche::Error>(())
@@ -3429,7 +3430,7 @@ impl Connection {
/// ```no_run
/// # let socket = std::net::UdpSocket::bind("127.0.0.1:0").unwrap();
/// # let mut config = quiche::Config::new(quiche::PROTOCOL_VERSION)?;
- /// # let scid = [0xba; 16];
+ /// # let scid = quiche::ConnectionId::from_ref(&[0xba; 16]);
/// # let mut conn = quiche::accept(&scid, None, &mut config)?;
/// conn.dgram_send(b"hello")?;
/// conn.dgram_purge_outgoing(&|d: &[u8]| -> bool { d[0] == 0 });
@@ -3451,7 +3452,7 @@ impl Connection {
/// # let mut buf = [0; 512];
/// # let socket = std::net::UdpSocket::bind("127.0.0.1:0").unwrap();
/// # let mut config = quiche::Config::new(quiche::PROTOCOL_VERSION)?;
- /// # let scid = [0xba; 16];
+ /// # let scid = quiche::ConnectionId::from_ref(&[0xba; 16]);
/// # let mut conn = quiche::accept(&scid, None, &mut config)?;
/// if let Some(payload_size) = conn.dgram_max_writable_len() {
/// if payload_size > 5 {
@@ -4843,9 +4844,11 @@ pub mod testing {
pub fn with_config(config: &mut Config) -> Result<Pipe> {
let mut client_scid = [0; 16];
rand::rand_bytes(&mut client_scid[..]);
+ let client_scid = ConnectionId::from_ref(&client_scid);
let mut server_scid = [0; 16];
rand::rand_bytes(&mut server_scid[..]);
+ let server_scid = ConnectionId::from_ref(&server_scid);
Ok(Pipe {
client: connect(Some("quic.tech"), &client_scid, config)?,
@@ -4856,9 +4859,11 @@ pub mod testing {
pub fn with_client_config(client_config: &mut Config) -> Result<Pipe> {
let mut client_scid = [0; 16];
rand::rand_bytes(&mut client_scid[..]);
+ let client_scid = ConnectionId::from_ref(&client_scid);
let mut server_scid = [0; 16];
rand::rand_bytes(&mut server_scid[..]);
+ let server_scid = ConnectionId::from_ref(&server_scid);
let mut config = Config::new(crate::PROTOCOL_VERSION)?;
config.load_cert_chain_from_pem_file("examples/cert.crt")?;
@@ -4879,9 +4884,11 @@ pub mod testing {
pub fn with_server_config(server_config: &mut Config) -> Result<Pipe> {
let mut client_scid = [0; 16];
rand::rand_bytes(&mut client_scid[..]);
+ let client_scid = ConnectionId::from_ref(&client_scid);
let mut server_scid = [0; 16];
rand::rand_bytes(&mut server_scid[..]);
+ let server_scid = ConnectionId::from_ref(&server_scid);
let mut config = Config::new(crate::PROTOCOL_VERSION)?;
config.set_application_protos(b"\x06proto1\x06proto2")?;
@@ -7087,10 +7094,11 @@ mod tests {
// Server sends Retry packet.
let hdr = Header::from_slice(&mut buf[..len], MAX_CONN_ID_LEN).unwrap();
- let odcid = hdr.dcid.to_vec();
+ let odcid = hdr.dcid.clone();
let mut scid = [0; MAX_CONN_ID_LEN];
rand::rand_bytes(&mut scid[..]);
+ let scid = ConnectionId::from_ref(&scid);
let token = b"quiche test retry token";
@@ -7148,6 +7156,7 @@ mod tests {
let mut scid = [0; MAX_CONN_ID_LEN];
rand::rand_bytes(&mut scid[..]);
+ let scid = ConnectionId::from_ref(&scid);
let token = b"quiche test retry token";
@@ -7203,6 +7212,7 @@ mod tests {
let mut scid = [0; MAX_CONN_ID_LEN];
rand::rand_bytes(&mut scid[..]);
+ let scid = ConnectionId::from_ref(&scid);
let token = b"quiche test retry token";
@@ -7223,7 +7233,8 @@ mod tests {
// Server accepts connection and send first flight. But original
// destination connection ID is invalid.
- pipe.server = accept(&scid, Some(b"bogus value"), &mut config).unwrap();
+ let odcid = ConnectionId::from_ref(b"bogus value");
+ pipe.server = accept(&scid, Some(&odcid), &mut config).unwrap();
len = testing::recv_send(&mut pipe.server, &mut buf, len).unwrap();
@@ -8507,9 +8518,11 @@ mod tests {
let mut client_scid = [0; 16];
rand::rand_bytes(&mut client_scid[..]);
+ let client_scid = ConnectionId::from_ref(&client_scid);
let mut server_scid = [0; 16];
rand::rand_bytes(&mut server_scid[..]);
+ let server_scid = ConnectionId::from_ref(&server_scid);
let mut client_config = Config::new(crate::PROTOCOL_VERSION).unwrap();
client_config
diff --git a/src/packet.rs b/src/packet.rs
index 3906dbb6..83a220af 100644
--- a/src/packet.rs
+++ b/src/packet.rs
@@ -140,13 +140,13 @@ enum ConnectionIdInner<'a> {
impl<'a> ConnectionId<'a> {
/// Creates a new connection ID from the given vector.
#[inline]
- pub fn from_vec(cid: Vec<u8>) -> Self {
+ pub const fn from_vec(cid: Vec<u8>) -> Self {
Self(ConnectionIdInner::Vec(cid))
}
/// Creates a new connection ID from the given slice.
#[inline]
- pub fn from_ref(cid: &'a [u8]) -> Self {
+ pub const fn from_ref(cid: &'a [u8]) -> Self {
Self(ConnectionIdInner::Ref(cid))
}
}