Skip to content

Commit

Permalink
src: improve and update ByteSource description
Browse files Browse the repository at this point in the history
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: #43478
Reviewed-By: Darshan Sen <[email protected]>
  • Loading branch information
tniessen authored Jun 25, 2022
1 parent f8bb0b1 commit c7a0b14
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/crypto/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down

0 comments on commit c7a0b14

Please sign in to comment.