mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Implement crypto.randomUUID() (#33158)
Signed-off-by: webbeef <me@webbeef.org>
This commit is contained in:
parent
663a92a5df
commit
9a1051c917
6 changed files with 16 additions and 65 deletions
|
@ -7,12 +7,14 @@ use js::jsapi::{JSObject, Type};
|
|||
use js::rust::CustomAutoRooterGuard;
|
||||
use js::typedarray::{ArrayBufferView, ArrayBufferViewU8, TypedArray};
|
||||
use servo_rand::{RngCore, ServoRng};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::dom::bindings::cell::DomRefCell;
|
||||
use crate::dom::bindings::codegen::Bindings::CryptoBinding::CryptoMethods;
|
||||
use crate::dom::bindings::error::{Error, Fallible};
|
||||
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
|
||||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::bindings::str::USVString;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::script_runtime::JSContext;
|
||||
|
||||
|
@ -40,7 +42,7 @@ impl Crypto {
|
|||
|
||||
impl CryptoMethods for Crypto {
|
||||
#[allow(unsafe_code)]
|
||||
// https://dvcs.w3.org/hg/webcrypto-api/raw-file/tip/spec/Overview.html#Crypto-method-getRandomValues
|
||||
// https://w3c.github.io/webcrypto/#Crypto-method-getRandomValues
|
||||
fn GetRandomValues(
|
||||
&self,
|
||||
_cx: JSContext,
|
||||
|
@ -61,6 +63,15 @@ impl CryptoMethods for Crypto {
|
|||
.map_err(|_| Error::JSFailed)
|
||||
}
|
||||
}
|
||||
|
||||
// https://w3c.github.io/webcrypto/#Crypto-method-randomUUID
|
||||
fn RandomUUID(&self) -> USVString {
|
||||
let uuid = Uuid::new_v4();
|
||||
uuid.hyphenated()
|
||||
.encode_lower(&mut Uuid::encode_buffer())
|
||||
.to_owned()
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
fn is_integer_buffer(array_type: Type) -> bool {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue