From c7a0b141b608ab47242efb106f26ac0fa32af721 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Sat, 25 Jun 2022 23:40:14 +0200 Subject: [PATCH] src: improve and update ByteSource description Clarify that external data must not be destroyed before the ByteSource that points to it, and that allocated data must have been allocated using OpenSSL's allocator (because it will be freed automatically, using OpenSSL's memory management functions). Also add a brief description of the new ByteSource::Builder class. PR-URL: https://github.com/nodejs/node/pull/43478 Reviewed-By: Darshan Sen --- src/crypto/README.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/crypto/README.md b/src/crypto/README.md index 22d4954b464ff0..58ba74c891398d 100644 --- a/src/crypto/README.md +++ b/src/crypto/README.md @@ -100,9 +100,16 @@ Examples of these being used are pervasive through the `src/crypto` code. The `ByteSource` class is a helper utility representing a _read-only_ byte array. Instances can either wrap external ("foreign") data sources, such as -an `ArrayBuffer` (`v8::BackingStore`) or allocated data. If allocated data -is used, then the allocation is freed automatically when the `ByteSource` is -destroyed. +an `ArrayBuffer` (`v8::BackingStore`), or allocated data. + +* If a pointer to external data is used to create a `ByteSource`, that pointer + must remain valid until the `ByteSource` is destroyed. +* If allocated data is used, then it must have been allocated using OpenSSL's + allocator. It will be freed automatically when the `ByteSource` is destroyed. + +The `ByteSource::Builder` class can be used to allocate writable memory that can +then be released as a `ByteSource`, making it read-only, or freed by destroying +the `ByteSource::Builder` without releasing it as a `ByteSource`. ### `ArrayBufferOrViewContents`