mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01: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::rust::CustomAutoRooterGuard;
|
||||||
use js::typedarray::{ArrayBufferView, ArrayBufferViewU8, TypedArray};
|
use js::typedarray::{ArrayBufferView, ArrayBufferViewU8, TypedArray};
|
||||||
use servo_rand::{RngCore, ServoRng};
|
use servo_rand::{RngCore, ServoRng};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::dom::bindings::cell::DomRefCell;
|
use crate::dom::bindings::cell::DomRefCell;
|
||||||
use crate::dom::bindings::codegen::Bindings::CryptoBinding::CryptoMethods;
|
use crate::dom::bindings::codegen::Bindings::CryptoBinding::CryptoMethods;
|
||||||
use crate::dom::bindings::error::{Error, Fallible};
|
use crate::dom::bindings::error::{Error, Fallible};
|
||||||
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
|
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
|
||||||
use crate::dom::bindings::root::DomRoot;
|
use crate::dom::bindings::root::DomRoot;
|
||||||
|
use crate::dom::bindings::str::USVString;
|
||||||
use crate::dom::globalscope::GlobalScope;
|
use crate::dom::globalscope::GlobalScope;
|
||||||
use crate::script_runtime::JSContext;
|
use crate::script_runtime::JSContext;
|
||||||
|
|
||||||
|
@ -40,7 +42,7 @@ impl Crypto {
|
||||||
|
|
||||||
impl CryptoMethods for Crypto {
|
impl CryptoMethods for Crypto {
|
||||||
#[allow(unsafe_code)]
|
#[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(
|
fn GetRandomValues(
|
||||||
&self,
|
&self,
|
||||||
_cx: JSContext,
|
_cx: JSContext,
|
||||||
|
@ -61,6 +63,15 @@ impl CryptoMethods for Crypto {
|
||||||
.map_err(|_| Error::JSFailed)
|
.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 {
|
fn is_integer_buffer(array_type: Type) -> bool {
|
||||||
|
|
|
@ -20,4 +20,8 @@ interface Crypto {
|
||||||
//readonly attribute SubtleCrypto subtle;
|
//readonly attribute SubtleCrypto subtle;
|
||||||
[Throws]
|
[Throws]
|
||||||
ArrayBufferView getRandomValues(ArrayBufferView array);
|
ArrayBufferView getRandomValues(ArrayBufferView array);
|
||||||
|
|
||||||
|
[SecureContext]
|
||||||
|
// UTF8String is not observably different from USVString
|
||||||
|
USVString randomUUID();
|
||||||
};
|
};
|
||||||
|
|
|
@ -206,12 +206,6 @@
|
||||||
[SubtleCrypto interface: calling generateKey(AlgorithmIdentifier, boolean, sequence<KeyUsage>) on crypto.subtle with too few arguments must throw TypeError]
|
[SubtleCrypto interface: calling generateKey(AlgorithmIdentifier, boolean, sequence<KeyUsage>) on crypto.subtle with too few arguments must throw TypeError]
|
||||||
expected: FAIL
|
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?)]
|
[SubtleCrypto interface: operation deriveBits(AlgorithmIdentifier, CryptoKey, optional unsigned long?)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
@ -430,12 +424,6 @@
|
||||||
[SubtleCrypto interface: calling generateKey(AlgorithmIdentifier, boolean, sequence<KeyUsage>) on crypto.subtle with too few arguments must throw TypeError]
|
[SubtleCrypto interface: calling generateKey(AlgorithmIdentifier, boolean, sequence<KeyUsage>) on crypto.subtle with too few arguments must throw TypeError]
|
||||||
expected: FAIL
|
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?)]
|
[SubtleCrypto interface: operation deriveBits(AlgorithmIdentifier, CryptoKey, optional unsigned long?)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -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
|
|
|
@ -2,15 +2,9 @@
|
||||||
[Crypto interface: attribute subtle]
|
[Crypto interface: attribute subtle]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[Crypto interface: operation randomUUID()]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Crypto interface: crypto must inherit property "subtle" with the proper type]
|
[Crypto interface: crypto must inherit property "subtle" with the proper type]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[Crypto interface: crypto must inherit property "randomUUID()" with the proper type]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[CryptoKey interface: existence and properties of interface object]
|
[CryptoKey interface: existence and properties of interface object]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
@ -187,15 +181,9 @@
|
||||||
[Crypto interface: attribute subtle]
|
[Crypto interface: attribute subtle]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[Crypto interface: operation randomUUID()]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Crypto interface: crypto must inherit property "subtle" with the proper type]
|
[Crypto interface: crypto must inherit property "subtle" with the proper type]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[Crypto interface: crypto must inherit property "randomUUID()" with the proper type]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[CryptoKey interface: existence and properties of interface object]
|
[CryptoKey interface: existence and properties of interface object]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -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
|
|
Loading…
Add table
Add a link
Reference in a new issue