mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Implement SubtleCrypto.deriveBits
with PBDKF2 (#34164)
* Start implementing SubtleCrypto.deriveBits Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Move shared crypto operations into their own functions Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Update some doclinks Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Remove note about potential no-op It is, indeed, a no-op. Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Move normalized algorithm digest operation into its own function Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Implement mvp for pbkdf2 derivation Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Add missing division to derive bytes instead of bits The length argument specifies the number of bits that we need to derive, so we should divide it by 8 to get the number of bytes. Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Allow using PBKDF2 with usage "importKey" Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Update WPT expectations Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Fix test-tidy errors Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Fix clippy warnings Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> --------- Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
parent
c0a4eee1fe
commit
2f6ca9407b
12 changed files with 369 additions and 4447 deletions
|
@ -26,6 +26,7 @@ pub enum Handle {
|
|||
Aes128(Vec<u8>),
|
||||
Aes192(Vec<u8>),
|
||||
Aes256(Vec<u8>),
|
||||
Pbkdf2(Vec<u8>),
|
||||
}
|
||||
|
||||
/// <https://w3c.github.io/webcrypto/#cryptokey-interface>
|
||||
|
@ -114,23 +115,23 @@ impl CryptoKey {
|
|||
}
|
||||
|
||||
impl CryptoKeyMethods for CryptoKey {
|
||||
/// <https://w3c.github.io/webcrypto/#cryptokey-interface-members>
|
||||
/// <https://w3c.github.io/webcrypto/#dom-cryptokey-type>
|
||||
fn Type(&self) -> KeyType {
|
||||
self.key_type
|
||||
}
|
||||
|
||||
/// <https://w3c.github.io/webcrypto/#cryptokey-interface-members>
|
||||
/// <https://w3c.github.io/webcrypto/#dom-cryptokey-extractable>
|
||||
fn Extractable(&self) -> bool {
|
||||
self.extractable.get()
|
||||
}
|
||||
|
||||
/// <https://w3c.github.io/webcrypto/#cryptokey-interface-members>
|
||||
/// <https://w3c.github.io/webcrypto/#dom-cryptokey-algorithm>
|
||||
fn Algorithm(&self, _cx: JSContext) -> NonNull<JSObject> {
|
||||
NonNull::new(self.algorithm_object.get()).unwrap()
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
/// <https://w3c.github.io/webcrypto/#cryptokey-interface-members>
|
||||
/// <https://w3c.github.io/webcrypto/#dom-cryptokey-usages>
|
||||
fn Usages(&self, cx: JSContext) -> NonNull<JSObject> {
|
||||
unsafe {
|
||||
rooted!(in(*cx) let mut usages: Value);
|
||||
|
@ -139,3 +140,14 @@ impl CryptoKeyMethods for CryptoKey {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Handle {
|
||||
pub fn as_bytes(&self) -> &[u8] {
|
||||
match self {
|
||||
Self::Aes128(bytes) => bytes,
|
||||
Self::Aes192(bytes) => bytes,
|
||||
Self::Aes256(bytes) => bytes,
|
||||
Self::Pbkdf2(bytes) => bytes,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue