build: fix doc test

This commit is contained in:
0x676e67 2025-03-21 17:56:57 +08:00
parent 6c74708e27
commit 360c3949c8
20 changed files with 62 additions and 62 deletions

View File

@ -22,7 +22,7 @@
//! //!
//! ## Key wrapping //! ## Key wrapping
//! ```rust //! ```rust
//! use boring::aes::{AesKey, unwrap_key, wrap_key}; //! use boring2::aes::{AesKey, unwrap_key, wrap_key};
//! //!
//! let kek = b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F"; //! let kek = b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F";
//! let key_to_wrap = b"\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA\xBB\xCC\xDD\xEE\xFF"; //! let key_to_wrap = b"\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA\xBB\xCC\xDD\xEE\xFF";

View File

@ -21,7 +21,7 @@
//! ## Examples //! ## Examples
//! //!
//! ``` //! ```
//! use boring::asn1::Asn1Time; //! use boring2::asn1::Asn1Time;
//! let tomorrow = Asn1Time::days_from_now(1); //! let tomorrow = Asn1Time::days_from_now(1);
//! ``` //! ```
use crate::ffi; use crate::ffi;

View File

@ -9,8 +9,8 @@
//! # Examples //! # Examples
//! //!
//! ``` //! ```
//! use boring::bn::BigNum; //! use boring2::bn::BigNum;
//! use boring::error::ErrorStack; //! use boring2::error::ErrorStack;
//! //!
//! fn main() -> Result<(), ErrorStack> { //! fn main() -> Result<(), ErrorStack> {
//! let a = BigNum::new()?; // a = 0 //! let a = BigNum::new()?; // a = 0
@ -97,8 +97,8 @@ foreign_type_and_impl_send_sync! {
/// ///
/// # Examples /// # Examples
/// ``` /// ```
/// use boring::bn::BigNum; /// use boring2::bn::BigNum;
/// # use boring::error::ErrorStack; /// # use boring2::error::ErrorStack;
/// # fn bignums() -> Result< (), ErrorStack > { /// # fn bignums() -> Result< (), ErrorStack > {
/// let little_big = BigNum::from_u32(std::u32::MAX)?; /// let little_big = BigNum::from_u32(std::u32::MAX)?;
/// assert_eq!(*&little_big.num_bytes(), 4); /// assert_eq!(*&little_big.num_bytes(), 4);
@ -271,7 +271,7 @@ impl BigNumRef {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # use boring::bn::BigNum; /// # use boring2::bn::BigNum;
/// # use std::cmp::Ordering; /// # use std::cmp::Ordering;
/// let s = -BigNum::from_u32(8).unwrap(); /// let s = -BigNum::from_u32(8).unwrap();
/// let o = BigNum::from_u32(8).unwrap(); /// let o = BigNum::from_u32(8).unwrap();
@ -311,8 +311,8 @@ impl BigNumRef {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use boring::bn::{BigNum, MsbOption}; /// use boring2::bn::{BigNum, MsbOption};
/// use boring::error::ErrorStack; /// use boring2::error::ErrorStack;
/// ///
/// fn generate_random() -> Result< BigNum, ErrorStack > { /// fn generate_random() -> Result< BigNum, ErrorStack > {
/// let mut big = BigNum::new()?; /// let mut big = BigNum::new()?;
@ -365,8 +365,8 @@ impl BigNumRef {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use boring::bn::BigNum; /// use boring2::bn::BigNum;
/// use boring::error::ErrorStack; /// use boring2::error::ErrorStack;
/// ///
/// fn generate_weak_prime() -> Result< BigNum, ErrorStack > { /// fn generate_weak_prime() -> Result< BigNum, ErrorStack > {
/// let mut big = BigNum::new()?; /// let mut big = BigNum::new()?;
@ -724,7 +724,7 @@ impl BigNumRef {
/// `self` can be recreated by using `from_slice`. /// `self` can be recreated by using `from_slice`.
/// ///
/// ``` /// ```
/// # use boring::bn::BigNum; /// # use boring2::bn::BigNum;
/// let s = -BigNum::from_u32(4543).unwrap(); /// let s = -BigNum::from_u32(4543).unwrap();
/// let r = BigNum::from_u32(4543).unwrap(); /// let r = BigNum::from_u32(4543).unwrap();
/// ///
@ -750,7 +750,7 @@ impl BigNumRef {
/// `self` can be recreated by using `from_slice`. /// `self` can be recreated by using `from_slice`.
/// ///
/// ``` /// ```
/// # use boring::bn::BigNum; /// # use boring2::bn::BigNum;
/// let bn = BigNum::from_u32(0x4543).unwrap(); /// let bn = BigNum::from_u32(0x4543).unwrap();
/// ///
/// let bn_vec = bn.to_vec_padded(4).unwrap(); /// let bn_vec = bn.to_vec_padded(4).unwrap();
@ -775,7 +775,7 @@ impl BigNumRef {
/// Returns a decimal string representation of `self`. /// Returns a decimal string representation of `self`.
/// ///
/// ``` /// ```
/// # use boring::bn::BigNum; /// # use boring2::bn::BigNum;
/// let s = -BigNum::from_u32(12345).unwrap(); /// let s = -BigNum::from_u32(12345).unwrap();
/// ///
/// assert_eq!(&**s.to_dec_str().unwrap(), "-12345"); /// assert_eq!(&**s.to_dec_str().unwrap(), "-12345");
@ -791,7 +791,7 @@ impl BigNumRef {
/// Returns a hexadecimal string representation of `self`. /// Returns a hexadecimal string representation of `self`.
/// ///
/// ``` /// ```
/// # use boring::bn::BigNum; /// # use boring2::bn::BigNum;
/// let s = -BigNum::from_u32(0x99ff).unwrap(); /// let s = -BigNum::from_u32(0x99ff).unwrap();
/// ///
/// assert_eq!(&**s.to_hex_str().unwrap(), "-99ff"); /// assert_eq!(&**s.to_hex_str().unwrap(), "-99ff");
@ -864,7 +864,7 @@ impl BigNum {
/// [`BN_bin2bn`]: https://www.openssl.org/docs/man1.1.0/crypto/BN_bin2bn.html /// [`BN_bin2bn`]: https://www.openssl.org/docs/man1.1.0/crypto/BN_bin2bn.html
/// ///
/// ``` /// ```
/// # use boring::bn::BigNum; /// # use boring2::bn::BigNum;
/// let bignum = BigNum::from_slice(&[0x12, 0x00, 0x34]).unwrap(); /// let bignum = BigNum::from_slice(&[0x12, 0x00, 0x34]).unwrap();
/// ///
/// assert_eq!(bignum, BigNum::from_u32(0x120034).unwrap()); /// assert_eq!(bignum, BigNum::from_u32(0x120034).unwrap());

View File

@ -41,9 +41,9 @@ generic_foreign_type_and_impl_send_sync! {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use boring::dsa::Dsa; /// use boring2::dsa::Dsa;
/// use boring::error::ErrorStack; /// use boring2::error::ErrorStack;
/// use boring::pkey::Private; /// use boring2::pkey::Private;
/// ///
/// fn create_dsa() -> Result<Dsa<Private>, ErrorStack> { /// fn create_dsa() -> Result<Dsa<Private>, ErrorStack> {
/// let sign = Dsa::generate(2048)?; /// let sign = Dsa::generate(2048)?;

View File

@ -602,10 +602,10 @@ impl EcKey<Public> {
/// # Example /// # Example
/// ///
/// ```no_run /// ```no_run
/// use boring::bn::BigNumContext; /// use boring2::bn::BigNumContext;
/// use boring::ec::*; /// use boring2::ec::*;
/// use boring::nid::Nid; /// use boring2::nid::Nid;
/// use boring::pkey::PKey; /// use boring2::pkey::PKey;
/// ///
/// // get bytes from somewhere, i.e. this will not produce a valid key /// // get bytes from somewhere, i.e. this will not produce a valid key
/// let public_key: Vec<u8> = vec![]; /// let public_key: Vec<u8> = vec![];

View File

@ -6,8 +6,8 @@
//! # Examples //! # Examples
//! //!
//! ``` //! ```
//! use boring::error::ErrorStack; //! use boring2::error::ErrorStack;
//! use boring::bn::BigNum; //! use boring2::bn::BigNum;
//! //!
//! let an_error = BigNum::from_dec_str("Cannot parse letters"); //! let an_error = BigNum::from_dec_str("Cannot parse letters");
//! match an_error { //! match an_error {

View File

@ -104,7 +104,7 @@ use self::State::*;
/// Calculate a hash in one go: /// Calculate a hash in one go:
/// ///
/// ``` /// ```
/// use boring::hash::{hash, MessageDigest}; /// use boring2::hash::{hash, MessageDigest};
/// ///
/// let data = b"\x42\xF4\x97\xE0"; /// let data = b"\x42\xF4\x97\xE0";
/// let spec = b"\x7c\x43\x0f\x17\x8a\xef\xdf\x14\x87\xfe\xe7\x14\x4e\x96\x41\xe2"; /// let spec = b"\x7c\x43\x0f\x17\x8a\xef\xdf\x14\x87\xfe\xe7\x14\x4e\x96\x41\xe2";
@ -115,7 +115,7 @@ use self::State::*;
/// Supply the input in chunks: /// Supply the input in chunks:
/// ///
/// ``` /// ```
/// use boring::hash::{Hasher, MessageDigest}; /// use boring2::hash::{Hasher, MessageDigest};
/// ///
/// let data = [b"\x42\xF4", b"\x97\xE0"]; /// let data = [b"\x42\xF4", b"\x97\xE0"];
/// let spec = b"\x7c\x43\x0f\x17\x8a\xef\xdf\x14\x87\xfe\xe7\x14\x4e\x96\x41\xe2"; /// let spec = b"\x7c\x43\x0f\x17\x8a\xef\xdf\x14\x87\xfe\xe7\x14\x4e\x96\x41\xe2";

View File

@ -16,7 +16,7 @@
//! values: //! values:
//! //!
//! ``` //! ```
//! use boring::memcmp::eq; //! use boring2::memcmp::eq;
//! //!
//! // We want to compare `a` to `b` and `c`, without giving //! // We want to compare `a` to `b` and `c`, without giving
//! // away through timing analysis that `c` is more similar to `a` //! // away through timing analysis that `c` is more similar to `a`
@ -48,7 +48,7 @@ use libc::size_t;
/// values: /// values:
/// ///
/// ``` /// ```
/// use boring::memcmp::eq; /// use boring2::memcmp::eq;
/// ///
/// // We want to compare `a` to `b` and `c`, without giving /// // We want to compare `a` to `b` and `c`, without giving
/// // away through timing analysis that `c` is more similar to `a` /// // away through timing analysis that `c` is more similar to `a`

View File

@ -34,7 +34,7 @@ pub struct SignatureAlgorithms {
/// To view the integer representation of a `Nid`: /// To view the integer representation of a `Nid`:
/// ///
/// ``` /// ```
/// use boring::nid::Nid; /// use boring2::nid::Nid;
/// ///
/// assert!(Nid::AES_256_GCM.as_raw() == 901); /// assert!(Nid::AES_256_GCM.as_raw() == 901);
/// ``` /// ```

View File

@ -29,8 +29,8 @@
//! Generate a 2048-bit RSA public/private key pair and print the public key. //! Generate a 2048-bit RSA public/private key pair and print the public key.
//! //!
//! ```rust //! ```rust
//! use boring::rsa::Rsa; //! use boring2::rsa::Rsa;
//! use boring::pkey::PKey; //! use boring2::pkey::PKey;
//! use std::str; //! use std::str;
//! //!
//! let rsa = Rsa::generate(2048).unwrap(); //! let rsa = Rsa::generate(2048).unwrap();

View File

@ -5,7 +5,7 @@
//! To generate a buffer with cryptographically strong bytes: //! To generate a buffer with cryptographically strong bytes:
//! //!
//! ``` //! ```
//! use boring::rand::rand_bytes; //! use boring2::rand::rand_bytes;
//! //!
//! let mut buf = [0; 256]; //! let mut buf = [0; 256];
//! rand_bytes(&mut buf).unwrap(); //! rand_bytes(&mut buf).unwrap();
@ -25,7 +25,7 @@ use crate::error::ErrorStack;
/// To generate a buffer with cryptographically strong bytes: /// To generate a buffer with cryptographically strong bytes:
/// ///
/// ``` /// ```
/// use boring::rand::rand_bytes; /// use boring2::rand::rand_bytes;
/// ///
/// let mut buf = [0; 256]; /// let mut buf = [0; 256];
/// rand_bytes(&mut buf).unwrap(); /// rand_bytes(&mut buf).unwrap();

View File

@ -16,7 +16,7 @@
//! Generate a 2048-bit RSA key pair and use the public key to encrypt some data. //! Generate a 2048-bit RSA key pair and use the public key to encrypt some data.
//! //!
//! ```rust //! ```rust
//! use boring::rsa::{Rsa, Padding}; //! use boring2::rsa::{Rsa, Padding};
//! //!
//! let rsa = Rsa::generate(2048).unwrap(); //! let rsa = Rsa::generate(2048).unwrap();
//! let data = b"foobar"; //! let data = b"foobar";

View File

@ -16,7 +16,7 @@
//! ```rust //! ```rust
//! extern crate hex; //! extern crate hex;
//! //!
//! use boring::sha; //! use boring2::sha;
//! //!
//! fn main() { //! fn main() {
//! let mut hasher = sha::Sha256::new(); //! let mut hasher = sha::Sha256::new();
@ -36,7 +36,7 @@
//! ```rust //! ```rust
//! extern crate hex; //! extern crate hex;
//! //!
//! use boring::sha::sha256; //! use boring2::sha::sha256;
//! //!
//! fn main() { //! fn main() {
//! let hash = sha256(b"your data or message"); //! let hash = sha256(b"your data or message");

View File

@ -10,10 +10,10 @@
//! Sign and verify data given an RSA keypair: //! Sign and verify data given an RSA keypair:
//! //!
//! ```rust //! ```rust
//! use boring::sign::{Signer, Verifier}; //! use boring2::sign::{Signer, Verifier};
//! use boring::rsa::Rsa; //! use boring2::rsa::Rsa;
//! use boring::pkey::PKey; //! use boring2::pkey::PKey;
//! use boring::hash::MessageDigest; //! use boring2::hash::MessageDigest;
//! //!
//! // Generate a keypair //! // Generate a keypair
//! let keypair = Rsa::generate(2048).unwrap(); //! let keypair = Rsa::generate(2048).unwrap();

View File

@ -8,7 +8,7 @@
//! To connect as a client to a remote server: //! To connect as a client to a remote server:
//! //!
//! ```no_run //! ```no_run
//! use boring::ssl::{SslMethod, SslConnector}; //! use boring2::ssl::{SslMethod, SslConnector};
//! use std::io::{Read, Write}; //! use std::io::{Read, Write};
//! use std::net::TcpStream; //! use std::net::TcpStream;
//! //!
@ -26,7 +26,7 @@
//! To accept connections as a server from remote clients: //! To accept connections as a server from remote clients:
//! //!
//! ```no_run //! ```no_run
//! use boring::ssl::{SslMethod, SslAcceptor, SslStream, SslFiletype}; //! use boring2::ssl::{SslMethod, SslAcceptor, SslStream, SslFiletype};
//! use std::net::{TcpListener, TcpStream}; //! use std::net::{TcpListener, TcpStream};
//! use std::sync::Arc; //! use std::sync::Arc;
//! use std::thread; //! use std::thread;

View File

@ -5,7 +5,7 @@
//! Encrypt data in AES128 CBC mode //! Encrypt data in AES128 CBC mode
//! //!
//! ``` //! ```
//! use boring::symm::{encrypt, Cipher}; //! use boring2::symm::{encrypt, Cipher};
//! //!
//! let cipher = Cipher::aes_128_cbc(); //! let cipher = Cipher::aes_128_cbc();
//! let data = b"Some Crypto Text"; //! let data = b"Some Crypto Text";
@ -26,8 +26,8 @@
//! Encrypting an asymmetric key with a symmetric cipher //! Encrypting an asymmetric key with a symmetric cipher
//! //!
//! ``` //! ```
//! use boring::rsa::{Padding, Rsa}; //! use boring2::rsa::{Padding, Rsa};
//! use boring::symm::Cipher; //! use boring2::symm::Cipher;
//! //!
//! // Generate keypair and encrypt private key: //! // Generate keypair and encrypt private key:
//! let keypair = Rsa::generate(2048).unwrap(); //! let keypair = Rsa::generate(2048).unwrap();
@ -226,7 +226,7 @@ unsafe impl Send for Cipher {}
/// CBC mode. /// CBC mode.
/// ///
/// ``` /// ```
/// use boring::symm::{Cipher, Mode, Crypter}; /// use boring2::symm::{Cipher, Mode, Crypter};
/// ///
/// let plaintexts: [&[u8]; 2] = [b"Some Stream of", b" Crypto Text"]; /// let plaintexts: [&[u8]; 2] = [b"Some Stream of", b" Crypto Text"];
/// let key = b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F"; /// let key = b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F";
@ -550,7 +550,7 @@ impl Drop for Crypter {
/// Encrypt data in AES128 CBC mode /// Encrypt data in AES128 CBC mode
/// ///
/// ``` /// ```
/// use boring::symm::{encrypt, Cipher}; /// use boring2::symm::{encrypt, Cipher};
/// ///
/// let cipher = Cipher::aes_128_cbc(); /// let cipher = Cipher::aes_128_cbc();
/// let data = b"Some Crypto Text"; /// let data = b"Some Crypto Text";
@ -589,7 +589,7 @@ pub fn encrypt(
/// Decrypt data in AES128 CBC mode /// Decrypt data in AES128 CBC mode
/// ///
/// ``` /// ```
/// use boring::symm::{decrypt, Cipher}; /// use boring2::symm::{decrypt, Cipher};
/// ///
/// let cipher = Cipher::aes_128_cbc(); /// let cipher = Cipher::aes_128_cbc();
/// let data = b"\xB4\xB9\xE7\x30\xD6\xD6\xF7\xDE\x77\x3F\x1C\xFF\xB3\x3E\x44\x5A\x91\xD7\x27\x62\ /// let data = b"\xB4\xB9\xE7\x30\xD6\xD6\xF7\xDE\x77\x3F\x1C\xFF\xB3\x3E\x44\x5A\x91\xD7\x27\x62\

View File

@ -8,8 +8,8 @@
//! # Example //! # Example
//! //!
//! ```rust //! ```rust
//! use boring::x509::extension::BasicConstraints; //! use boring2::x509::extension::BasicConstraints;
//! use boring::x509::X509Extension; //! use boring2::x509::X509Extension;
//! //!
//! let mut bc = BasicConstraints::new(); //! let mut bc = BasicConstraints::new();
//! let bc = bc.critical().ca().pathlen(1); //! let bc = bc.critical().ca().pathlen(1);

View File

@ -275,16 +275,16 @@ impl X509Builder {
/// The `CN` field is used for the common name, such as a DNS name. /// The `CN` field is used for the common name, such as a DNS name.
/// ///
/// ``` /// ```
/// use boring::x509::{X509, X509NameBuilder}; /// use boring2::x509::{X509, X509NameBuilder};
/// ///
/// let mut x509_name = boring::x509::X509NameBuilder::new().unwrap(); /// let mut x509_name = boring2::x509::X509NameBuilder::new().unwrap();
/// x509_name.append_entry_by_text("C", "US").unwrap(); /// x509_name.append_entry_by_text("C", "US").unwrap();
/// x509_name.append_entry_by_text("ST", "CA").unwrap(); /// x509_name.append_entry_by_text("ST", "CA").unwrap();
/// x509_name.append_entry_by_text("O", "Some organization").unwrap(); /// x509_name.append_entry_by_text("O", "Some organization").unwrap();
/// x509_name.append_entry_by_text("CN", "www.example.com").unwrap(); /// x509_name.append_entry_by_text("CN", "www.example.com").unwrap();
/// let x509_name = x509_name.build(); /// let x509_name = x509_name.build();
/// ///
/// let mut x509 = boring::x509::X509::builder().unwrap(); /// let mut x509 = boring2::x509::X509::builder().unwrap();
/// x509.set_subject_name(&x509_name).unwrap(); /// x509.set_subject_name(&x509_name).unwrap();
/// ``` /// ```
#[corresponds(X509_set_subject_name)] #[corresponds(X509_set_subject_name)]

View File

@ -6,13 +6,13 @@
//! # Example //! # Example
//! //!
//! ```rust //! ```rust
//! use boring::x509::store::{X509StoreBuilder, X509Store}; //! use boring2::x509::store::{X509StoreBuilder, X509Store};
//! use boring::x509::{X509, X509Name}; //! use boring2::x509::{X509, X509Name};
//! use boring::asn1::Asn1Time; //! use boring2::asn1::Asn1Time;
//! use boring::pkey::PKey; //! use boring2::pkey::PKey;
//! use boring::hash::MessageDigest; //! use boring2::hash::MessageDigest;
//! use boring::rsa::Rsa; //! use boring2::rsa::Rsa;
//! use boring::nid::Nid; //! use boring2::nid::Nid;
//! //!
//! let rsa = Rsa::generate(2048).unwrap(); //! let rsa = Rsa::generate(2048).unwrap();
//! let pkey = PKey::from_rsa(rsa).unwrap(); //! let pkey = PKey::from_rsa(rsa).unwrap();

View File

@ -25,7 +25,7 @@ async fn main() -> anyhow::Result<()> {
let (tcp_stream, _addr) = listener.accept().await?; let (tcp_stream, _addr) = listener.accept().await?;
let server = ssl::SslMethod::tls_server(); let server = ssl::SslMethod::tls_server();
let mut ssl_builder = boring::ssl::SslAcceptor::mozilla_modern(server)?; let mut ssl_builder = boring2::ssl::SslAcceptor::mozilla_modern(server)?;
ssl_builder.set_default_verify_paths()?; ssl_builder.set_default_verify_paths()?;
ssl_builder.set_verify(ssl::SslVerifyMode::PEER); ssl_builder.set_verify(ssl::SslVerifyMode::PEER);
let acceptor = ssl_builder.build(); let acceptor = ssl_builder.build();