mirror of
https://git.proxmox.com/git/proxmox
synced 2025-05-29 20:30:37 +00:00
uuid: rustfmt
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
d3b387f1a7
commit
800cf63a8a
@ -3,14 +3,14 @@
|
|||||||
use std::borrow::{Borrow, BorrowMut};
|
use std::borrow::{Borrow, BorrowMut};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
#[cfg(not(target_arch="wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
mod lib_uuid_bindings;
|
mod lib_uuid_bindings;
|
||||||
#[cfg(not(target_arch="wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
use lib_uuid_bindings::*;
|
use lib_uuid_bindings::*;
|
||||||
|
|
||||||
#[cfg(target_arch="wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
mod wasm;
|
mod wasm;
|
||||||
#[cfg(target_arch="wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
pub use wasm::*;
|
pub use wasm::*;
|
||||||
|
|
||||||
/// An error parsing a uuid from a string.
|
/// An error parsing a uuid from a string.
|
||||||
|
@ -3,7 +3,6 @@ use std::fmt;
|
|||||||
use crate::Uuid;
|
use crate::Uuid;
|
||||||
|
|
||||||
pub fn uuid_generate(out: *mut [u8; 16]) {
|
pub fn uuid_generate(out: *mut [u8; 16]) {
|
||||||
|
|
||||||
// TODO: implement soemthing better than this
|
// TODO: implement soemthing better than this
|
||||||
|
|
||||||
let time = js_sys::Date::now() as u64;
|
let time = js_sys::Date::now() as u64;
|
||||||
@ -28,12 +27,14 @@ pub fn uuid_generate(out: *mut [u8; 16]) {
|
|||||||
bytes3[0..8].copy_from_slice(&time.to_le_bytes());
|
bytes3[0..8].copy_from_slice(&time.to_le_bytes());
|
||||||
bytes3[8..16].copy_from_slice(&time.to_le_bytes());
|
bytes3[8..16].copy_from_slice(&time.to_le_bytes());
|
||||||
|
|
||||||
if out.is_null() { return; }
|
if out.is_null() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let out = unsafe { out.as_mut().unwrap() };
|
let out = unsafe { out.as_mut().unwrap() };
|
||||||
|
|
||||||
for i in 0..16 {
|
for i in 0..16 {
|
||||||
let v = bytes1[i] ^ bytes2[i] ^ bytes3[i];
|
let v = bytes1[i] ^ bytes2[i] ^ bytes3[i];
|
||||||
out[i] = v;
|
out[i] = v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -42,12 +43,10 @@ pub fn uuid_generate(out: *mut [u8; 16]) {
|
|||||||
// adopted types to our needs
|
// adopted types to our needs
|
||||||
|
|
||||||
const UPPER: [u8; 16] = [
|
const UPPER: [u8; 16] = [
|
||||||
b'0', b'1', b'2', b'3', b'4', b'5', b'6', b'7', b'8', b'9', b'A', b'B',
|
b'0', b'1', b'2', b'3', b'4', b'5', b'6', b'7', b'8', b'9', b'A', b'B', b'C', b'D', b'E', b'F',
|
||||||
b'C', b'D', b'E', b'F',
|
|
||||||
];
|
];
|
||||||
const LOWER: [u8; 16] = [
|
const LOWER: [u8; 16] = [
|
||||||
b'0', b'1', b'2', b'3', b'4', b'5', b'6', b'7', b'8', b'9', b'a', b'b',
|
b'0', b'1', b'2', b'3', b'4', b'5', b'6', b'7', b'8', b'9', b'a', b'b', b'c', b'd', b'e', b'f',
|
||||||
b'c', b'd', b'e', b'f',
|
|
||||||
];
|
];
|
||||||
/// The segments of a UUID's [u8; 16] corresponding to each group.
|
/// The segments of a UUID's [u8; 16] corresponding to each group.
|
||||||
const BYTE_POSITIONS: [usize; 6] = [0, 4, 6, 8, 10, 16];
|
const BYTE_POSITIONS: [usize; 6] = [0, 4, 6, 8, 10, 16];
|
||||||
@ -55,10 +54,7 @@ const BYTE_POSITIONS: [usize; 6] = [0, 4, 6, 8, 10, 16];
|
|||||||
/// group.
|
/// group.
|
||||||
const HYPHEN_POSITIONS: [usize; 4] = [8, 13, 18, 23];
|
const HYPHEN_POSITIONS: [usize; 4] = [8, 13, 18, 23];
|
||||||
|
|
||||||
pub fn uuid_encode(
|
pub fn uuid_encode(uuid: &[u8; 16], upper: bool) -> String {
|
||||||
uuid: &[u8; 16],
|
|
||||||
upper: bool,
|
|
||||||
) -> String {
|
|
||||||
let mut buffer = [0u8; 36];
|
let mut buffer = [0u8; 36];
|
||||||
|
|
||||||
let hex = if upper { &UPPER } else { &LOWER };
|
let hex = if upper { &UPPER } else { &LOWER };
|
||||||
|
Loading…
Reference in New Issue
Block a user