aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/crypto.rs13
-rw-r--r--components/script/dom/webidls/Crypto.webidl4
2 files changed, 16 insertions, 1 deletions
diff --git a/components/script/dom/crypto.rs b/components/script/dom/crypto.rs
index e5c441815f0..75b3e88cad3 100644
--- a/components/script/dom/crypto.rs
+++ b/components/script/dom/crypto.rs
@@ -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 {
diff --git a/components/script/dom/webidls/Crypto.webidl b/components/script/dom/webidls/Crypto.webidl
index 8a92d425d89..84b14ff1d0c 100644
--- a/components/script/dom/webidls/Crypto.webidl
+++ b/components/script/dom/webidls/Crypto.webidl
@@ -20,4 +20,8 @@ interface Crypto {
//readonly attribute SubtleCrypto subtle;
[Throws]
ArrayBufferView getRandomValues(ArrayBufferView array);
+
+ [SecureContext]
+ // UTF8String is not observably different from USVString
+ USVString randomUUID();
};