From 1477035afdb3a152ea9146feaef8add8291035d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Sat, 18 Jun 2022 19:44:09 +0000 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. --- 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`