From e8960370e36c92b7c6c08216e88a655fe0a10d9e Mon Sep 17 00:00:00 2001 From: James Mayclin Date: Wed, 18 Sep 2024 11:39:00 -0700 Subject: [PATCH] docs(bindings): example for Policy::from_version (#4731) --- bindings/rust/s2n-tls/src/security.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/bindings/rust/s2n-tls/src/security.rs b/bindings/rust/s2n-tls/src/security.rs index 8b23307c1cd..21e67ba4728 100644 --- a/bindings/rust/s2n-tls/src/security.rs +++ b/bindings/rust/s2n-tls/src/security.rs @@ -29,8 +29,29 @@ impl Policy { } } + /// Construct a numbered security policy. + /// + /// Numbered security policies are stable and will not change, in comparison + /// to default security policies: [DEFAULT] and [DEFAULT_TLS13]. + /// /// See the s2n-tls usage guide for details on available policies: /// + /// ``` + /// use s2n_tls::{config, security}; + /// + /// let mut config = config::Builder::new(); + /// + /// // "20240501" is a numbered security policy. More information can be found + /// // in the linked s2n-tls usage guide. + /// let security_policy = match security::Policy::from_version("20240501") { + /// Ok(policy) => policy, + /// Err(e) => { + /// eprintln!("unable to construct the policy: {}", e); + /// return; + /// } + /// }; + /// config.set_security_policy(&security_policy); + /// ``` pub fn from_version(version: &str) -> Result { let cstr = CString::new(version).map_err(|_| Error::INVALID_INPUT)?; let context = Context::Owned(cstr);