diff options
6 files changed, 16 insertions, 65 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(); }; diff --git a/tests/wpt/meta-legacy-layout/WebCryptoAPI/idlharness.https.any.js.ini b/tests/wpt/meta-legacy-layout/WebCryptoAPI/idlharness.https.any.js.ini index 3808a6431c0..ed3e50ec92c 100644 --- a/tests/wpt/meta-legacy-layout/WebCryptoAPI/idlharness.https.any.js.ini +++ b/tests/wpt/meta-legacy-layout/WebCryptoAPI/idlharness.https.any.js.ini @@ -206,12 +206,6 @@ [SubtleCrypto interface: calling generateKey(AlgorithmIdentifier, boolean, sequence<KeyUsage>) on crypto.subtle with too few arguments must throw TypeError] expected: FAIL - [Crypto interface: operation randomUUID()] - expected: FAIL - - [Crypto interface: crypto must inherit property "randomUUID()" with the proper type] - expected: FAIL - [SubtleCrypto interface: operation deriveBits(AlgorithmIdentifier, CryptoKey, optional unsigned long?)] expected: FAIL @@ -430,12 +424,6 @@ [SubtleCrypto interface: calling generateKey(AlgorithmIdentifier, boolean, sequence<KeyUsage>) on crypto.subtle with too few arguments must throw TypeError] expected: FAIL - [Crypto interface: operation randomUUID()] - expected: FAIL - - [Crypto interface: crypto must inherit property "randomUUID()" with the proper type] - expected: FAIL - [SubtleCrypto interface: operation deriveBits(AlgorithmIdentifier, CryptoKey, optional unsigned long?)] expected: FAIL diff --git a/tests/wpt/meta-legacy-layout/WebCryptoAPI/randomUUID.https.any.js.ini b/tests/wpt/meta-legacy-layout/WebCryptoAPI/randomUUID.https.any.js.ini deleted file mode 100644 index 7c174d7a19e..00000000000 --- a/tests/wpt/meta-legacy-layout/WebCryptoAPI/randomUUID.https.any.js.ini +++ /dev/null @@ -1,20 +0,0 @@ -[randomUUID.https.any.html] - [namespace format] - expected: FAIL - - [version set] - expected: FAIL - - [variant set] - expected: FAIL - - -[randomUUID.https.any.worker.html] - [namespace format] - expected: FAIL - - [version set] - expected: FAIL - - [variant set] - expected: FAIL diff --git a/tests/wpt/meta/WebCryptoAPI/idlharness.https.any.js.ini b/tests/wpt/meta/WebCryptoAPI/idlharness.https.any.js.ini index 60a8a4fe5b4..a5ab0feb3ec 100644 --- a/tests/wpt/meta/WebCryptoAPI/idlharness.https.any.js.ini +++ b/tests/wpt/meta/WebCryptoAPI/idlharness.https.any.js.ini @@ -2,15 +2,9 @@ [Crypto interface: attribute subtle] expected: FAIL - [Crypto interface: operation randomUUID()] - expected: FAIL - [Crypto interface: crypto must inherit property "subtle" with the proper type] expected: FAIL - [Crypto interface: crypto must inherit property "randomUUID()" with the proper type] - expected: FAIL - [CryptoKey interface: existence and properties of interface object] expected: FAIL @@ -187,15 +181,9 @@ [Crypto interface: attribute subtle] expected: FAIL - [Crypto interface: operation randomUUID()] - expected: FAIL - [Crypto interface: crypto must inherit property "subtle" with the proper type] expected: FAIL - [Crypto interface: crypto must inherit property "randomUUID()" with the proper type] - expected: FAIL - [CryptoKey interface: existence and properties of interface object] expected: FAIL diff --git a/tests/wpt/meta/WebCryptoAPI/randomUUID.https.any.js.ini b/tests/wpt/meta/WebCryptoAPI/randomUUID.https.any.js.ini deleted file mode 100644 index 7c174d7a19e..00000000000 --- a/tests/wpt/meta/WebCryptoAPI/randomUUID.https.any.js.ini +++ /dev/null @@ -1,20 +0,0 @@ -[randomUUID.https.any.html] - [namespace format] - expected: FAIL - - [version set] - expected: FAIL - - [variant set] - expected: FAIL - - -[randomUUID.https.any.worker.html] - [namespace format] - expected: FAIL - - [version set] - expected: FAIL - - [variant set] - expected: FAIL |