ok/jj
1
0
Fork 0
forked from mirrors/jj

backend: reimplement random ChangeId generator without using UUID

This commit is contained in:
Yuya Nishihara 2023-01-14 12:47:24 +09:00
parent 2e075f7de0
commit 2144870e5c

View file

@ -155,13 +155,11 @@ impl UserSettings {
pub struct JJRng(Mutex<ChaCha20Rng>);
impl JJRng {
pub fn new_change_id(&self) -> ChangeId {
let random_bytes = self.gen();
// The `uuid` crate is used merely to specify the number of random bytes (16)
ChangeId::from_bytes(
uuid::Builder::from_random_bytes(random_bytes)
.into_uuid()
.as_bytes(),
)
let mut random_bytes: [u8; 16] = self.gen();
// TODO: make it fully random
random_bytes[6] = (random_bytes[6] & 0x0f) | ((4 as u8) << 4); // Version: 4
random_bytes[8] = (random_bytes[8] & 0x3f) | 0x80; // Variant::RFC4122
ChangeId::new(random_bytes.into())
}
/// Wraps Rng::gen but only requires an immutable reference. Can be made