pub enum Connection {
Client(ClientConnection),
Server(ServerConnection),
}展开描述
客户端或服务器连接。
变体§
实现§
Source§impl Connection
impl Connection
Sourcepub fn read_tls(&mut self, rd: &mut dyn Read) -> Result<usize, Error>
pub fn read_tls(&mut self, rd: &mut dyn Read) -> Result<usize, Error>
从以下来源读取 TLS 内容 rd。
,请参见ConnectionCommon::read_tls() 以获取更多信息。
Sourcepub fn write_tls(&mut self, wr: &mut dyn Write) -> Result<usize, Error>
pub fn write_tls(&mut self, wr: &mut dyn Write) -> Result<usize, Error>
将 TLS 消息写入 wr。
,请参见ConnectionCommon::write_tls() 以获取更多信息。
Sourcepub fn process_new_packets(&mut self) -> Result<IoState, Error>
pub fn process_new_packets(&mut self) -> Result<IoState, Error>
处理先前调用以下方法读取的所有新数据包: Connection::read_tls。
,请参见ConnectionCommon::process_new_packets() 以获取更多信息。
Sourcepub fn export_keying_material<T: AsMut<[u8]>>(
&self,
output: T,
label: &[u8],
context: Option<&[u8]>,
) -> Result<T, Error>
pub fn export_keying_material<T: AsMut<[u8]>>( &self, output: T, label: &[u8], context: Option<&[u8]>, ) -> Result<T, Error>
从已协商的连接密钥派生密钥材料。
,请参见ConnectionCommon::export_keying_material() 以获取更多信息。
Sourcepub fn complete_io<T>(&mut self, io: &mut T) -> Result<(usize, usize), Error>
pub fn complete_io<T>(&mut self, io: &mut T) -> Result<(usize, usize), Error>
This function uses io 到 complete any outstanding IO 用于 this connection.
,请参见ConnectionCommon::complete_io() 以获取更多信息。
Sourcepub fn dangerous_extract_secrets(self) -> Result<ExtractedSecrets, Error>
pub fn dangerous_extract_secrets(self) -> Result<ExtractedSecrets, Error>
提取密钥,以便在配置 kTLS 时使用,例如。 Should be 用 with care as it exposes secret 密钥材料。
Sourcepub fn set_buffer_limit(&mut self, limit: Option<usize>)
pub fn set_buffer_limit(&mut self, limit: Option<usize>)
设置内部缓冲区的限制
,请参见ConnectionCommon::set_buffer_limit() 以获取更多信息。
Sourcepub fn refresh_traffic_keys(&mut self) -> Result<(), Error>
pub fn refresh_traffic_keys(&mut self) -> Result<(), Error>
Sends 一个 TLS 1.3 key_update message 到 refresh 一个 connection’s keys
,请参见ConnectionCommon::refresh_traffic_keys() 以获取更多信息。
Methods from Deref<Target = CommonState>§
Sourcepub fn wants_write(&self) -> bool
pub fn wants_write(&self) -> bool
如果调用者应尽快调用以下方法,则返回 true: Connection::write_tls 尽快。
Sourcepub fn is_handshaking(&self) -> bool
pub fn is_handshaking(&self) -> bool
如果连接当前正在执行 TLS 握手,则返回 true。
During this time 明文 written 到 the connection is buffered in memory. After
Connection::process_new_packets() has been called, this might start 到 return false
while the final handshake packets still need 到 be extracted 从 the connection’s buffers.
Sourcepub fn peer_certificates(&self) -> Option<&[CertificateDer<'static>]>
pub fn peer_certificates(&self) -> Option<&[CertificateDer<'static>]>
检索对等方用于身份验证的证书链或原始公钥。
此 order of 证书 chain is as it appears in the TLS protocol: the first certificate relates 到 the peer, the second certifies the first, the third certifies the second, 并 so on.
When using raw public keys, the first 并 only element 是 raw 公钥.
This is made available 用于 both full 并 resumed handshakes.
For clients, this 是 certificate chain 或 the raw 公钥 of the server.
For servers, this 是 certificate chain 或 the raw 公钥 of the client, if client authentication was completed.
此 return value is None until this value is available.
Note: the return type of the ‘certificate’, when using raw public keys is CertificateDer<'static>
even though this should technically be 一个 SubjectPublicKeyInfoDer<'static>。
This choice simplifies the API 并 ensures backwards compatibility.
Sourcepub fn alpn_protocol(&self) -> Option<&[u8]>
pub fn alpn_protocol(&self) -> Option<&[u8]>
检索通过 ALPN 与对等方协商的协议。
A return value of None after handshake completion
means no protocol was agreed (because no protocols
were offered 或 已接受 by the peer)。
Sourcepub fn negotiated_cipher_suite(&self) -> Option<SupportedCipherSuite>
pub fn negotiated_cipher_suite(&self) -> Option<SupportedCipherSuite>
检索与对等方协商的密码套件。
在密码套件协商一致之前返回 None。
Sourcepub fn negotiated_key_exchange_group(
&self,
) -> Option<&'static dyn SupportedKxGroup>
pub fn negotiated_key_exchange_group( &self, ) -> Option<&'static dyn SupportedKxGroup>
检索与对等方协商的密钥交换组。
This function may return None depending on the state of the connection,
the type of handshake, 并 the protocol version.
If CommonState::is_handshaking() 为 true,此函数将返回 None。
Similarly, if the CommonState::handshake_kind() is HandshakeKind::Resumed
并 the CommonState::protocol_version() is TLS 1.2, then no key exchange will have
occurred 并 此函数将返回 None。
Sourcepub fn protocol_version(&self) -> Option<ProtocolVersion>
pub fn protocol_version(&self) -> Option<ProtocolVersion>
检索与对等方协商的协议版本。
This returns None until the version is agreed.
Sourcepub fn handshake_kind(&self) -> Option<HandshakeKind>
pub fn handshake_kind(&self) -> Option<HandshakeKind>
执行的握手类型。
它会告知握手是否为恢复握手。
This 将返回 None before it is known which sort of
handshake occurred.
Sourcepub fn send_close_notify(&mut self)
pub fn send_close_notify(&mut self)
Queues 一个 close_notify warning alert 到 be sent in the next
Connection::write_tls 调用。 This informs the peer that the
connection is being closed.
Does nothing if any close_notify 或 fatal alert was already sent.
Sourcepub fn wants_read(&self) -> bool
pub fn wants_read(&self) -> bool
如果调用者应尽快调用以下方法,则返回 true: Connection::read_tls as soon
as possible.
如果有要读取的待处理明文数据,请使用 Connection::reader,
this returns false. If your application respects this mechanism,
only one full TLS message , buffered by rustls.