Skip to content

Commit a9b9532

Browse files
committed
RUST-942 Properly generate 5 random bytes instead of 3 for ObjectIds
1 parent e81ffef commit a9b9532

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/oid.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ impl ObjectId {
148148
hex::encode(self.id)
149149
}
150150

151-
// Generates a new timestamp representing the current seconds since epoch.
152-
// Represented in Big Endian.
151+
/// Generates a new timestamp representing the current seconds since epoch.
152+
/// Represented in Big Endian.
153153
fn gen_timestamp() -> [u8; 4] {
154154
let timestamp: u32 = SystemTime::now()
155155
.duration_since(SystemTime::UNIX_EPOCH)
@@ -160,22 +160,17 @@ impl ObjectId {
160160
timestamp.to_be_bytes()
161161
}
162162

163-
// Generate a random 5-byte array.
163+
/// Generate a random 5-byte array.
164164
fn gen_process_id() -> [u8; 5] {
165165
lazy_static! {
166-
static ref BUF: [u8; 5] = {
167-
let rng = thread_rng().gen_range(0, MAX_U24) as u32;
168-
let mut buf: [u8; 5] = [0; 5];
169-
buf[0..4].copy_from_slice(&rng.to_be_bytes());
170-
buf
171-
};
166+
static ref BUF: [u8; 5] = thread_rng().gen();
172167
}
173168

174169
*BUF
175170
}
176171

177-
// Gets an incremental 3-byte count.
178-
// Represented in Big Endian.
172+
/// Gets an incremental 3-byte count.
173+
/// Represented in Big Endian.
179174
fn gen_count() -> [u8; 3] {
180175
let u_counter = OID_COUNTER.fetch_add(1, Ordering::SeqCst);
181176

0 commit comments

Comments
 (0)