Skip to content

Commit

Permalink
Renet/Netcode: make generate_random_bytes public
Browse files Browse the repository at this point in the history
This can be used to generate a random private key
  • Loading branch information
lucaspoffo committed Aug 3, 2022
1 parent bb890e8 commit f8509f1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion renet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod server;
pub use rechannel::channel::{BlockChannelConfig, ChannelConfig, ReliableChannelConfig, UnreliableChannelConfig};
pub use rechannel::error::{ChannelError, DisconnectionReason, RechannelError};

pub use renetcode::{ConnectToken, NetcodeError};
pub use renetcode::{ConnectToken, NetcodeError, generate_random_bytes};
pub use renetcode::{NETCODE_KEY_BYTES, NETCODE_USER_DATA_BYTES};

pub use client::{ClientAuthentication, RenetClient};
Expand Down
4 changes: 4 additions & 0 deletions renetcode/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ pub fn encrypt_in_place_xnonce(buffer: &mut [u8], xnonce: &[u8; 24], key: &[u8;
Ok(())
}

/// Generate a buffer with random bytes using randomness from the operating system.
///
/// The implementation is provided by the [getrandom] crate. Refer to
/// [getrandom] documentation for details.
pub fn generate_random_bytes<const N: usize>() -> [u8; N] {
let mut bytes = [0; N];
OsRng.fill_bytes(&mut bytes);
Expand Down
1 change: 1 addition & 0 deletions renetcode/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub use client::{DisconnectReason, NetcodeClient};
pub use error::NetcodeError;
pub use server::{NetcodeServer, ServerResult};
pub use token::{ConnectToken, TokenGenerationError};
pub use crypto::generate_random_bytes;

use std::time::Duration;

Expand Down

0 comments on commit f8509f1

Please sign in to comment.