summaryrefslogtreecommitdiff
path: root/ext/crypto/lib.rs
diff options
context:
space:
mode:
authorLuca Casonato <hello@lcas.dev>2021-08-31 11:25:44 +0200
committerGitHub <noreply@github.com>2021-08-31 11:25:44 +0200
commitcee5be45394c77863dacbf8f1d0f0b90188d2cca (patch)
treea7f457682dc5a399641738ce903014e64c3d7b59 /ext/crypto/lib.rs
parentfcd0992dba9cce0539cc60cd11867f50c0cf5efb (diff)
feat(ext/crypto): AES key generation (#11869)
Support AES-CTR, AES-CBC, AES-GCM, and AES-KW in SubtleCrypto#generateKey.
Diffstat (limited to 'ext/crypto/lib.rs')
-rw-r--r--ext/crypto/lib.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/ext/crypto/lib.rs b/ext/crypto/lib.rs
index b68bd7887..7c4010f53 100644
--- a/ext/crypto/lib.rs
+++ b/ext/crypto/lib.rs
@@ -180,6 +180,18 @@ pub async fn op_crypto_generate_key(
private_key
}
+ Algorithm::AesCtr
+ | Algorithm::AesCbc
+ | Algorithm::AesGcm
+ | Algorithm::AesKw => {
+ let length = args.length.ok_or_else(not_supported)?;
+ let mut key_data = vec![0u8; length];
+ let rng = RingRand::SystemRandom::new();
+ rng.fill(&mut key_data).map_err(|_| {
+ custom_error("DOMExceptionOperationError", "Key generation failed")
+ })?;
+ key_data
+ }
Algorithm::Hmac => {
let hash: HmacAlgorithm = args.hash.ok_or_else(not_supported)?.into();