From b828560908c3b2f6aded011e9c01a22f222a80b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Mon, 11 May 2020 17:55:37 +0000 Subject: [PATCH] crypto: allow KeyObjects in postMessage This change allows sharing KeyObjects between threads via postMessage. The receiver acquires a new KeyObject and a new KeyObjectHandle, but refers to the same KeyObjectData: +-------------------+ | NativeKeyObject 1 | ------------------------------------------+ +-------------------+ | ^ | extends | | | +-------------------+ +-------------------+ | | KeyObject 1 (JS) | -> | KeyObjectHandle 1 | --------------+ | +-------------------+ +-------------------+ | | | | | | | | | | | | +-------------------+ | | | NativeKeyObject 2 | ------------------------------------+ | | +-------------------+ | | | ^ | | | extends | | | | | | | +-------------------+ +-------------------+ | | | | KeyObject 2 (JS) | -> | KeyObjectHandle 2 | --------+ | | | +-------------------+ +-------------------+ | | | | | | | | | | | | | | | | | | | | | | | | +-------------------+ | | | | | NativeKeyObject 3 | ------------------------------+ | | | | +-------------------+ | | | | | ^ | | | | | extends | | | | | | v v v v v +-------------------+ +-------------------+ +---------------+ | KeyObject 3 (JS) | -> | KeyObjectHandle 3 | -> | KeyObjectData | +-------------------+ +-------------------+ +---------------+ Co-authored-by: Anna Henningsen PR-URL: https://github.com/nodejs/node/pull/33360 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell --- doc/api/crypto.md | 9 ++ doc/api/worker_threads.md | 8 +- lib/internal/crypto/keys.js | 13 +- src/env.h | 3 + src/node_crypto.cc | 117 +++++++++++++----- src/node_crypto.h | 67 ++++++++-- .../test-crypto-key-objects-messageport.js | 87 +++++++++++++ 7 files changed, 252 insertions(+), 52 deletions(-) create mode 100644 test/parallel/test-crypto-key-objects-messageport.js diff --git a/doc/api/crypto.md b/doc/api/crypto.md index 4ec5036b6b54a3..ca6abdb988255d 100644 --- a/doc/api/crypto.md +++ b/doc/api/crypto.md @@ -1215,6 +1215,10 @@ This can be called many times with new data as it is streamed.