Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: remove usages of GetBackingStore in crypto #44079

Merged
merged 2 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/crypto/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,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.
addaleax marked this conversation as resolved.
Show resolved Hide resolved

### Key objects

Most crypto operations involve the use of keys -- cryptographic inputs
Expand Down
12 changes: 6 additions & 6 deletions src/crypto/crypto_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -703,17 +703,17 @@ class ArrayBufferOrViewContents {
auto view = buf.As<v8::ArrayBufferView>();
offset_ = view->ByteOffset();
length_ = view->ByteLength();
store_ = view->Buffer()->GetBackingStore();
data_ = view->Buffer()->Data();
} else if (buf->IsArrayBuffer()) {
auto ab = buf.As<v8::ArrayBuffer>();
offset_ = 0;
length_ = ab->ByteLength();
store_ = ab->GetBackingStore();
data_ = ab->Data();
} else {
auto sab = buf.As<v8::SharedArrayBuffer>();
offset_ = 0;
length_ = sab->ByteLength();
store_ = sab->GetBackingStore();
data_ = sab->Data();
}
}

Expand All @@ -723,7 +723,7 @@ class ArrayBufferOrViewContents {
// length is zero, so we have to return something.
if (size() == 0)
return &buf;
return reinterpret_cast<T*>(store_->Data()) + offset_;
return reinterpret_cast<T*>(data_) + offset_;
}

inline T* data() {
Expand All @@ -732,7 +732,7 @@ class ArrayBufferOrViewContents {
// length is zero, so we have to return something.
if (size() == 0)
return &buf;
return reinterpret_cast<T*>(store_->Data()) + offset_;
return reinterpret_cast<T*>(data_) + offset_;
}

inline size_t size() const { return length_; }
Expand Down Expand Up @@ -772,7 +772,7 @@ class ArrayBufferOrViewContents {
T buf = 0;
size_t offset_ = 0;
size_t length_ = 0;
std::shared_ptr<v8::BackingStore> store_;
void* data_ = 0;
kvakil marked this conversation as resolved.
Show resolved Hide resolved
};

v8::MaybeLocal<v8::Value> EncodeBignum(
Expand Down