diff --git a/src/crypto/README.md b/src/crypto/README.md index 58ba74c891398d..047972525743ee 100644 --- a/src/crypto/README.md +++ b/src/crypto/README.md @@ -113,12 +113,15 @@ the `ByteSource::Builder` without releasing it as a `ByteSource`. ### `ArrayBufferOrViewContents` -The `ArrayBufferOfViewContents` class is a helper utility that abstracts +The `ArrayBufferOrViewContents` class is a helper utility that abstracts `ArrayBuffer`, `TypedArray`, or `DataView` inputs and provides access to their underlying data pointers. It is used extensively through `src/crypto` to make it easier to deal with inputs that allow any `ArrayBuffer`-backed object. +The lifetime of `ArrayBufferOrViewContents` should not exceed the +lifetime of its input. + ### Key objects Most crypto operations involve the use of keys -- cryptographic inputs diff --git a/src/crypto/crypto_util.h b/src/crypto/crypto_util.h index 9e33b3777b00d7..a7ea69cb27ea6d 100644 --- a/src/crypto/crypto_util.h +++ b/src/crypto/crypto_util.h @@ -703,17 +703,17 @@ class ArrayBufferOrViewContents { auto view = buf.As(); offset_ = view->ByteOffset(); length_ = view->ByteLength(); - store_ = view->Buffer()->GetBackingStore(); + data_ = view->Buffer()->Data(); } else if (buf->IsArrayBuffer()) { auto ab = buf.As(); offset_ = 0; length_ = ab->ByteLength(); - store_ = ab->GetBackingStore(); + data_ = ab->Data(); } else { auto sab = buf.As(); offset_ = 0; length_ = sab->ByteLength(); - store_ = sab->GetBackingStore(); + data_ = sab->Data(); } } @@ -723,7 +723,7 @@ class ArrayBufferOrViewContents { // length is zero, so we have to return something. if (size() == 0) return &buf; - return reinterpret_cast(store_->Data()) + offset_; + return reinterpret_cast(data_) + offset_; } inline T* data() { @@ -732,7 +732,7 @@ class ArrayBufferOrViewContents { // length is zero, so we have to return something. if (size() == 0) return &buf; - return reinterpret_cast(store_->Data()) + offset_; + return reinterpret_cast(data_) + offset_; } inline size_t size() const { return length_; } @@ -772,7 +772,7 @@ class ArrayBufferOrViewContents { T buf = 0; size_t offset_ = 0; size_t length_ = 0; - std::shared_ptr store_; + void* data_ = 0; }; v8::MaybeLocal EncodeBignum(