Commit 782ad5d

Browse files
panvaaduh95
authored andcommitted
src: implement MemoryRetainer protocol for ByteSource
Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: #64660 Backport-PR-URL: #65087 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 4afc15b commit 782ad5d

32 files changed

Lines changed: 135 additions & 201 deletions

β€Žsrc/crypto/crypto_aes.ccβ€Ž

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,7 @@ void UseDefaultIV(AESCipherConfig* params) {
491491
} // namespace
492492

493493
AESCipherConfig::AESCipherConfig(AESCipherConfig&& other) noexcept
494-
: mode(other.mode),
495-
variant(other.variant),
494+
: variant(other.variant),
496495
cipher(other.cipher),
497496
length(other.length),
498497
iv(std::move(other.iv)),
@@ -505,12 +504,8 @@ AESCipherConfig& AESCipherConfig::operator=(AESCipherConfig&& other) noexcept {
505504
}
506505

507506
voidAESCipherConfig::MemoryInfo(MemoryTracker* tracker) const {
508-
// If mode is sync, then the data in each of these properties
509-
// is not owned by the AESCipherConfig, so we ignore it.
510-
if (IsCryptoJobAsync(mode)) {
511-
tracker->TrackFieldWithSize("iv", iv.size());
512-
tracker->TrackFieldWithSize("additional_data", additional_data.size());
513-
}
507+
tracker->TraitTrackInline(iv, "iv");
508+
tracker->TraitTrackInline(additional_data, "additional_data");
514509
}
515510

516511
Maybe<void> AESCipherTraits::AdditionalConfig(
@@ -521,8 +516,6 @@ Maybe<void> AESCipherTraits::AdditionalConfig(
521516
AESCipherConfig* params) {
522517
Environment* env = Environment::GetCurrent(args);
523518

524-
params->mode = mode;
525-
526519
CHECK(args[offset]->IsUint32()); // Key Variant
527520
params->variant =
528521
static_cast<AESKeyVariant>(args[offset].As<Uint32>()->Value());

β€Žsrc/crypto/crypto_aes.hβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ enum class AESKeyVariant {
5858
};
5959

6060
structAESCipherConfigfinal : public MemoryRetainer {
61-
CryptoJobMode mode;
6261
AESKeyVariant variant;
6362
ncrypto::Cipher cipher;
6463
size_t length;

β€Žsrc/crypto/crypto_argon2.ccβ€Ž

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ using v8::Uint32;
2121
using v8::Value;
2222

2323
Argon2Config::Argon2Config(Argon2Config&& other) noexcept
24-
: mode{other.mode},
25-
key{std::move(other.key)},
24+
: key{std::move(other.key)},
2625
pass{std::move(other.pass)},
2726
salt{std::move(other.salt)},
2827
secret{std::move(other.secret)},
@@ -40,13 +39,13 @@ Argon2Config& Argon2Config::operator=(Argon2Config&& other) noexcept {
4039
}
4140

4241
voidArgon2Config::MemoryInfo(MemoryTracker* tracker) const {
43-
if (key) tracker->TrackField("key", key);
44-
if (IsCryptoJobAsync(mode)) {
45-
if (!key) tracker->TrackFieldWithSize("pass", pass.size());
46-
tracker->TrackFieldWithSize("salt", salt.size());
47-
tracker->TrackFieldWithSize("secret", secret.size());
48-
tracker->TrackFieldWithSize("ad", ad.size());
49-
}
42+
if (key)
43+
tracker->TrackField("key", key);
44+
else
45+
tracker->TraitTrackInline(pass, "pass");
46+
tracker->TraitTrackInline(salt, "salt");
47+
tracker->TraitTrackInline(secret, "secret");
48+
tracker->TraitTrackInline(ad, "ad");
5049
}
5150

5251
MaybeLocal<Value> Argon2Traits::EncodeOutput(Environment* env,
@@ -62,8 +61,6 @@ Maybe<void> Argon2Traits::AdditionalConfig(
6261
Argon2Config* config) {
6362
Environment* env = Environment::GetCurrent(args);
6463

65-
config->mode = mode;
66-
6764
CHECK(KeyObjectHandle::HasInstance(env, args[offset]) ||
6865
IsAnyBufferSource(args[offset])); // pass
6966
ArrayBufferOrViewContents<char> salt(args[offset + 1]);

β€Žsrc/crypto/crypto_argon2.hβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ namespace node::crypto {
2222
// at least 16 bytes in length.
2323

2424
structArgon2Configfinal : public MemoryRetainer {
25-
CryptoJobMode mode;
2625
KeyObjectData key;
2726
ByteSource pass;
2827
ByteSource salt;

β€Žsrc/crypto/crypto_chacha20_poly1305.ccβ€Ž

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ bool ValidateAdditionalData(Environment* env,
8181

8282
ChaCha20Poly1305CipherConfig::ChaCha20Poly1305CipherConfig(
8383
ChaCha20Poly1305CipherConfig&& other) noexcept
84-
: mode(other.mode),
85-
cipher(other.cipher),
84+
: cipher(other.cipher),
8685
iv(std::move(other.iv)),
8786
additional_data(std::move(other.additional_data)) {}
8887

@@ -94,12 +93,8 @@ ChaCha20Poly1305CipherConfig& ChaCha20Poly1305CipherConfig::operator=(
9493
}
9594

9695
voidChaCha20Poly1305CipherConfig::MemoryInfo(MemoryTracker* tracker) const {
97-
// If mode is sync, then the data in each of these properties
98-
// is not owned by the ChaCha20Poly1305CipherConfig, so we ignore it.
99-
if (IsCryptoJobAsync(mode)) {
100-
tracker->TrackFieldWithSize("iv", iv.size());
101-
tracker->TrackFieldWithSize("additional_data", additional_data.size());
102-
}
96+
tracker->TraitTrackInline(iv, "iv");
97+
tracker->TraitTrackInline(additional_data, "additional_data");
10398
}
10499

105100
Maybe<void> ChaCha20Poly1305CipherTraits::AdditionalConfig(
@@ -110,7 +105,6 @@ Maybe<void> ChaCha20Poly1305CipherTraits::AdditionalConfig(
110105
ChaCha20Poly1305CipherConfig* params) {
111106
Environment* env = Environment::GetCurrent(args);
112107

113-
params->mode = mode;
114108
params->cipher = ncrypto::Cipher::CHACHA20_POLY1305;
115109

116110
#ifndef OPENSSL_IS_BORINGSSL

β€Žsrc/crypto/crypto_chacha20_poly1305.hβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ namespace node::crypto {
1313
constexprunsignedkChaCha20Poly1305AuthTagLength = 16;
1414

1515
structChaCha20Poly1305CipherConfigfinal : public MemoryRetainer {
16-
CryptoJobMode mode;
1716
ncrypto::Cipher cipher;
1817
ByteSource iv;
1918
ByteSource additional_data;

β€Žsrc/crypto/crypto_cipher.hβ€Ž

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,8 @@ class CipherJob final : public CryptoJob<CipherTraits> {
268268

269269
SET_SELF_SIZE(CipherJob)
270270
void MemoryInfo(MemoryTracker* tracker) constoverride {
271-
if (IsCryptoJobAsync(CryptoJob<CipherTraits>::mode()))
272-
tracker->TrackFieldWithSize("in", in_.size());
273-
tracker->TrackFieldWithSize("out", out_.size());
271+
tracker->TraitTrackInline(in_, "in");
272+
tracker->TraitTrackInline(out_, "out");
274273
CryptoJob<CipherTraits>::MemoryInfo(tracker);
275274
}
276275

β€Žsrc/crypto/crypto_hash.ccβ€Ž

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Hash::Hash(Environment* env, Local<Object> wrap) : BaseObject(env, wrap) {
5858

5959
voidHash::MemoryInfo(MemoryTracker* tracker) const {
6060
tracker->TrackFieldWithSize("mdctx", mdctx_ ? kSizeOf_EVP_MD_CTX : 0);
61-
tracker->TrackFieldWithSize("md", digest_ ? md_len_ : 0);
61+
tracker->TraitTrackInline(digest_, "md");
6262
}
6363

6464
#if NCRYPTO_USE_BORINGSSL_EVP_DO_ALL_FALLBACK
@@ -524,10 +524,7 @@ void Hash::HashDigest(const FunctionCallbackInfo<Value>& args) {
524524
}
525525

526526
HashConfig::HashConfig(HashConfig&& other) noexcept
527-
: mode(other.mode),
528-
in(std::move(other.in)),
529-
digest(other.digest),
530-
length(other.length) {}
527+
: in(std::move(other.in)), digest(other.digest), length(other.length) {}
531528

532529
HashConfig& HashConfig::operator=(HashConfig&& other) noexcept {
533530
if (&other == this) return *this;
@@ -536,8 +533,7 @@ HashConfig& HashConfig::operator=(HashConfig&& other) noexcept {
536533
}
537534

538535
voidHashConfig::MemoryInfo(MemoryTracker* tracker) const {
539-
// If the Job is sync, then the HashConfig does not own the data.
540-
if (IsCryptoJobAsync(mode)) tracker->TrackFieldWithSize("in", in.size());
536+
tracker->TraitTrackInline(in, "in");
541537
}
542538

543539
MaybeLocal<Value> HashTraits::EncodeOutput(Environment* env,
@@ -553,8 +549,6 @@ Maybe<void> HashTraits::AdditionalConfig(
553549
HashConfig* params) {
554550
Environment* env = Environment::GetCurrent(args);
555551

556-
params->mode = mode;
557-
558552
CHECK(args[offset]->IsString()); // Hash algorithm
559553
Utf8Value digest(env->isolate(), args[offset]);
560554
params->digest = ncrypto::getDigestByName(*digest);
@@ -782,8 +776,7 @@ bool DigestUpdateBytepad(ncrypto::EVPMDCtxPointer* ctx,
782776
} // namespace
783777

784778
CShakeConfig::CShakeConfig(CShakeConfig&& other) noexcept
785-
: mode(other.mode),
786-
in(std::move(other.in)),
779+
: in(std::move(other.in)),
787780
function_name(std::move(other.function_name)),
788781
customization(std::move(other.customization)),
789782
variant(other.variant),
@@ -796,12 +789,9 @@ CShakeConfig& CShakeConfig::operator=(CShakeConfig&& other) noexcept {
796789
}
797790

798791
voidCShakeConfig::MemoryInfo(MemoryTracker* tracker) const {
799-
// If the Job is sync, then the CShakeConfig does not own the data.
800-
if (IsCryptoJobAsync(mode)) {
801-
tracker->TrackFieldWithSize("in", in.size());
802-
tracker->TrackFieldWithSize("function_name", function_name.size());
803-
tracker->TrackFieldWithSize("customization", customization.size());
804-
}
792+
tracker->TraitTrackInline(in, "in");
793+
tracker->TraitTrackInline(function_name, "function_name");
794+
tracker->TraitTrackInline(customization, "customization");
805795
}
806796

807797
MaybeLocal<Value> CShakeTraits::EncodeOutput(Environment* env,
@@ -817,8 +807,6 @@ Maybe<void> CShakeTraits::AdditionalConfig(
817807
CShakeConfig* params) {
818808
Environment* env = Environment::GetCurrent(args);
819809

820-
params->mode = mode;
821-
822810
CHECK(args[offset]->IsString()); // Algorithm name
823811
Utf8Value algorithm_name(env->isolate(), args[offset]);
824812
std::string_view algorithm_str = algorithm_name.ToStringView();

β€Žsrc/crypto/crypto_hash.hβ€Ž

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class Hash final : public BaseObject {
4242
};
4343

4444
structHashConfigfinal : public MemoryRetainer {
45-
CryptoJobMode mode;
4645
ByteSource in;
4746
constEVP_MD* digest;
4847
unsignedint length;
@@ -107,7 +106,6 @@ struct CShakeParams final {
107106
boolDeriveCShakeBits(const CShakeParams& params, ByteSource* out);
108107

109108
structCShakeConfigfinal : public MemoryRetainer {
110-
CryptoJobMode mode;
111109
ByteSource in;
112110
ByteSource function_name;
113111
ByteSource customization;

β€Žsrc/crypto/crypto_hkdf.ccβ€Ž

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ using v8::Value;
2020

2121
namespacecrypto {
2222
HKDFConfig::HKDFConfig(HKDFConfig&& other) noexcept
23-
: mode(other.mode),
24-
length(other.length),
23+
: length(other.length),
2524
digest(other.digest),
2625
key(std::move(other.key)),
2726
key_data(std::move(other.key_data)),
@@ -47,8 +46,6 @@ Maybe<void> HKDFTraits::AdditionalConfig(
4746
HKDFConfig* params) {
4847
Environment* env = Environment::GetCurrent(args);
4948

50-
params->mode = mode;
51-
5249
CHECK(args[offset]->IsString()); // Hash
5350
CHECK(KeyObjectHandle::HasInstance(env, args[offset + 1]) ||
5451
IsAnyBufferSource(args[offset + 1])); // Key
@@ -136,13 +133,12 @@ bool HKDFTraits::DeriveBits(Environment* env,
136133
}
137134

138135
voidHKDFConfig::MemoryInfo(MemoryTracker* tracker) const {
139-
if (key) tracker->TrackField("key", key);
140-
// If the job is sync, then the HKDFConfig does not own the data
141-
if (IsCryptoJobAsync(mode)) {
142-
if (!key) tracker->TrackFieldWithSize("key", key_data.size());
143-
tracker->TrackFieldWithSize("salt", salt.size());
144-
tracker->TrackFieldWithSize("info", info.size());
145-
}
136+
if (key)
137+
tracker->TrackField("key", key);
138+
else
139+
tracker->TraitTrackInline(key_data, "key");
140+
tracker->TraitTrackInline(salt, "salt");
141+
tracker->TraitTrackInline(info, "info");
146142
}
147143

148144
} // namespace crypto

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Commit 782ad5d

Browse files
panvaaduh95
authored andcommitted
src: implement MemoryRetainer protocol for ByteSource
Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: #64660 Backport-PR-URL: #65087 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 4afc15b commit 782ad5d

32 files changed

Lines changed: 135 additions & 201 deletions

β€Žsrc/crypto/crypto_aes.ccβ€Ž

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,7 @@ void UseDefaultIV(AESCipherConfig* params) {
491491
} // namespace
492492

493493
AESCipherConfig::AESCipherConfig(AESCipherConfig&& other) noexcept
494-
: mode(other.mode),
495-
variant(other.variant),
494+
: variant(other.variant),
496495
cipher(other.cipher),
497496
length(other.length),
498497
iv(std::move(other.iv)),
@@ -505,12 +504,8 @@ AESCipherConfig& AESCipherConfig::operator=(AESCipherConfig&& other) noexcept {
505504
}
506505

507506
voidAESCipherConfig::MemoryInfo(MemoryTracker* tracker) const {
508-
// If mode is sync, then the data in each of these properties
509-
// is not owned by the AESCipherConfig, so we ignore it.
510-
if (IsCryptoJobAsync(mode)) {
511-
tracker->TrackFieldWithSize("iv", iv.size());
512-
tracker->TrackFieldWithSize("additional_data", additional_data.size());
513-
}
507+
tracker->TraitTrackInline(iv, "iv");
508+
tracker->TraitTrackInline(additional_data, "additional_data");
514509
}
515510

516511
Maybe<void> AESCipherTraits::AdditionalConfig(
@@ -521,8 +516,6 @@ Maybe<void> AESCipherTraits::AdditionalConfig(
521516
AESCipherConfig* params) {
522517
Environment* env = Environment::GetCurrent(args);
523518

524-
params->mode = mode;
525-
526519
CHECK(args[offset]->IsUint32()); // Key Variant
527520
params->variant =
528521
static_cast<AESKeyVariant>(args[offset].As<Uint32>()->Value());

β€Žsrc/crypto/crypto_aes.hβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ enum class AESKeyVariant {
5858
};
5959

6060
structAESCipherConfigfinal : public MemoryRetainer {
61-
CryptoJobMode mode;
6261
AESKeyVariant variant;
6362
ncrypto::Cipher cipher;
6463
size_t length;

β€Žsrc/crypto/crypto_argon2.ccβ€Ž

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ using v8::Uint32;
2121
using v8::Value;
2222

2323
Argon2Config::Argon2Config(Argon2Config&& other) noexcept
24-
: mode{other.mode},
25-
key{std::move(other.key)},
24+
: key{std::move(other.key)},
2625
pass{std::move(other.pass)},
2726
salt{std::move(other.salt)},
2827
secret{std::move(other.secret)},
@@ -40,13 +39,13 @@ Argon2Config& Argon2Config::operator=(Argon2Config&& other) noexcept {
4039
}
4140

4241
voidArgon2Config::MemoryInfo(MemoryTracker* tracker) const {
43-
if (key) tracker->TrackField("key", key);
44-
if (IsCryptoJobAsync(mode)) {
45-
if (!key) tracker->TrackFieldWithSize("pass", pass.size());
46-
tracker->TrackFieldWithSize("salt", salt.size());
47-
tracker->TrackFieldWithSize("secret", secret.size());
48-
tracker->TrackFieldWithSize("ad", ad.size());
49-
}
42+
if (key)
43+
tracker->TrackField("key", key);
44+
else
45+
tracker->TraitTrackInline(pass, "pass");
46+
tracker->TraitTrackInline(salt, "salt");
47+
tracker->TraitTrackInline(secret, "secret");
48+
tracker->TraitTrackInline(ad, "ad");
5049
}
5150

5251
MaybeLocal<Value> Argon2Traits::EncodeOutput(Environment* env,
@@ -62,8 +61,6 @@ Maybe<void> Argon2Traits::AdditionalConfig(
6261
Argon2Config* config) {
6362
Environment* env = Environment::GetCurrent(args);
6463

65-
config->mode = mode;
66-
6764
CHECK(KeyObjectHandle::HasInstance(env, args[offset]) ||
6865
IsAnyBufferSource(args[offset])); // pass
6966
ArrayBufferOrViewContents<char> salt(args[offset + 1]);

β€Žsrc/crypto/crypto_argon2.hβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ namespace node::crypto {
2222
// at least 16 bytes in length.
2323

2424
structArgon2Configfinal : public MemoryRetainer {
25-
CryptoJobMode mode;
2625
KeyObjectData key;
2726
ByteSource pass;
2827
ByteSource salt;

β€Žsrc/crypto/crypto_chacha20_poly1305.ccβ€Ž

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ bool ValidateAdditionalData(Environment* env,
8181

8282
ChaCha20Poly1305CipherConfig::ChaCha20Poly1305CipherConfig(
8383
ChaCha20Poly1305CipherConfig&& other) noexcept
84-
: mode(other.mode),
85-
cipher(other.cipher),
84+
: cipher(other.cipher),
8685
iv(std::move(other.iv)),
8786
additional_data(std::move(other.additional_data)) {}
8887

@@ -94,12 +93,8 @@ ChaCha20Poly1305CipherConfig& ChaCha20Poly1305CipherConfig::operator=(
9493
}
9594

9695
voidChaCha20Poly1305CipherConfig::MemoryInfo(MemoryTracker* tracker) const {
97-
// If mode is sync, then the data in each of these properties
98-
// is not owned by the ChaCha20Poly1305CipherConfig, so we ignore it.
99-
if (IsCryptoJobAsync(mode)) {
100-
tracker->TrackFieldWithSize("iv", iv.size());
101-
tracker->TrackFieldWithSize("additional_data", additional_data.size());
102-
}
96+
tracker->TraitTrackInline(iv, "iv");
97+
tracker->TraitTrackInline(additional_data, "additional_data");
10398
}
10499

105100
Maybe<void> ChaCha20Poly1305CipherTraits::AdditionalConfig(
@@ -110,7 +105,6 @@ Maybe<void> ChaCha20Poly1305CipherTraits::AdditionalConfig(
110105
ChaCha20Poly1305CipherConfig* params) {
111106
Environment* env = Environment::GetCurrent(args);
112107

113-
params->mode = mode;
114108
params->cipher = ncrypto::Cipher::CHACHA20_POLY1305;
115109

116110
#ifndef OPENSSL_IS_BORINGSSL

β€Žsrc/crypto/crypto_chacha20_poly1305.hβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ namespace node::crypto {
1313
constexprunsignedkChaCha20Poly1305AuthTagLength = 16;
1414

1515
structChaCha20Poly1305CipherConfigfinal : public MemoryRetainer {
16-
CryptoJobMode mode;
1716
ncrypto::Cipher cipher;
1817
ByteSource iv;
1918
ByteSource additional_data;

β€Žsrc/crypto/crypto_cipher.hβ€Ž

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,8 @@ class CipherJob final : public CryptoJob<CipherTraits> {
268268

269269
SET_SELF_SIZE(CipherJob)
270270
void MemoryInfo(MemoryTracker* tracker) constoverride {
271-
if (IsCryptoJobAsync(CryptoJob<CipherTraits>::mode()))
272-
tracker->TrackFieldWithSize("in", in_.size());
273-
tracker->TrackFieldWithSize("out", out_.size());
271+
tracker->TraitTrackInline(in_, "in");
272+
tracker->TraitTrackInline(out_, "out");
274273
CryptoJob<CipherTraits>::MemoryInfo(tracker);
275274
}
276275

β€Žsrc/crypto/crypto_hash.ccβ€Ž

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Hash::Hash(Environment* env, Local<Object> wrap) : BaseObject(env, wrap) {
5858

5959
voidHash::MemoryInfo(MemoryTracker* tracker) const {
6060
tracker->TrackFieldWithSize("mdctx", mdctx_ ? kSizeOf_EVP_MD_CTX : 0);
61-
tracker->TrackFieldWithSize("md", digest_ ? md_len_ : 0);
61+
tracker->TraitTrackInline(digest_, "md");
6262
}
6363

6464
#if NCRYPTO_USE_BORINGSSL_EVP_DO_ALL_FALLBACK
@@ -524,10 +524,7 @@ void Hash::HashDigest(const FunctionCallbackInfo<Value>& args) {
524524
}
525525

526526
HashConfig::HashConfig(HashConfig&& other) noexcept
527-
: mode(other.mode),
528-
in(std::move(other.in)),
529-
digest(other.digest),
530-
length(other.length) {}
527+
: in(std::move(other.in)), digest(other.digest), length(other.length) {}
531528

532529
HashConfig& HashConfig::operator=(HashConfig&& other) noexcept {
533530
if (&other == this) return *this;
@@ -536,8 +533,7 @@ HashConfig& HashConfig::operator=(HashConfig&& other) noexcept {
536533
}
537534

538535
voidHashConfig::MemoryInfo(MemoryTracker* tracker) const {
539-
// If the Job is sync, then the HashConfig does not own the data.
540-
if (IsCryptoJobAsync(mode)) tracker->TrackFieldWithSize("in", in.size());
536+
tracker->TraitTrackInline(in, "in");
541537
}
542538

543539
MaybeLocal<Value> HashTraits::EncodeOutput(Environment* env,
@@ -553,8 +549,6 @@ Maybe<void> HashTraits::AdditionalConfig(
553549
HashConfig* params) {
554550
Environment* env = Environment::GetCurrent(args);
555551

556-
params->mode = mode;
557-
558552
CHECK(args[offset]->IsString()); // Hash algorithm
559553
Utf8Value digest(env->isolate(), args[offset]);
560554
params->digest = ncrypto::getDigestByName(*digest);
@@ -782,8 +776,7 @@ bool DigestUpdateBytepad(ncrypto::EVPMDCtxPointer* ctx,
782776
} // namespace
783777

784778
CShakeConfig::CShakeConfig(CShakeConfig&& other) noexcept
785-
: mode(other.mode),
786-
in(std::move(other.in)),
779+
: in(std::move(other.in)),
787780
function_name(std::move(other.function_name)),
788781
customization(std::move(other.customization)),
789782
variant(other.variant),
@@ -796,12 +789,9 @@ CShakeConfig& CShakeConfig::operator=(CShakeConfig&& other) noexcept {
796789
}
797790

798791
voidCShakeConfig::MemoryInfo(MemoryTracker* tracker) const {
799-
// If the Job is sync, then the CShakeConfig does not own the data.
800-
if (IsCryptoJobAsync(mode)) {
801-
tracker->TrackFieldWithSize("in", in.size());
802-
tracker->TrackFieldWithSize("function_name", function_name.size());
803-
tracker->TrackFieldWithSize("customization", customization.size());
804-
}
792+
tracker->TraitTrackInline(in, "in");
793+
tracker->TraitTrackInline(function_name, "function_name");
794+
tracker->TraitTrackInline(customization, "customization");
805795
}
806796

807797
MaybeLocal<Value> CShakeTraits::EncodeOutput(Environment* env,
@@ -817,8 +807,6 @@ Maybe<void> CShakeTraits::AdditionalConfig(
817807
CShakeConfig* params) {
818808
Environment* env = Environment::GetCurrent(args);
819809

820-
params->mode = mode;
821-
822810
CHECK(args[offset]->IsString()); // Algorithm name
823811
Utf8Value algorithm_name(env->isolate(), args[offset]);
824812
std::string_view algorithm_str = algorithm_name.ToStringView();

β€Žsrc/crypto/crypto_hash.hβ€Ž

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class Hash final : public BaseObject {
4242
};
4343

4444
structHashConfigfinal : public MemoryRetainer {
45-
CryptoJobMode mode;
4645
ByteSource in;
4746
constEVP_MD* digest;
4847
unsignedint length;
@@ -107,7 +106,6 @@ struct CShakeParams final {
107106
boolDeriveCShakeBits(const CShakeParams& params, ByteSource* out);
108107

109108
structCShakeConfigfinal : public MemoryRetainer {
110-
CryptoJobMode mode;
111109
ByteSource in;
112110
ByteSource function_name;
113111
ByteSource customization;

β€Žsrc/crypto/crypto_hkdf.ccβ€Ž

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ using v8::Value;
2020

2121
namespacecrypto {
2222
HKDFConfig::HKDFConfig(HKDFConfig&& other) noexcept
23-
: mode(other.mode),
24-
length(other.length),
23+
: length(other.length),
2524
digest(other.digest),
2625
key(std::move(other.key)),
2726
key_data(std::move(other.key_data)),
@@ -47,8 +46,6 @@ Maybe<void> HKDFTraits::AdditionalConfig(
4746
HKDFConfig* params) {
4847
Environment* env = Environment::GetCurrent(args);
4948

50-
params->mode = mode;
51-
5249
CHECK(args[offset]->IsString()); // Hash
5350
CHECK(KeyObjectHandle::HasInstance(env, args[offset + 1]) ||
5451
IsAnyBufferSource(args[offset + 1])); // Key
@@ -136,13 +133,12 @@ bool HKDFTraits::DeriveBits(Environment* env,
136133
}
137134

138135
voidHKDFConfig::MemoryInfo(MemoryTracker* tracker) const {
139-
if (key) tracker->TrackField("key", key);
140-
// If the job is sync, then the HKDFConfig does not own the data
141-
if (IsCryptoJobAsync(mode)) {
142-
if (!key) tracker->TrackFieldWithSize("key", key_data.size());
143-
tracker->TrackFieldWithSize("salt", salt.size());
144-
tracker->TrackFieldWithSize("info", info.size());
145-
}
136+
if (key)
137+
tracker->TrackField("key", key);
138+
else
139+
tracker->TraitTrackInline(key_data, "key");
140+
tracker->TraitTrackInline(salt, "salt");
141+
tracker->TraitTrackInline(info, "info");
146142
}
147143

148144
} // namespace crypto

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 782ad5d

Browse files
panvaaduh95
authored andcommitted
src: implement MemoryRetainer protocol for ByteSource
Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: #64660 Backport-PR-URL: #65087 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 4afc15b commit 782ad5d

32 files changed

Lines changed: 135 additions & 201 deletions

β€Žsrc/crypto/crypto_aes.ccβ€Ž

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,7 @@ void UseDefaultIV(AESCipherConfig* params) {
491491
} // namespace
492492

493493
AESCipherConfig::AESCipherConfig(AESCipherConfig&& other) noexcept
494-
: mode(other.mode),
495-
variant(other.variant),
494+
: variant(other.variant),
496495
cipher(other.cipher),
497496
length(other.length),
498497
iv(std::move(other.iv)),
@@ -505,12 +504,8 @@ AESCipherConfig& AESCipherConfig::operator=(AESCipherConfig&& other) noexcept {
505504
}
506505

507506
voidAESCipherConfig::MemoryInfo(MemoryTracker* tracker) const {
508-
// If mode is sync, then the data in each of these properties
509-
// is not owned by the AESCipherConfig, so we ignore it.
510-
if (IsCryptoJobAsync(mode)) {
511-
tracker->TrackFieldWithSize("iv", iv.size());
512-
tracker->TrackFieldWithSize("additional_data", additional_data.size());
513-
}
507+
tracker->TraitTrackInline(iv, "iv");
508+
tracker->TraitTrackInline(additional_data, "additional_data");
514509
}
515510

516511
Maybe<void> AESCipherTraits::AdditionalConfig(
@@ -521,8 +516,6 @@ Maybe<void> AESCipherTraits::AdditionalConfig(
521516
AESCipherConfig* params) {
522517
Environment* env = Environment::GetCurrent(args);
523518

524-
params->mode = mode;
525-
526519
CHECK(args[offset]->IsUint32()); // Key Variant
527520
params->variant =
528521
static_cast<AESKeyVariant>(args[offset].As<Uint32>()->Value());

β€Žsrc/crypto/crypto_aes.hβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ enum class AESKeyVariant {
5858
};
5959

6060
structAESCipherConfigfinal : public MemoryRetainer {
61-
CryptoJobMode mode;
6261
AESKeyVariant variant;
6362
ncrypto::Cipher cipher;
6463
size_t length;

β€Žsrc/crypto/crypto_argon2.ccβ€Ž

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ using v8::Uint32;
2121
using v8::Value;
2222

2323
Argon2Config::Argon2Config(Argon2Config&& other) noexcept
24-
: mode{other.mode},
25-
key{std::move(other.key)},
24+
: key{std::move(other.key)},
2625
pass{std::move(other.pass)},
2726
salt{std::move(other.salt)},
2827
secret{std::move(other.secret)},
@@ -40,13 +39,13 @@ Argon2Config& Argon2Config::operator=(Argon2Config&& other) noexcept {
4039
}
4140

4241
voidArgon2Config::MemoryInfo(MemoryTracker* tracker) const {
43-
if (key) tracker->TrackField("key", key);
44-
if (IsCryptoJobAsync(mode)) {
45-
if (!key) tracker->TrackFieldWithSize("pass", pass.size());
46-
tracker->TrackFieldWithSize("salt", salt.size());
47-
tracker->TrackFieldWithSize("secret", secret.size());
48-
tracker->TrackFieldWithSize("ad", ad.size());
49-
}
42+
if (key)
43+
tracker->TrackField("key", key);
44+
else
45+
tracker->TraitTrackInline(pass, "pass");
46+
tracker->TraitTrackInline(salt, "salt");
47+
tracker->TraitTrackInline(secret, "secret");
48+
tracker->TraitTrackInline(ad, "ad");
5049
}
5150

5251
MaybeLocal<Value> Argon2Traits::EncodeOutput(Environment* env,
@@ -62,8 +61,6 @@ Maybe<void> Argon2Traits::AdditionalConfig(
6261
Argon2Config* config) {
6362
Environment* env = Environment::GetCurrent(args);
6463

65-
config->mode = mode;
66-
6764
CHECK(KeyObjectHandle::HasInstance(env, args[offset]) ||
6865
IsAnyBufferSource(args[offset])); // pass
6966
ArrayBufferOrViewContents<char> salt(args[offset + 1]);

β€Žsrc/crypto/crypto_argon2.hβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ namespace node::crypto {
2222
// at least 16 bytes in length.
2323

2424
structArgon2Configfinal : public MemoryRetainer {
25-
CryptoJobMode mode;
2625
KeyObjectData key;
2726
ByteSource pass;
2827
ByteSource salt;

β€Žsrc/crypto/crypto_chacha20_poly1305.ccβ€Ž

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ bool ValidateAdditionalData(Environment* env,
8181

8282
ChaCha20Poly1305CipherConfig::ChaCha20Poly1305CipherConfig(
8383
ChaCha20Poly1305CipherConfig&& other) noexcept
84-
: mode(other.mode),
85-
cipher(other.cipher),
84+
: cipher(other.cipher),
8685
iv(std::move(other.iv)),
8786
additional_data(std::move(other.additional_data)) {}
8887

@@ -94,12 +93,8 @@ ChaCha20Poly1305CipherConfig& ChaCha20Poly1305CipherConfig::operator=(
9493
}
9594

9695
voidChaCha20Poly1305CipherConfig::MemoryInfo(MemoryTracker* tracker) const {
97-
// If mode is sync, then the data in each of these properties
98-
// is not owned by the ChaCha20Poly1305CipherConfig, so we ignore it.
99-
if (IsCryptoJobAsync(mode)) {
100-
tracker->TrackFieldWithSize("iv", iv.size());
101-
tracker->TrackFieldWithSize("additional_data", additional_data.size());
102-
}
96+
tracker->TraitTrackInline(iv, "iv");
97+
tracker->TraitTrackInline(additional_data, "additional_data");
10398
}
10499

105100
Maybe<void> ChaCha20Poly1305CipherTraits::AdditionalConfig(
@@ -110,7 +105,6 @@ Maybe<void> ChaCha20Poly1305CipherTraits::AdditionalConfig(
110105
ChaCha20Poly1305CipherConfig* params) {
111106
Environment* env = Environment::GetCurrent(args);
112107

113-
params->mode = mode;
114108
params->cipher = ncrypto::Cipher::CHACHA20_POLY1305;
115109

116110
#ifndef OPENSSL_IS_BORINGSSL

β€Žsrc/crypto/crypto_chacha20_poly1305.hβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ namespace node::crypto {
1313
constexprunsignedkChaCha20Poly1305AuthTagLength = 16;
1414

1515
structChaCha20Poly1305CipherConfigfinal : public MemoryRetainer {
16-
CryptoJobMode mode;
1716
ncrypto::Cipher cipher;
1817
ByteSource iv;
1918
ByteSource additional_data;

β€Žsrc/crypto/crypto_cipher.hβ€Ž

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,8 @@ class CipherJob final : public CryptoJob<CipherTraits> {
268268

269269
SET_SELF_SIZE(CipherJob)
270270
void MemoryInfo(MemoryTracker* tracker) constoverride {
271-
if (IsCryptoJobAsync(CryptoJob<CipherTraits>::mode()))
272-
tracker->TrackFieldWithSize("in", in_.size());
273-
tracker->TrackFieldWithSize("out", out_.size());
271+
tracker->TraitTrackInline(in_, "in");
272+
tracker->TraitTrackInline(out_, "out");
274273
CryptoJob<CipherTraits>::MemoryInfo(tracker);
275274
}
276275

β€Žsrc/crypto/crypto_hash.ccβ€Ž

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Hash::Hash(Environment* env, Local<Object> wrap) : BaseObject(env, wrap) {
5858

5959
voidHash::MemoryInfo(MemoryTracker* tracker) const {
6060
tracker->TrackFieldWithSize("mdctx", mdctx_ ? kSizeOf_EVP_MD_CTX : 0);
61-
tracker->TrackFieldWithSize("md", digest_ ? md_len_ : 0);
61+
tracker->TraitTrackInline(digest_, "md");
6262
}
6363

6464
#if NCRYPTO_USE_BORINGSSL_EVP_DO_ALL_FALLBACK
@@ -524,10 +524,7 @@ void Hash::HashDigest(const FunctionCallbackInfo<Value>& args) {
524524
}
525525

526526
HashConfig::HashConfig(HashConfig&& other) noexcept
527-
: mode(other.mode),
528-
in(std::move(other.in)),
529-
digest(other.digest),
530-
length(other.length) {}
527+
: in(std::move(other.in)), digest(other.digest), length(other.length) {}
531528

532529
HashConfig& HashConfig::operator=(HashConfig&& other) noexcept {
533530
if (&other == this) return *this;
@@ -536,8 +533,7 @@ HashConfig& HashConfig::operator=(HashConfig&& other) noexcept {
536533
}
537534

538535
voidHashConfig::MemoryInfo(MemoryTracker* tracker) const {
539-
// If the Job is sync, then the HashConfig does not own the data.
540-
if (IsCryptoJobAsync(mode)) tracker->TrackFieldWithSize("in", in.size());
536+
tracker->TraitTrackInline(in, "in");
541537
}
542538

543539
MaybeLocal<Value> HashTraits::EncodeOutput(Environment* env,
@@ -553,8 +549,6 @@ Maybe<void> HashTraits::AdditionalConfig(
553549
HashConfig* params) {
554550
Environment* env = Environment::GetCurrent(args);
555551

556-
params->mode = mode;
557-
558552
CHECK(args[offset]->IsString()); // Hash algorithm
559553
Utf8Value digest(env->isolate(), args[offset]);
560554
params->digest = ncrypto::getDigestByName(*digest);
@@ -782,8 +776,7 @@ bool DigestUpdateBytepad(ncrypto::EVPMDCtxPointer* ctx,
782776
} // namespace
783777

784778
CShakeConfig::CShakeConfig(CShakeConfig&& other) noexcept
785-
: mode(other.mode),
786-
in(std::move(other.in)),
779+
: in(std::move(other.in)),
787780
function_name(std::move(other.function_name)),
788781
customization(std::move(other.customization)),
789782
variant(other.variant),
@@ -796,12 +789,9 @@ CShakeConfig& CShakeConfig::operator=(CShakeConfig&& other) noexcept {
796789
}
797790

798791
voidCShakeConfig::MemoryInfo(MemoryTracker* tracker) const {
799-
// If the Job is sync, then the CShakeConfig does not own the data.
800-
if (IsCryptoJobAsync(mode)) {
801-
tracker->TrackFieldWithSize("in", in.size());
802-
tracker->TrackFieldWithSize("function_name", function_name.size());
803-
tracker->TrackFieldWithSize("customization", customization.size());
804-
}
792+
tracker->TraitTrackInline(in, "in");
793+
tracker->TraitTrackInline(function_name, "function_name");
794+
tracker->TraitTrackInline(customization, "customization");
805795
}
806796

807797
MaybeLocal<Value> CShakeTraits::EncodeOutput(Environment* env,
@@ -817,8 +807,6 @@ Maybe<void> CShakeTraits::AdditionalConfig(
817807
CShakeConfig* params) {
818808
Environment* env = Environment::GetCurrent(args);
819809

820-
params->mode = mode;
821-
822810
CHECK(args[offset]->IsString()); // Algorithm name
823811
Utf8Value algorithm_name(env->isolate(), args[offset]);
824812
std::string_view algorithm_str = algorithm_name.ToStringView();

β€Žsrc/crypto/crypto_hash.hβ€Ž

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class Hash final : public BaseObject {
4242
};
4343

4444
structHashConfigfinal : public MemoryRetainer {
45-
CryptoJobMode mode;
4645
ByteSource in;
4746
constEVP_MD* digest;
4847
unsignedint length;
@@ -107,7 +106,6 @@ struct CShakeParams final {
107106
boolDeriveCShakeBits(const CShakeParams& params, ByteSource* out);
108107

109108
structCShakeConfigfinal : public MemoryRetainer {
110-
CryptoJobMode mode;
111109
ByteSource in;
112110
ByteSource function_name;
113111
ByteSource customization;

β€Žsrc/crypto/crypto_hkdf.ccβ€Ž

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ using v8::Value;
2020

2121
namespacecrypto {
2222
HKDFConfig::HKDFConfig(HKDFConfig&& other) noexcept
23-
: mode(other.mode),
24-
length(other.length),
23+
: length(other.length),
2524
digest(other.digest),
2625
key(std::move(other.key)),
2726
key_data(std::move(other.key_data)),
@@ -47,8 +46,6 @@ Maybe<void> HKDFTraits::AdditionalConfig(
4746
HKDFConfig* params) {
4847
Environment* env = Environment::GetCurrent(args);
4948

50-
params->mode = mode;
51-
5249
CHECK(args[offset]->IsString()); // Hash
5350
CHECK(KeyObjectHandle::HasInstance(env, args[offset + 1]) ||
5451
IsAnyBufferSource(args[offset + 1])); // Key
@@ -136,13 +133,12 @@ bool HKDFTraits::DeriveBits(Environment* env,
136133
}
137134

138135
voidHKDFConfig::MemoryInfo(MemoryTracker* tracker) const {
139-
if (key) tracker->TrackField("key", key);
140-
// If the job is sync, then the HKDFConfig does not own the data
141-
if (IsCryptoJobAsync(mode)) {
142-
if (!key) tracker->TrackFieldWithSize("key", key_data.size());
143-
tracker->TrackFieldWithSize("salt", salt.size());
144-
tracker->TrackFieldWithSize("info", info.size());
145-
}
136+
if (key)
137+
tracker->TrackField("key", key);
138+
else
139+
tracker->TraitTrackInline(key_data, "key");
140+
tracker->TraitTrackInline(salt, "salt");
141+
tracker->TraitTrackInline(info, "info");
146142
}
147143

148144
} // namespace crypto

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 782ad5d

Browse files
panvaaduh95
authored andcommitted
src: implement MemoryRetainer protocol for ByteSource
Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: #64660 Backport-PR-URL: #65087 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 4afc15b commit 782ad5d

32 files changed

Lines changed: 135 additions & 201 deletions

β€Žsrc/crypto/crypto_aes.ccβ€Ž

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,7 @@ void UseDefaultIV(AESCipherConfig* params) {
491491
} // namespace
492492

493493
AESCipherConfig::AESCipherConfig(AESCipherConfig&& other) noexcept
494-
: mode(other.mode),
495-
variant(other.variant),
494+
: variant(other.variant),
496495
cipher(other.cipher),
497496
length(other.length),
498497
iv(std::move(other.iv)),
@@ -505,12 +504,8 @@ AESCipherConfig& AESCipherConfig::operator=(AESCipherConfig&& other) noexcept {
505504
}
506505

507506
voidAESCipherConfig::MemoryInfo(MemoryTracker* tracker) const {
508-
// If mode is sync, then the data in each of these properties
509-
// is not owned by the AESCipherConfig, so we ignore it.
510-
if (IsCryptoJobAsync(mode)) {
511-
tracker->TrackFieldWithSize("iv", iv.size());
512-
tracker->TrackFieldWithSize("additional_data", additional_data.size());
513-
}
507+
tracker->TraitTrackInline(iv, "iv");
508+
tracker->TraitTrackInline(additional_data, "additional_data");
514509
}
515510

516511
Maybe<void> AESCipherTraits::AdditionalConfig(
@@ -521,8 +516,6 @@ Maybe<void> AESCipherTraits::AdditionalConfig(
521516
AESCipherConfig* params) {
522517
Environment* env = Environment::GetCurrent(args);
523518

524-
params->mode = mode;
525-
526519
CHECK(args[offset]->IsUint32()); // Key Variant
527520
params->variant =
528521
static_cast<AESKeyVariant>(args[offset].As<Uint32>()->Value());

β€Žsrc/crypto/crypto_aes.hβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ enum class AESKeyVariant {
5858
};
5959

6060
structAESCipherConfigfinal : public MemoryRetainer {
61-
CryptoJobMode mode;
6261
AESKeyVariant variant;
6362
ncrypto::Cipher cipher;
6463
size_t length;

β€Žsrc/crypto/crypto_argon2.ccβ€Ž

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ using v8::Uint32;
2121
using v8::Value;
2222

2323
Argon2Config::Argon2Config(Argon2Config&& other) noexcept
24-
: mode{other.mode},
25-
key{std::move(other.key)},
24+
: key{std::move(other.key)},
2625
pass{std::move(other.pass)},
2726
salt{std::move(other.salt)},
2827
secret{std::move(other.secret)},
@@ -40,13 +39,13 @@ Argon2Config& Argon2Config::operator=(Argon2Config&& other) noexcept {
4039
}
4140

4241
voidArgon2Config::MemoryInfo(MemoryTracker* tracker) const {
43-
if (key) tracker->TrackField("key", key);
44-
if (IsCryptoJobAsync(mode)) {
45-
if (!key) tracker->TrackFieldWithSize("pass", pass.size());
46-
tracker->TrackFieldWithSize("salt", salt.size());
47-
tracker->TrackFieldWithSize("secret", secret.size());
48-
tracker->TrackFieldWithSize("ad", ad.size());
49-
}
42+
if (key)
43+
tracker->TrackField("key", key);
44+
else
45+
tracker->TraitTrackInline(pass, "pass");
46+
tracker->TraitTrackInline(salt, "salt");
47+
tracker->TraitTrackInline(secret, "secret");
48+
tracker->TraitTrackInline(ad, "ad");
5049
}
5150

5251
MaybeLocal<Value> Argon2Traits::EncodeOutput(Environment* env,
@@ -62,8 +61,6 @@ Maybe<void> Argon2Traits::AdditionalConfig(
6261
Argon2Config* config) {
6362
Environment* env = Environment::GetCurrent(args);
6463

65-
config->mode = mode;
66-
6764
CHECK(KeyObjectHandle::HasInstance(env, args[offset]) ||
6865
IsAnyBufferSource(args[offset])); // pass
6966
ArrayBufferOrViewContents<char> salt(args[offset + 1]);

β€Žsrc/crypto/crypto_argon2.hβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ namespace node::crypto {
2222
// at least 16 bytes in length.
2323

2424
structArgon2Configfinal : public MemoryRetainer {
25-
CryptoJobMode mode;
2625
KeyObjectData key;
2726
ByteSource pass;
2827
ByteSource salt;

β€Žsrc/crypto/crypto_chacha20_poly1305.ccβ€Ž

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ bool ValidateAdditionalData(Environment* env,
8181

8282
ChaCha20Poly1305CipherConfig::ChaCha20Poly1305CipherConfig(
8383
ChaCha20Poly1305CipherConfig&& other) noexcept
84-
: mode(other.mode),
85-
cipher(other.cipher),
84+
: cipher(other.cipher),
8685
iv(std::move(other.iv)),
8786
additional_data(std::move(other.additional_data)) {}
8887

@@ -94,12 +93,8 @@ ChaCha20Poly1305CipherConfig& ChaCha20Poly1305CipherConfig::operator=(
9493
}
9594

9695
voidChaCha20Poly1305CipherConfig::MemoryInfo(MemoryTracker* tracker) const {
97-
// If mode is sync, then the data in each of these properties
98-
// is not owned by the ChaCha20Poly1305CipherConfig, so we ignore it.
99-
if (IsCryptoJobAsync(mode)) {
100-
tracker->TrackFieldWithSize("iv", iv.size());
101-
tracker->TrackFieldWithSize("additional_data", additional_data.size());
102-
}
96+
tracker->TraitTrackInline(iv, "iv");
97+
tracker->TraitTrackInline(additional_data, "additional_data");
10398
}
10499

105100
Maybe<void> ChaCha20Poly1305CipherTraits::AdditionalConfig(
@@ -110,7 +105,6 @@ Maybe<void> ChaCha20Poly1305CipherTraits::AdditionalConfig(
110105
ChaCha20Poly1305CipherConfig* params) {
111106
Environment* env = Environment::GetCurrent(args);
112107

113-
params->mode = mode;
114108
params->cipher = ncrypto::Cipher::CHACHA20_POLY1305;
115109

116110
#ifndef OPENSSL_IS_BORINGSSL

β€Žsrc/crypto/crypto_chacha20_poly1305.hβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ namespace node::crypto {
1313
constexprunsignedkChaCha20Poly1305AuthTagLength = 16;
1414

1515
structChaCha20Poly1305CipherConfigfinal : public MemoryRetainer {
16-
CryptoJobMode mode;
1716
ncrypto::Cipher cipher;
1817
ByteSource iv;
1918
ByteSource additional_data;

β€Žsrc/crypto/crypto_cipher.hβ€Ž

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,8 @@ class CipherJob final : public CryptoJob<CipherTraits> {
268268

269269
SET_SELF_SIZE(CipherJob)
270270
void MemoryInfo(MemoryTracker* tracker) constoverride {
271-
if (IsCryptoJobAsync(CryptoJob<CipherTraits>::mode()))
272-
tracker->TrackFieldWithSize("in", in_.size());
273-
tracker->TrackFieldWithSize("out", out_.size());
271+
tracker->TraitTrackInline(in_, "in");
272+
tracker->TraitTrackInline(out_, "out");
274273
CryptoJob<CipherTraits>::MemoryInfo(tracker);
275274
}
276275

β€Žsrc/crypto/crypto_hash.ccβ€Ž

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Hash::Hash(Environment* env, Local<Object> wrap) : BaseObject(env, wrap) {
5858

5959
voidHash::MemoryInfo(MemoryTracker* tracker) const {
6060
tracker->TrackFieldWithSize("mdctx", mdctx_ ? kSizeOf_EVP_MD_CTX : 0);
61-
tracker->TrackFieldWithSize("md", digest_ ? md_len_ : 0);
61+
tracker->TraitTrackInline(digest_, "md");
6262
}
6363

6464
#if NCRYPTO_USE_BORINGSSL_EVP_DO_ALL_FALLBACK
@@ -524,10 +524,7 @@ void Hash::HashDigest(const FunctionCallbackInfo<Value>& args) {
524524
}
525525

526526
HashConfig::HashConfig(HashConfig&& other) noexcept
527-
: mode(other.mode),
528-
in(std::move(other.in)),
529-
digest(other.digest),
530-
length(other.length) {}
527+
: in(std::move(other.in)), digest(other.digest), length(other.length) {}
531528

532529
HashConfig& HashConfig::operator=(HashConfig&& other) noexcept {
533530
if (&other == this) return *this;
@@ -536,8 +533,7 @@ HashConfig& HashConfig::operator=(HashConfig&& other) noexcept {
536533
}
537534

538535
voidHashConfig::MemoryInfo(MemoryTracker* tracker) const {
539-
// If the Job is sync, then the HashConfig does not own the data.
540-
if (IsCryptoJobAsync(mode)) tracker->TrackFieldWithSize("in", in.size());
536+
tracker->TraitTrackInline(in, "in");
541537
}
542538

543539
MaybeLocal<Value> HashTraits::EncodeOutput(Environment* env,
@@ -553,8 +549,6 @@ Maybe<void> HashTraits::AdditionalConfig(
553549
HashConfig* params) {
554550
Environment* env = Environment::GetCurrent(args);
555551

556-
params->mode = mode;
557-
558552
CHECK(args[offset]->IsString()); // Hash algorithm
559553
Utf8Value digest(env->isolate(), args[offset]);
560554
params->digest = ncrypto::getDigestByName(*digest);
@@ -782,8 +776,7 @@ bool DigestUpdateBytepad(ncrypto::EVPMDCtxPointer* ctx,
782776
} // namespace
783777

784778
CShakeConfig::CShakeConfig(CShakeConfig&& other) noexcept
785-
: mode(other.mode),
786-
in(std::move(other.in)),
779+
: in(std::move(other.in)),
787780
function_name(std::move(other.function_name)),
788781
customization(std::move(other.customization)),
789782
variant(other.variant),
@@ -796,12 +789,9 @@ CShakeConfig& CShakeConfig::operator=(CShakeConfig&& other) noexcept {
796789
}
797790

798791
voidCShakeConfig::MemoryInfo(MemoryTracker* tracker) const {
799-
// If the Job is sync, then the CShakeConfig does not own the data.
800-
if (IsCryptoJobAsync(mode)) {
801-
tracker->TrackFieldWithSize("in", in.size());
802-
tracker->TrackFieldWithSize("function_name", function_name.size());
803-
tracker->TrackFieldWithSize("customization", customization.size());
804-
}
792+
tracker->TraitTrackInline(in, "in");
793+
tracker->TraitTrackInline(function_name, "function_name");
794+
tracker->TraitTrackInline(customization, "customization");
805795
}
806796

807797
MaybeLocal<Value> CShakeTraits::EncodeOutput(Environment* env,
@@ -817,8 +807,6 @@ Maybe<void> CShakeTraits::AdditionalConfig(
817807
CShakeConfig* params) {
818808
Environment* env = Environment::GetCurrent(args);
819809

820-
params->mode = mode;
821-
822810
CHECK(args[offset]->IsString()); // Algorithm name
823811
Utf8Value algorithm_name(env->isolate(), args[offset]);
824812
std::string_view algorithm_str = algorithm_name.ToStringView();

β€Žsrc/crypto/crypto_hash.hβ€Ž

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class Hash final : public BaseObject {
4242
};
4343

4444
structHashConfigfinal : public MemoryRetainer {
45-
CryptoJobMode mode;
4645
ByteSource in;
4746
constEVP_MD* digest;
4847
unsignedint length;
@@ -107,7 +106,6 @@ struct CShakeParams final {
107106
boolDeriveCShakeBits(const CShakeParams& params, ByteSource* out);
108107

109108
structCShakeConfigfinal : public MemoryRetainer {
110-
CryptoJobMode mode;
111109
ByteSource in;
112110
ByteSource function_name;
113111
ByteSource customization;

β€Žsrc/crypto/crypto_hkdf.ccβ€Ž

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ using v8::Value;
2020

2121
namespacecrypto {
2222
HKDFConfig::HKDFConfig(HKDFConfig&& other) noexcept
23-
: mode(other.mode),
24-
length(other.length),
23+
: length(other.length),
2524
digest(other.digest),
2625
key(std::move(other.key)),
2726
key_data(std::move(other.key_data)),
@@ -47,8 +46,6 @@ Maybe<void> HKDFTraits::AdditionalConfig(
4746
HKDFConfig* params) {
4847
Environment* env = Environment::GetCurrent(args);
4948

50-
params->mode = mode;
51-
5249
CHECK(args[offset]->IsString()); // Hash
5350
CHECK(KeyObjectHandle::HasInstance(env, args[offset + 1]) ||
5451
IsAnyBufferSource(args[offset + 1])); // Key
@@ -136,13 +133,12 @@ bool HKDFTraits::DeriveBits(Environment* env,
136133
}
137134

138135
voidHKDFConfig::MemoryInfo(MemoryTracker* tracker) const {
139-
if (key) tracker->TrackField("key", key);
140-
// If the job is sync, then the HKDFConfig does not own the data
141-
if (IsCryptoJobAsync(mode)) {
142-
if (!key) tracker->TrackFieldWithSize("key", key_data.size());
143-
tracker->TrackFieldWithSize("salt", salt.size());
144-
tracker->TrackFieldWithSize("info", info.size());
145-
}
136+
if (key)
137+
tracker->TrackField("key", key);
138+
else
139+
tracker->TraitTrackInline(key_data, "key");
140+
tracker->TraitTrackInline(salt, "salt");
141+
tracker->TraitTrackInline(info, "info");
146142
}
147143

148144
} // namespace crypto

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Commit 782ad5d

Browse files
panvaaduh95
authored andcommitted
src: implement MemoryRetainer protocol for ByteSource
Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: #64660 Backport-PR-URL: #65087 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 4afc15b commit 782ad5d

32 files changed

Lines changed: 135 additions & 201 deletions

β€Žsrc/crypto/crypto_aes.ccβ€Ž

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,7 @@ void UseDefaultIV(AESCipherConfig* params) {
491491
} // namespace
492492

493493
AESCipherConfig::AESCipherConfig(AESCipherConfig&& other) noexcept
494-
: mode(other.mode),
495-
variant(other.variant),
494+
: variant(other.variant),
496495
cipher(other.cipher),
497496
length(other.length),
498497
iv(std::move(other.iv)),
@@ -505,12 +504,8 @@ AESCipherConfig& AESCipherConfig::operator=(AESCipherConfig&& other) noexcept {
505504
}
506505

507506
voidAESCipherConfig::MemoryInfo(MemoryTracker* tracker) const {
508-
// If mode is sync, then the data in each of these properties
509-
// is not owned by the AESCipherConfig, so we ignore it.
510-
if (IsCryptoJobAsync(mode)) {
511-
tracker->TrackFieldWithSize("iv", iv.size());
512-
tracker->TrackFieldWithSize("additional_data", additional_data.size());
513-
}
507+
tracker->TraitTrackInline(iv, "iv");
508+
tracker->TraitTrackInline(additional_data, "additional_data");
514509
}
515510

516511
Maybe<void> AESCipherTraits::AdditionalConfig(
@@ -521,8 +516,6 @@ Maybe<void> AESCipherTraits::AdditionalConfig(
521516
AESCipherConfig* params) {
522517
Environment* env = Environment::GetCurrent(args);
523518

524-
params->mode = mode;
525-
526519
CHECK(args[offset]->IsUint32()); // Key Variant
527520
params->variant =
528521
static_cast<AESKeyVariant>(args[offset].As<Uint32>()->Value());

β€Žsrc/crypto/crypto_aes.hβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ enum class AESKeyVariant {
5858
};
5959

6060
structAESCipherConfigfinal : public MemoryRetainer {
61-
CryptoJobMode mode;
6261
AESKeyVariant variant;
6362
ncrypto::Cipher cipher;
6463
size_t length;

β€Žsrc/crypto/crypto_argon2.ccβ€Ž

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ using v8::Uint32;
2121
using v8::Value;
2222

2323
Argon2Config::Argon2Config(Argon2Config&& other) noexcept
24-
: mode{other.mode},
25-
key{std::move(other.key)},
24+
: key{std::move(other.key)},
2625
pass{std::move(other.pass)},
2726
salt{std::move(other.salt)},
2827
secret{std::move(other.secret)},
@@ -40,13 +39,13 @@ Argon2Config& Argon2Config::operator=(Argon2Config&& other) noexcept {
4039
}
4140

4241
voidArgon2Config::MemoryInfo(MemoryTracker* tracker) const {
43-
if (key) tracker->TrackField("key", key);
44-
if (IsCryptoJobAsync(mode)) {
45-
if (!key) tracker->TrackFieldWithSize("pass", pass.size());
46-
tracker->TrackFieldWithSize("salt", salt.size());
47-
tracker->TrackFieldWithSize("secret", secret.size());
48-
tracker->TrackFieldWithSize("ad", ad.size());
49-
}
42+
if (key)
43+
tracker->TrackField("key", key);
44+
else
45+
tracker->TraitTrackInline(pass, "pass");
46+
tracker->TraitTrackInline(salt, "salt");
47+
tracker->TraitTrackInline(secret, "secret");
48+
tracker->TraitTrackInline(ad, "ad");
5049
}
5150

5251
MaybeLocal<Value> Argon2Traits::EncodeOutput(Environment* env,
@@ -62,8 +61,6 @@ Maybe<void> Argon2Traits::AdditionalConfig(
6261
Argon2Config* config) {
6362
Environment* env = Environment::GetCurrent(args);
6463

65-
config->mode = mode;
66-
6764
CHECK(KeyObjectHandle::HasInstance(env, args[offset]) ||
6865
IsAnyBufferSource(args[offset])); // pass
6966
ArrayBufferOrViewContents<char> salt(args[offset + 1]);

β€Žsrc/crypto/crypto_argon2.hβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ namespace node::crypto {
2222
// at least 16 bytes in length.
2323

2424
structArgon2Configfinal : public MemoryRetainer {
25-
CryptoJobMode mode;
2625
KeyObjectData key;
2726
ByteSource pass;
2827
ByteSource salt;

β€Žsrc/crypto/crypto_chacha20_poly1305.ccβ€Ž

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ bool ValidateAdditionalData(Environment* env,
8181

8282
ChaCha20Poly1305CipherConfig::ChaCha20Poly1305CipherConfig(
8383
ChaCha20Poly1305CipherConfig&& other) noexcept
84-
: mode(other.mode),
85-
cipher(other.cipher),
84+
: cipher(other.cipher),
8685
iv(std::move(other.iv)),
8786
additional_data(std::move(other.additional_data)) {}
8887

@@ -94,12 +93,8 @@ ChaCha20Poly1305CipherConfig& ChaCha20Poly1305CipherConfig::operator=(
9493
}
9594

9695
voidChaCha20Poly1305CipherConfig::MemoryInfo(MemoryTracker* tracker) const {
97-
// If mode is sync, then the data in each of these properties
98-
// is not owned by the ChaCha20Poly1305CipherConfig, so we ignore it.
99-
if (IsCryptoJobAsync(mode)) {
100-
tracker->TrackFieldWithSize("iv", iv.size());
101-
tracker->TrackFieldWithSize("additional_data", additional_data.size());
102-
}
96+
tracker->TraitTrackInline(iv, "iv");
97+
tracker->TraitTrackInline(additional_data, "additional_data");
10398
}
10499

105100
Maybe<void> ChaCha20Poly1305CipherTraits::AdditionalConfig(
@@ -110,7 +105,6 @@ Maybe<void> ChaCha20Poly1305CipherTraits::AdditionalConfig(
110105
ChaCha20Poly1305CipherConfig* params) {
111106
Environment* env = Environment::GetCurrent(args);
112107

113-
params->mode = mode;
114108
params->cipher = ncrypto::Cipher::CHACHA20_POLY1305;
115109

116110
#ifndef OPENSSL_IS_BORINGSSL

β€Žsrc/crypto/crypto_chacha20_poly1305.hβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ namespace node::crypto {
1313
constexprunsignedkChaCha20Poly1305AuthTagLength = 16;
1414

1515
structChaCha20Poly1305CipherConfigfinal : public MemoryRetainer {
16-
CryptoJobMode mode;
1716
ncrypto::Cipher cipher;
1817
ByteSource iv;
1918
ByteSource additional_data;

β€Žsrc/crypto/crypto_cipher.hβ€Ž

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,8 @@ class CipherJob final : public CryptoJob<CipherTraits> {
268268

269269
SET_SELF_SIZE(CipherJob)
270270
void MemoryInfo(MemoryTracker* tracker) constoverride {
271-
if (IsCryptoJobAsync(CryptoJob<CipherTraits>::mode()))
272-
tracker->TrackFieldWithSize("in", in_.size());
273-
tracker->TrackFieldWithSize("out", out_.size());
271+
tracker->TraitTrackInline(in_, "in");
272+
tracker->TraitTrackInline(out_, "out");
274273
CryptoJob<CipherTraits>::MemoryInfo(tracker);
275274
}
276275

β€Žsrc/crypto/crypto_hash.ccβ€Ž

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Hash::Hash(Environment* env, Local<Object> wrap) : BaseObject(env, wrap) {
5858

5959
voidHash::MemoryInfo(MemoryTracker* tracker) const {
6060
tracker->TrackFieldWithSize("mdctx", mdctx_ ? kSizeOf_EVP_MD_CTX : 0);
61-
tracker->TrackFieldWithSize("md", digest_ ? md_len_ : 0);
61+
tracker->TraitTrackInline(digest_, "md");
6262
}
6363

6464
#if NCRYPTO_USE_BORINGSSL_EVP_DO_ALL_FALLBACK
@@ -524,10 +524,7 @@ void Hash::HashDigest(const FunctionCallbackInfo<Value>& args) {
524524
}
525525

526526
HashConfig::HashConfig(HashConfig&& other) noexcept
527-
: mode(other.mode),
528-
in(std::move(other.in)),
529-
digest(other.digest),
530-
length(other.length) {}
527+
: in(std::move(other.in)), digest(other.digest), length(other.length) {}
531528

532529
HashConfig& HashConfig::operator=(HashConfig&& other) noexcept {
533530
if (&other == this) return *this;
@@ -536,8 +533,7 @@ HashConfig& HashConfig::operator=(HashConfig&& other) noexcept {
536533
}
537534

538535
voidHashConfig::MemoryInfo(MemoryTracker* tracker) const {
539-
// If the Job is sync, then the HashConfig does not own the data.
540-
if (IsCryptoJobAsync(mode)) tracker->TrackFieldWithSize("in", in.size());
536+
tracker->TraitTrackInline(in, "in");
541537
}
542538

543539
MaybeLocal<Value> HashTraits::EncodeOutput(Environment* env,
@@ -553,8 +549,6 @@ Maybe<void> HashTraits::AdditionalConfig(
553549
HashConfig* params) {
554550
Environment* env = Environment::GetCurrent(args);
555551

556-
params->mode = mode;
557-
558552
CHECK(args[offset]->IsString()); // Hash algorithm
559553
Utf8Value digest(env->isolate(), args[offset]);
560554
params->digest = ncrypto::getDigestByName(*digest);
@@ -782,8 +776,7 @@ bool DigestUpdateBytepad(ncrypto::EVPMDCtxPointer* ctx,
782776
} // namespace
783777

784778
CShakeConfig::CShakeConfig(CShakeConfig&& other) noexcept
785-
: mode(other.mode),
786-
in(std::move(other.in)),
779+
: in(std::move(other.in)),
787780
function_name(std::move(other.function_name)),
788781
customization(std::move(other.customization)),
789782
variant(other.variant),
@@ -796,12 +789,9 @@ CShakeConfig& CShakeConfig::operator=(CShakeConfig&& other) noexcept {
796789
}
797790

798791
voidCShakeConfig::MemoryInfo(MemoryTracker* tracker) const {
799-
// If the Job is sync, then the CShakeConfig does not own the data.
800-
if (IsCryptoJobAsync(mode)) {
801-
tracker->TrackFieldWithSize("in", in.size());
802-
tracker->TrackFieldWithSize("function_name", function_name.size());
803-
tracker->TrackFieldWithSize("customization", customization.size());
804-
}
792+
tracker->TraitTrackInline(in, "in");
793+
tracker->TraitTrackInline(function_name, "function_name");
794+
tracker->TraitTrackInline(customization, "customization");
805795
}
806796

807797
MaybeLocal<Value> CShakeTraits::EncodeOutput(Environment* env,
@@ -817,8 +807,6 @@ Maybe<void> CShakeTraits::AdditionalConfig(
817807
CShakeConfig* params) {
818808
Environment* env = Environment::GetCurrent(args);
819809

820-
params->mode = mode;
821-
822810
CHECK(args[offset]->IsString()); // Algorithm name
823811
Utf8Value algorithm_name(env->isolate(), args[offset]);
824812
std::string_view algorithm_str = algorithm_name.ToStringView();

β€Žsrc/crypto/crypto_hash.hβ€Ž

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class Hash final : public BaseObject {
4242
};
4343

4444
structHashConfigfinal : public MemoryRetainer {
45-
CryptoJobMode mode;
4645
ByteSource in;
4746
constEVP_MD* digest;
4847
unsignedint length;
@@ -107,7 +106,6 @@ struct CShakeParams final {
107106
boolDeriveCShakeBits(const CShakeParams& params, ByteSource* out);
108107

109108
structCShakeConfigfinal : public MemoryRetainer {
110-
CryptoJobMode mode;
111109
ByteSource in;
112110
ByteSource function_name;
113111
ByteSource customization;

β€Žsrc/crypto/crypto_hkdf.ccβ€Ž

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ using v8::Value;
2020

2121
namespacecrypto {
2222
HKDFConfig::HKDFConfig(HKDFConfig&& other) noexcept
23-
: mode(other.mode),
24-
length(other.length),
23+
: length(other.length),
2524
digest(other.digest),
2625
key(std::move(other.key)),
2726
key_data(std::move(other.key_data)),
@@ -47,8 +46,6 @@ Maybe<void> HKDFTraits::AdditionalConfig(
4746
HKDFConfig* params) {
4847
Environment* env = Environment::GetCurrent(args);
4948

50-
params->mode = mode;
51-
5249
CHECK(args[offset]->IsString()); // Hash
5350
CHECK(KeyObjectHandle::HasInstance(env, args[offset + 1]) ||
5451
IsAnyBufferSource(args[offset + 1])); // Key
@@ -136,13 +133,12 @@ bool HKDFTraits::DeriveBits(Environment* env,
136133
}
137134

138135
voidHKDFConfig::MemoryInfo(MemoryTracker* tracker) const {
139-
if (key) tracker->TrackField("key", key);
140-
// If the job is sync, then the HKDFConfig does not own the data
141-
if (IsCryptoJobAsync(mode)) {
142-
if (!key) tracker->TrackFieldWithSize("key", key_data.size());
143-
tracker->TrackFieldWithSize("salt", salt.size());
144-
tracker->TrackFieldWithSize("info", info.size());
145-
}
136+
if (key)
137+
tracker->TrackField("key", key);
138+
else
139+
tracker->TraitTrackInline(key_data, "key");
140+
tracker->TraitTrackInline(salt, "salt");
141+
tracker->TraitTrackInline(info, "info");
146142
}
147143

148144
} // namespace crypto

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 782ad5d

Browse files
panvaaduh95
authored andcommitted
src: implement MemoryRetainer protocol for ByteSource
Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: #64660 Backport-PR-URL: #65087 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 4afc15b commit 782ad5d

32 files changed

Lines changed: 135 additions & 201 deletions

β€Žsrc/crypto/crypto_aes.ccβ€Ž

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,7 @@ void UseDefaultIV(AESCipherConfig* params) {
491491
} // namespace
492492

493493
AESCipherConfig::AESCipherConfig(AESCipherConfig&& other) noexcept
494-
: mode(other.mode),
495-
variant(other.variant),
494+
: variant(other.variant),
496495
cipher(other.cipher),
497496
length(other.length),
498497
iv(std::move(other.iv)),
@@ -505,12 +504,8 @@ AESCipherConfig& AESCipherConfig::operator=(AESCipherConfig&& other) noexcept {
505504
}
506505

507506
voidAESCipherConfig::MemoryInfo(MemoryTracker* tracker) const {
508-
// If mode is sync, then the data in each of these properties
509-
// is not owned by the AESCipherConfig, so we ignore it.
510-
if (IsCryptoJobAsync(mode)) {
511-
tracker->TrackFieldWithSize("iv", iv.size());
512-
tracker->TrackFieldWithSize("additional_data", additional_data.size());
513-
}
507+
tracker->TraitTrackInline(iv, "iv");
508+
tracker->TraitTrackInline(additional_data, "additional_data");
514509
}
515510

516511
Maybe<void> AESCipherTraits::AdditionalConfig(
@@ -521,8 +516,6 @@ Maybe<void> AESCipherTraits::AdditionalConfig(
521516
AESCipherConfig* params) {
522517
Environment* env = Environment::GetCurrent(args);
523518

524-
params->mode = mode;
525-
526519
CHECK(args[offset]->IsUint32()); // Key Variant
527520
params->variant =
528521
static_cast<AESKeyVariant>(args[offset].As<Uint32>()->Value());

β€Žsrc/crypto/crypto_aes.hβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ enum class AESKeyVariant {
5858
};
5959

6060
structAESCipherConfigfinal : public MemoryRetainer {
61-
CryptoJobMode mode;
6261
AESKeyVariant variant;
6362
ncrypto::Cipher cipher;
6463
size_t length;

β€Žsrc/crypto/crypto_argon2.ccβ€Ž

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ using v8::Uint32;
2121
using v8::Value;
2222

2323
Argon2Config::Argon2Config(Argon2Config&& other) noexcept
24-
: mode{other.mode},
25-
key{std::move(other.key)},
24+
: key{std::move(other.key)},
2625
pass{std::move(other.pass)},
2726
salt{std::move(other.salt)},
2827
secret{std::move(other.secret)},
@@ -40,13 +39,13 @@ Argon2Config& Argon2Config::operator=(Argon2Config&& other) noexcept {
4039
}
4140

4241
voidArgon2Config::MemoryInfo(MemoryTracker* tracker) const {
43-
if (key) tracker->TrackField("key", key);
44-
if (IsCryptoJobAsync(mode)) {
45-
if (!key) tracker->TrackFieldWithSize("pass", pass.size());
46-
tracker->TrackFieldWithSize("salt", salt.size());
47-
tracker->TrackFieldWithSize("secret", secret.size());
48-
tracker->TrackFieldWithSize("ad", ad.size());
49-
}
42+
if (key)
43+
tracker->TrackField("key", key);
44+
else
45+
tracker->TraitTrackInline(pass, "pass");
46+
tracker->TraitTrackInline(salt, "salt");
47+
tracker->TraitTrackInline(secret, "secret");
48+
tracker->TraitTrackInline(ad, "ad");
5049
}
5150

5251
MaybeLocal<Value> Argon2Traits::EncodeOutput(Environment* env,
@@ -62,8 +61,6 @@ Maybe<void> Argon2Traits::AdditionalConfig(
6261
Argon2Config* config) {
6362
Environment* env = Environment::GetCurrent(args);
6463

65-
config->mode = mode;
66-
6764
CHECK(KeyObjectHandle::HasInstance(env, args[offset]) ||
6865
IsAnyBufferSource(args[offset])); // pass
6966
ArrayBufferOrViewContents<char> salt(args[offset + 1]);

β€Žsrc/crypto/crypto_argon2.hβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ namespace node::crypto {
2222
// at least 16 bytes in length.
2323

2424
structArgon2Configfinal : public MemoryRetainer {
25-
CryptoJobMode mode;
2625
KeyObjectData key;
2726
ByteSource pass;
2827
ByteSource salt;

β€Žsrc/crypto/crypto_chacha20_poly1305.ccβ€Ž

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ bool ValidateAdditionalData(Environment* env,
8181

8282
ChaCha20Poly1305CipherConfig::ChaCha20Poly1305CipherConfig(
8383
ChaCha20Poly1305CipherConfig&& other) noexcept
84-
: mode(other.mode),
85-
cipher(other.cipher),
84+
: cipher(other.cipher),
8685
iv(std::move(other.iv)),
8786
additional_data(std::move(other.additional_data)) {}
8887

@@ -94,12 +93,8 @@ ChaCha20Poly1305CipherConfig& ChaCha20Poly1305CipherConfig::operator=(
9493
}
9594

9695
voidChaCha20Poly1305CipherConfig::MemoryInfo(MemoryTracker* tracker) const {
97-
// If mode is sync, then the data in each of these properties
98-
// is not owned by the ChaCha20Poly1305CipherConfig, so we ignore it.
99-
if (IsCryptoJobAsync(mode)) {
100-
tracker->TrackFieldWithSize("iv", iv.size());
101-
tracker->TrackFieldWithSize("additional_data", additional_data.size());
102-
}
96+
tracker->TraitTrackInline(iv, "iv");
97+
tracker->TraitTrackInline(additional_data, "additional_data");
10398
}
10499

105100
Maybe<void> ChaCha20Poly1305CipherTraits::AdditionalConfig(
@@ -110,7 +105,6 @@ Maybe<void> ChaCha20Poly1305CipherTraits::AdditionalConfig(
110105
ChaCha20Poly1305CipherConfig* params) {
111106
Environment* env = Environment::GetCurrent(args);
112107

113-
params->mode = mode;
114108
params->cipher = ncrypto::Cipher::CHACHA20_POLY1305;
115109

116110
#ifndef OPENSSL_IS_BORINGSSL

β€Žsrc/crypto/crypto_chacha20_poly1305.hβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ namespace node::crypto {
1313
constexprunsignedkChaCha20Poly1305AuthTagLength = 16;
1414

1515
structChaCha20Poly1305CipherConfigfinal : public MemoryRetainer {
16-
CryptoJobMode mode;
1716
ncrypto::Cipher cipher;
1817
ByteSource iv;
1918
ByteSource additional_data;

β€Žsrc/crypto/crypto_cipher.hβ€Ž

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,8 @@ class CipherJob final : public CryptoJob<CipherTraits> {
268268

269269
SET_SELF_SIZE(CipherJob)
270270
void MemoryInfo(MemoryTracker* tracker) constoverride {
271-
if (IsCryptoJobAsync(CryptoJob<CipherTraits>::mode()))
272-
tracker->TrackFieldWithSize("in", in_.size());
273-
tracker->TrackFieldWithSize("out", out_.size());
271+
tracker->TraitTrackInline(in_, "in");
272+
tracker->TraitTrackInline(out_, "out");
274273
CryptoJob<CipherTraits>::MemoryInfo(tracker);
275274
}
276275

β€Žsrc/crypto/crypto_hash.ccβ€Ž

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Hash::Hash(Environment* env, Local<Object> wrap) : BaseObject(env, wrap) {
5858

5959
voidHash::MemoryInfo(MemoryTracker* tracker) const {
6060
tracker->TrackFieldWithSize("mdctx", mdctx_ ? kSizeOf_EVP_MD_CTX : 0);
61-
tracker->TrackFieldWithSize("md", digest_ ? md_len_ : 0);
61+
tracker->TraitTrackInline(digest_, "md");
6262
}
6363

6464
#if NCRYPTO_USE_BORINGSSL_EVP_DO_ALL_FALLBACK
@@ -524,10 +524,7 @@ void Hash::HashDigest(const FunctionCallbackInfo<Value>& args) {
524524
}
525525

526526
HashConfig::HashConfig(HashConfig&& other) noexcept
527-
: mode(other.mode),
528-
in(std::move(other.in)),
529-
digest(other.digest),
530-
length(other.length) {}
527+
: in(std::move(other.in)), digest(other.digest), length(other.length) {}
531528

532529
HashConfig& HashConfig::operator=(HashConfig&& other) noexcept {
533530
if (&other == this) return *this;
@@ -536,8 +533,7 @@ HashConfig& HashConfig::operator=(HashConfig&& other) noexcept {
536533
}
537534

538535
voidHashConfig::MemoryInfo(MemoryTracker* tracker) const {
539-
// If the Job is sync, then the HashConfig does not own the data.
540-
if (IsCryptoJobAsync(mode)) tracker->TrackFieldWithSize("in", in.size());
536+
tracker->TraitTrackInline(in, "in");
541537
}
542538

543539
MaybeLocal<Value> HashTraits::EncodeOutput(Environment* env,
@@ -553,8 +549,6 @@ Maybe<void> HashTraits::AdditionalConfig(
553549
HashConfig* params) {
554550
Environment* env = Environment::GetCurrent(args);
555551

556-
params->mode = mode;
557-
558552
CHECK(args[offset]->IsString()); // Hash algorithm
559553
Utf8Value digest(env->isolate(), args[offset]);
560554
params->digest = ncrypto::getDigestByName(*digest);
@@ -782,8 +776,7 @@ bool DigestUpdateBytepad(ncrypto::EVPMDCtxPointer* ctx,
782776
} // namespace
783777

784778
CShakeConfig::CShakeConfig(CShakeConfig&& other) noexcept
785-
: mode(other.mode),
786-
in(std::move(other.in)),
779+
: in(std::move(other.in)),
787780
function_name(std::move(other.function_name)),
788781
customization(std::move(other.customization)),
789782
variant(other.variant),
@@ -796,12 +789,9 @@ CShakeConfig& CShakeConfig::operator=(CShakeConfig&& other) noexcept {
796789
}
797790

798791
voidCShakeConfig::MemoryInfo(MemoryTracker* tracker) const {
799-
// If the Job is sync, then the CShakeConfig does not own the data.
800-
if (IsCryptoJobAsync(mode)) {
801-
tracker->TrackFieldWithSize("in", in.size());
802-
tracker->TrackFieldWithSize("function_name", function_name.size());
803-
tracker->TrackFieldWithSize("customization", customization.size());
804-
}
792+
tracker->TraitTrackInline(in, "in");
793+
tracker->TraitTrackInline(function_name, "function_name");
794+
tracker->TraitTrackInline(customization, "customization");
805795
}
806796

807797
MaybeLocal<Value> CShakeTraits::EncodeOutput(Environment* env,
@@ -817,8 +807,6 @@ Maybe<void> CShakeTraits::AdditionalConfig(
817807
CShakeConfig* params) {
818808
Environment* env = Environment::GetCurrent(args);
819809

820-
params->mode = mode;
821-
822810
CHECK(args[offset]->IsString()); // Algorithm name
823811
Utf8Value algorithm_name(env->isolate(), args[offset]);
824812
std::string_view algorithm_str = algorithm_name.ToStringView();

β€Žsrc/crypto/crypto_hash.hβ€Ž

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class Hash final : public BaseObject {
4242
};
4343

4444
structHashConfigfinal : public MemoryRetainer {
45-
CryptoJobMode mode;
4645
ByteSource in;
4746
constEVP_MD* digest;
4847
unsignedint length;
@@ -107,7 +106,6 @@ struct CShakeParams final {
107106
boolDeriveCShakeBits(const CShakeParams& params, ByteSource* out);
108107

109108
structCShakeConfigfinal : public MemoryRetainer {
110-
CryptoJobMode mode;
111109
ByteSource in;
112110
ByteSource function_name;
113111
ByteSource customization;

β€Žsrc/crypto/crypto_hkdf.ccβ€Ž

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ using v8::Value;
2020

2121
namespacecrypto {
2222
HKDFConfig::HKDFConfig(HKDFConfig&& other) noexcept
23-
: mode(other.mode),
24-
length(other.length),
23+
: length(other.length),
2524
digest(other.digest),
2625
key(std::move(other.key)),
2726
key_data(std::move(other.key_data)),
@@ -47,8 +46,6 @@ Maybe<void> HKDFTraits::AdditionalConfig(
4746
HKDFConfig* params) {
4847
Environment* env = Environment::GetCurrent(args);
4948

50-
params->mode = mode;
51-
5249
CHECK(args[offset]->IsString()); // Hash
5350
CHECK(KeyObjectHandle::HasInstance(env, args[offset + 1]) ||
5451
IsAnyBufferSource(args[offset + 1])); // Key
@@ -136,13 +133,12 @@ bool HKDFTraits::DeriveBits(Environment* env,
136133
}
137134

138135
voidHKDFConfig::MemoryInfo(MemoryTracker* tracker) const {
139-
if (key) tracker->TrackField("key", key);
140-
// If the job is sync, then the HKDFConfig does not own the data
141-
if (IsCryptoJobAsync(mode)) {
142-
if (!key) tracker->TrackFieldWithSize("key", key_data.size());
143-
tracker->TrackFieldWithSize("salt", salt.size());
144-
tracker->TrackFieldWithSize("info", info.size());
145-
}
136+
if (key)
137+
tracker->TrackField("key", key);
138+
else
139+
tracker->TraitTrackInline(key_data, "key");
140+
tracker->TraitTrackInline(salt, "salt");
141+
tracker->TraitTrackInline(info, "info");
146142
}
147143

148144
} // namespace crypto

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 782ad5d

Browse files
panvaaduh95
authored andcommitted
src: implement MemoryRetainer protocol for ByteSource
Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: #64660 Backport-PR-URL: #65087 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 4afc15b commit 782ad5d

32 files changed

Lines changed: 135 additions & 201 deletions

β€Žsrc/crypto/crypto_aes.ccβ€Ž

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,7 @@ void UseDefaultIV(AESCipherConfig* params) {
491491
} // namespace
492492

493493
AESCipherConfig::AESCipherConfig(AESCipherConfig&& other) noexcept
494-
: mode(other.mode),
495-
variant(other.variant),
494+
: variant(other.variant),
496495
cipher(other.cipher),
497496
length(other.length),
498497
iv(std::move(other.iv)),
@@ -505,12 +504,8 @@ AESCipherConfig& AESCipherConfig::operator=(AESCipherConfig&& other) noexcept {
505504
}
506505

507506
voidAESCipherConfig::MemoryInfo(MemoryTracker* tracker) const {
508-
// If mode is sync, then the data in each of these properties
509-
// is not owned by the AESCipherConfig, so we ignore it.
510-
if (IsCryptoJobAsync(mode)) {
511-
tracker->TrackFieldWithSize("iv", iv.size());
512-
tracker->TrackFieldWithSize("additional_data", additional_data.size());
513-
}
507+
tracker->TraitTrackInline(iv, "iv");
508+
tracker->TraitTrackInline(additional_data, "additional_data");
514509
}
515510

516511
Maybe<void> AESCipherTraits::AdditionalConfig(
@@ -521,8 +516,6 @@ Maybe<void> AESCipherTraits::AdditionalConfig(
521516
AESCipherConfig* params) {
522517
Environment* env = Environment::GetCurrent(args);
523518

524-
params->mode = mode;
525-
526519
CHECK(args[offset]->IsUint32()); // Key Variant
527520
params->variant =
528521
static_cast<AESKeyVariant>(args[offset].As<Uint32>()->Value());

β€Žsrc/crypto/crypto_aes.hβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ enum class AESKeyVariant {
5858
};
5959

6060
structAESCipherConfigfinal : public MemoryRetainer {
61-
CryptoJobMode mode;
6261
AESKeyVariant variant;
6362
ncrypto::Cipher cipher;
6463
size_t length;

β€Žsrc/crypto/crypto_argon2.ccβ€Ž

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ using v8::Uint32;
2121
using v8::Value;
2222

2323
Argon2Config::Argon2Config(Argon2Config&& other) noexcept
24-
: mode{other.mode},
25-
key{std::move(other.key)},
24+
: key{std::move(other.key)},
2625
pass{std::move(other.pass)},
2726
salt{std::move(other.salt)},
2827
secret{std::move(other.secret)},
@@ -40,13 +39,13 @@ Argon2Config& Argon2Config::operator=(Argon2Config&& other) noexcept {
4039
}
4140

4241
voidArgon2Config::MemoryInfo(MemoryTracker* tracker) const {
43-
if (key) tracker->TrackField("key", key);
44-
if (IsCryptoJobAsync(mode)) {
45-
if (!key) tracker->TrackFieldWithSize("pass", pass.size());
46-
tracker->TrackFieldWithSize("salt", salt.size());
47-
tracker->TrackFieldWithSize("secret", secret.size());
48-
tracker->TrackFieldWithSize("ad", ad.size());
49-
}
42+
if (key)
43+
tracker->TrackField("key", key);
44+
else
45+
tracker->TraitTrackInline(pass, "pass");
46+
tracker->TraitTrackInline(salt, "salt");
47+
tracker->TraitTrackInline(secret, "secret");
48+
tracker->TraitTrackInline(ad, "ad");
5049
}
5150

5251
MaybeLocal<Value> Argon2Traits::EncodeOutput(Environment* env,
@@ -62,8 +61,6 @@ Maybe<void> Argon2Traits::AdditionalConfig(
6261
Argon2Config* config) {
6362
Environment* env = Environment::GetCurrent(args);
6463

65-
config->mode = mode;
66-
6764
CHECK(KeyObjectHandle::HasInstance(env, args[offset]) ||
6865
IsAnyBufferSource(args[offset])); // pass
6966
ArrayBufferOrViewContents<char> salt(args[offset + 1]);

β€Žsrc/crypto/crypto_argon2.hβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ namespace node::crypto {
2222
// at least 16 bytes in length.
2323

2424
structArgon2Configfinal : public MemoryRetainer {
25-
CryptoJobMode mode;
2625
KeyObjectData key;
2726
ByteSource pass;
2827
ByteSource salt;

β€Žsrc/crypto/crypto_chacha20_poly1305.ccβ€Ž

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ bool ValidateAdditionalData(Environment* env,
8181

8282
ChaCha20Poly1305CipherConfig::ChaCha20Poly1305CipherConfig(
8383
ChaCha20Poly1305CipherConfig&& other) noexcept
84-
: mode(other.mode),
85-
cipher(other.cipher),
84+
: cipher(other.cipher),
8685
iv(std::move(other.iv)),
8786
additional_data(std::move(other.additional_data)) {}
8887

@@ -94,12 +93,8 @@ ChaCha20Poly1305CipherConfig& ChaCha20Poly1305CipherConfig::operator=(
9493
}
9594

9695
voidChaCha20Poly1305CipherConfig::MemoryInfo(MemoryTracker* tracker) const {
97-
// If mode is sync, then the data in each of these properties
98-
// is not owned by the ChaCha20Poly1305CipherConfig, so we ignore it.
99-
if (IsCryptoJobAsync(mode)) {
100-
tracker->TrackFieldWithSize("iv", iv.size());
101-
tracker->TrackFieldWithSize("additional_data", additional_data.size());
102-
}
96+
tracker->TraitTrackInline(iv, "iv");
97+
tracker->TraitTrackInline(additional_data, "additional_data");
10398
}
10499

105100
Maybe<void> ChaCha20Poly1305CipherTraits::AdditionalConfig(
@@ -110,7 +105,6 @@ Maybe<void> ChaCha20Poly1305CipherTraits::AdditionalConfig(
110105
ChaCha20Poly1305CipherConfig* params) {
111106
Environment* env = Environment::GetCurrent(args);
112107

113-
params->mode = mode;
114108
params->cipher = ncrypto::Cipher::CHACHA20_POLY1305;
115109

116110
#ifndef OPENSSL_IS_BORINGSSL

β€Žsrc/crypto/crypto_chacha20_poly1305.hβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ namespace node::crypto {
1313
constexprunsignedkChaCha20Poly1305AuthTagLength = 16;
1414

1515
structChaCha20Poly1305CipherConfigfinal : public MemoryRetainer {
16-
CryptoJobMode mode;
1716
ncrypto::Cipher cipher;
1817
ByteSource iv;
1918
ByteSource additional_data;

β€Žsrc/crypto/crypto_cipher.hβ€Ž

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,8 @@ class CipherJob final : public CryptoJob<CipherTraits> {
268268

269269
SET_SELF_SIZE(CipherJob)
270270
void MemoryInfo(MemoryTracker* tracker) constoverride {
271-
if (IsCryptoJobAsync(CryptoJob<CipherTraits>::mode()))
272-
tracker->TrackFieldWithSize("in", in_.size());
273-
tracker->TrackFieldWithSize("out", out_.size());
271+
tracker->TraitTrackInline(in_, "in");
272+
tracker->TraitTrackInline(out_, "out");
274273
CryptoJob<CipherTraits>::MemoryInfo(tracker);
275274
}
276275

β€Žsrc/crypto/crypto_hash.ccβ€Ž

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Hash::Hash(Environment* env, Local<Object> wrap) : BaseObject(env, wrap) {
5858

5959
voidHash::MemoryInfo(MemoryTracker* tracker) const {
6060
tracker->TrackFieldWithSize("mdctx", mdctx_ ? kSizeOf_EVP_MD_CTX : 0);
61-
tracker->TrackFieldWithSize("md", digest_ ? md_len_ : 0);
61+
tracker->TraitTrackInline(digest_, "md");
6262
}
6363

6464
#if NCRYPTO_USE_BORINGSSL_EVP_DO_ALL_FALLBACK
@@ -524,10 +524,7 @@ void Hash::HashDigest(const FunctionCallbackInfo<Value>& args) {
524524
}
525525

526526
HashConfig::HashConfig(HashConfig&& other) noexcept
527-
: mode(other.mode),
528-
in(std::move(other.in)),
529-
digest(other.digest),
530-
length(other.length) {}
527+
: in(std::move(other.in)), digest(other.digest), length(other.length) {}
531528

532529
HashConfig& HashConfig::operator=(HashConfig&& other) noexcept {
533530
if (&other == this) return *this;
@@ -536,8 +533,7 @@ HashConfig& HashConfig::operator=(HashConfig&& other) noexcept {
536533
}
537534

538535
voidHashConfig::MemoryInfo(MemoryTracker* tracker) const {
539-
// If the Job is sync, then the HashConfig does not own the data.
540-
if (IsCryptoJobAsync(mode)) tracker->TrackFieldWithSize("in", in.size());
536+
tracker->TraitTrackInline(in, "in");
541537
}
542538

543539
MaybeLocal<Value> HashTraits::EncodeOutput(Environment* env,
@@ -553,8 +549,6 @@ Maybe<void> HashTraits::AdditionalConfig(
553549
HashConfig* params) {
554550
Environment* env = Environment::GetCurrent(args);
555551

556-
params->mode = mode;
557-
558552
CHECK(args[offset]->IsString()); // Hash algorithm
559553
Utf8Value digest(env->isolate(), args[offset]);
560554
params->digest = ncrypto::getDigestByName(*digest);
@@ -782,8 +776,7 @@ bool DigestUpdateBytepad(ncrypto::EVPMDCtxPointer* ctx,
782776
} // namespace
783777

784778
CShakeConfig::CShakeConfig(CShakeConfig&& other) noexcept
785-
: mode(other.mode),
786-
in(std::move(other.in)),
779+
: in(std::move(other.in)),
787780
function_name(std::move(other.function_name)),
788781
customization(std::move(other.customization)),
789782
variant(other.variant),
@@ -796,12 +789,9 @@ CShakeConfig& CShakeConfig::operator=(CShakeConfig&& other) noexcept {
796789
}
797790

798791
voidCShakeConfig::MemoryInfo(MemoryTracker* tracker) const {
799-
// If the Job is sync, then the CShakeConfig does not own the data.
800-
if (IsCryptoJobAsync(mode)) {
801-
tracker->TrackFieldWithSize("in", in.size());
802-
tracker->TrackFieldWithSize("function_name", function_name.size());
803-
tracker->TrackFieldWithSize("customization", customization.size());
804-
}
792+
tracker->TraitTrackInline(in, "in");
793+
tracker->TraitTrackInline(function_name, "function_name");
794+
tracker->TraitTrackInline(customization, "customization");
805795
}
806796

807797
MaybeLocal<Value> CShakeTraits::EncodeOutput(Environment* env,
@@ -817,8 +807,6 @@ Maybe<void> CShakeTraits::AdditionalConfig(
817807
CShakeConfig* params) {
818808
Environment* env = Environment::GetCurrent(args);
819809

820-
params->mode = mode;
821-
822810
CHECK(args[offset]->IsString()); // Algorithm name
823811
Utf8Value algorithm_name(env->isolate(), args[offset]);
824812
std::string_view algorithm_str = algorithm_name.ToStringView();

β€Žsrc/crypto/crypto_hash.hβ€Ž

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class Hash final : public BaseObject {
4242
};
4343

4444
structHashConfigfinal : public MemoryRetainer {
45-
CryptoJobMode mode;
4645
ByteSource in;
4746
constEVP_MD* digest;
4847
unsignedint length;
@@ -107,7 +106,6 @@ struct CShakeParams final {
107106
boolDeriveCShakeBits(const CShakeParams& params, ByteSource* out);
108107

109108
structCShakeConfigfinal : public MemoryRetainer {
110-
CryptoJobMode mode;
111109
ByteSource in;
112110
ByteSource function_name;
113111
ByteSource customization;

β€Žsrc/crypto/crypto_hkdf.ccβ€Ž

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ using v8::Value;
2020

2121
namespacecrypto {
2222
HKDFConfig::HKDFConfig(HKDFConfig&& other) noexcept
23-
: mode(other.mode),
24-
length(other.length),
23+
: length(other.length),
2524
digest(other.digest),
2625
key(std::move(other.key)),
2726
key_data(std::move(other.key_data)),
@@ -47,8 +46,6 @@ Maybe<void> HKDFTraits::AdditionalConfig(
4746
HKDFConfig* params) {
4847
Environment* env = Environment::GetCurrent(args);
4948

50-
params->mode = mode;
51-
5249
CHECK(args[offset]->IsString()); // Hash
5350
CHECK(KeyObjectHandle::HasInstance(env, args[offset + 1]) ||
5451
IsAnyBufferSource(args[offset + 1])); // Key
@@ -136,13 +133,12 @@ bool HKDFTraits::DeriveBits(Environment* env,
136133
}
137134

138135
voidHKDFConfig::MemoryInfo(MemoryTracker* tracker) const {
139-
if (key) tracker->TrackField("key", key);
140-
// If the job is sync, then the HKDFConfig does not own the data
141-
if (IsCryptoJobAsync(mode)) {
142-
if (!key) tracker->TrackFieldWithSize("key", key_data.size());
143-
tracker->TrackFieldWithSize("salt", salt.size());
144-
tracker->TrackFieldWithSize("info", info.size());
145-
}
136+
if (key)
137+
tracker->TrackField("key", key);
138+
else
139+
tracker->TraitTrackInline(key_data, "key");
140+
tracker->TraitTrackInline(salt, "salt");
141+
tracker->TraitTrackInline(info, "info");
146142
}
147143

148144
} // namespace crypto

0 commit comments

Comments
Β (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Commit 782ad5d

Browse files
panvaaduh95
authored andcommitted
src: implement MemoryRetainer protocol for ByteSource
Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: #64660 Backport-PR-URL: #65087 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 4afc15b commit 782ad5d

32 files changed

Lines changed: 135 additions & 201 deletions

β€Žsrc/crypto/crypto_aes.ccβ€Ž

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,7 @@ void UseDefaultIV(AESCipherConfig* params) {
491491
} // namespace
492492

493493
AESCipherConfig::AESCipherConfig(AESCipherConfig&& other) noexcept
494-
: mode(other.mode),
495-
variant(other.variant),
494+
: variant(other.variant),
496495
cipher(other.cipher),
497496
length(other.length),
498497
iv(std::move(other.iv)),
@@ -505,12 +504,8 @@ AESCipherConfig& AESCipherConfig::operator=(AESCipherConfig&& other) noexcept {
505504
}
506505

507506
voidAESCipherConfig::MemoryInfo(MemoryTracker* tracker) const {
508-
// If mode is sync, then the data in each of these properties
509-
// is not owned by the AESCipherConfig, so we ignore it.
510-
if (IsCryptoJobAsync(mode)) {
511-
tracker->TrackFieldWithSize("iv", iv.size());
512-
tracker->TrackFieldWithSize("additional_data", additional_data.size());
513-
}
507+
tracker->TraitTrackInline(iv, "iv");
508+
tracker->TraitTrackInline(additional_data, "additional_data");
514509
}
515510

516511
Maybe<void> AESCipherTraits::AdditionalConfig(
@@ -521,8 +516,6 @@ Maybe<void> AESCipherTraits::AdditionalConfig(
521516
AESCipherConfig* params) {
522517
Environment* env = Environment::GetCurrent(args);
523518

524-
params->mode = mode;
525-
526519
CHECK(args[offset]->IsUint32()); // Key Variant
527520
params->variant =
528521
static_cast<AESKeyVariant>(args[offset].As<Uint32>()->Value());

β€Žsrc/crypto/crypto_aes.hβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ enum class AESKeyVariant {
5858
};
5959

6060
structAESCipherConfigfinal : public MemoryRetainer {
61-
CryptoJobMode mode;
6261
AESKeyVariant variant;
6362
ncrypto::Cipher cipher;
6463
size_t length;

β€Žsrc/crypto/crypto_argon2.ccβ€Ž

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ using v8::Uint32;
2121
using v8::Value;
2222

2323
Argon2Config::Argon2Config(Argon2Config&& other) noexcept
24-
: mode{other.mode},
25-
key{std::move(other.key)},
24+
: key{std::move(other.key)},
2625
pass{std::move(other.pass)},
2726
salt{std::move(other.salt)},
2827
secret{std::move(other.secret)},
@@ -40,13 +39,13 @@ Argon2Config& Argon2Config::operator=(Argon2Config&& other) noexcept {
4039
}
4140

4241
voidArgon2Config::MemoryInfo(MemoryTracker* tracker) const {
43-
if (key) tracker->TrackField("key", key);
44-
if (IsCryptoJobAsync(mode)) {
45-
if (!key) tracker->TrackFieldWithSize("pass", pass.size());
46-
tracker->TrackFieldWithSize("salt", salt.size());
47-
tracker->TrackFieldWithSize("secret", secret.size());
48-
tracker->TrackFieldWithSize("ad", ad.size());
49-
}
42+
if (key)
43+
tracker->TrackField("key", key);
44+
else
45+
tracker->TraitTrackInline(pass, "pass");
46+
tracker->TraitTrackInline(salt, "salt");
47+
tracker->TraitTrackInline(secret, "secret");
48+
tracker->TraitTrackInline(ad, "ad");
5049
}
5150

5251
MaybeLocal<Value> Argon2Traits::EncodeOutput(Environment* env,
@@ -62,8 +61,6 @@ Maybe<void> Argon2Traits::AdditionalConfig(
6261
Argon2Config* config) {
6362
Environment* env = Environment::GetCurrent(args);
6463

65-
config->mode = mode;
66-
6764
CHECK(KeyObjectHandle::HasInstance(env, args[offset]) ||
6865
IsAnyBufferSource(args[offset])); // pass
6966
ArrayBufferOrViewContents<char> salt(args[offset + 1]);

β€Žsrc/crypto/crypto_argon2.hβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ namespace node::crypto {
2222
// at least 16 bytes in length.
2323

2424
structArgon2Configfinal : public MemoryRetainer {
25-
CryptoJobMode mode;
2625
KeyObjectData key;
2726
ByteSource pass;
2827
ByteSource salt;

β€Žsrc/crypto/crypto_chacha20_poly1305.ccβ€Ž

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ bool ValidateAdditionalData(Environment* env,
8181

8282
ChaCha20Poly1305CipherConfig::ChaCha20Poly1305CipherConfig(
8383
ChaCha20Poly1305CipherConfig&& other) noexcept
84-
: mode(other.mode),
85-
cipher(other.cipher),
84+
: cipher(other.cipher),
8685
iv(std::move(other.iv)),
8786
additional_data(std::move(other.additional_data)) {}
8887

@@ -94,12 +93,8 @@ ChaCha20Poly1305CipherConfig& ChaCha20Poly1305CipherConfig::operator=(
9493
}
9594

9695
voidChaCha20Poly1305CipherConfig::MemoryInfo(MemoryTracker* tracker) const {
97-
// If mode is sync, then the data in each of these properties
98-
// is not owned by the ChaCha20Poly1305CipherConfig, so we ignore it.
99-
if (IsCryptoJobAsync(mode)) {
100-
tracker->TrackFieldWithSize("iv", iv.size());
101-
tracker->TrackFieldWithSize("additional_data", additional_data.size());
102-
}
96+
tracker->TraitTrackInline(iv, "iv");
97+
tracker->TraitTrackInline(additional_data, "additional_data");
10398
}
10499

105100
Maybe<void> ChaCha20Poly1305CipherTraits::AdditionalConfig(
@@ -110,7 +105,6 @@ Maybe<void> ChaCha20Poly1305CipherTraits::AdditionalConfig(
110105
ChaCha20Poly1305CipherConfig* params) {
111106
Environment* env = Environment::GetCurrent(args);
112107

113-
params->mode = mode;
114108
params->cipher = ncrypto::Cipher::CHACHA20_POLY1305;
115109

116110
#ifndef OPENSSL_IS_BORINGSSL

β€Žsrc/crypto/crypto_chacha20_poly1305.hβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ namespace node::crypto {
1313
constexprunsignedkChaCha20Poly1305AuthTagLength = 16;
1414

1515
structChaCha20Poly1305CipherConfigfinal : public MemoryRetainer {
16-
CryptoJobMode mode;
1716
ncrypto::Cipher cipher;
1817
ByteSource iv;
1918
ByteSource additional_data;

β€Žsrc/crypto/crypto_cipher.hβ€Ž

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,8 @@ class CipherJob final : public CryptoJob<CipherTraits> {
268268

269269
SET_SELF_SIZE(CipherJob)
270270
void MemoryInfo(MemoryTracker* tracker) constoverride {
271-
if (IsCryptoJobAsync(CryptoJob<CipherTraits>::mode()))
272-
tracker->TrackFieldWithSize("in", in_.size());
273-
tracker->TrackFieldWithSize("out", out_.size());
271+
tracker->TraitTrackInline(in_, "in");
272+
tracker->TraitTrackInline(out_, "out");
274273
CryptoJob<CipherTraits>::MemoryInfo(tracker);
275274
}
276275

β€Žsrc/crypto/crypto_hash.ccβ€Ž

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Hash::Hash(Environment* env, Local<Object> wrap) : BaseObject(env, wrap) {
5858

5959
voidHash::MemoryInfo(MemoryTracker* tracker) const {
6060
tracker->TrackFieldWithSize("mdctx", mdctx_ ? kSizeOf_EVP_MD_CTX : 0);
61-
tracker->TrackFieldWithSize("md", digest_ ? md_len_ : 0);
61+
tracker->TraitTrackInline(digest_, "md");
6262
}
6363

6464
#if NCRYPTO_USE_BORINGSSL_EVP_DO_ALL_FALLBACK
@@ -524,10 +524,7 @@ void Hash::HashDigest(const FunctionCallbackInfo<Value>& args) {
524524
}
525525

526526
HashConfig::HashConfig(HashConfig&& other) noexcept
527-
: mode(other.mode),
528-
in(std::move(other.in)),
529-
digest(other.digest),
530-
length(other.length) {}
527+
: in(std::move(other.in)), digest(other.digest), length(other.length) {}
531528

532529
HashConfig& HashConfig::operator=(HashConfig&& other) noexcept {
533530
if (&other == this) return *this;
@@ -536,8 +533,7 @@ HashConfig& HashConfig::operator=(HashConfig&& other) noexcept {
536533
}
537534

538535
voidHashConfig::MemoryInfo(MemoryTracker* tracker) const {
539-
// If the Job is sync, then the HashConfig does not own the data.
540-
if (IsCryptoJobAsync(mode)) tracker->TrackFieldWithSize("in", in.size());
536+
tracker->TraitTrackInline(in, "in");
541537
}
542538

543539
MaybeLocal<Value> HashTraits::EncodeOutput(Environment* env,
@@ -553,8 +549,6 @@ Maybe<void> HashTraits::AdditionalConfig(
553549
HashConfig* params) {
554550
Environment* env = Environment::GetCurrent(args);
555551

556-
params->mode = mode;
557-
558552
CHECK(args[offset]->IsString()); // Hash algorithm
559553
Utf8Value digest(env->isolate(), args[offset]);
560554
params->digest = ncrypto::getDigestByName(*digest);
@@ -782,8 +776,7 @@ bool DigestUpdateBytepad(ncrypto::EVPMDCtxPointer* ctx,
782776
} // namespace
783777

784778
CShakeConfig::CShakeConfig(CShakeConfig&& other) noexcept
785-
: mode(other.mode),
786-
in(std::move(other.in)),
779+
: in(std::move(other.in)),
787780
function_name(std::move(other.function_name)),
788781
customization(std::move(other.customization)),
789782
variant(other.variant),
@@ -796,12 +789,9 @@ CShakeConfig& CShakeConfig::operator=(CShakeConfig&& other) noexcept {
796789
}
797790

798791
voidCShakeConfig::MemoryInfo(MemoryTracker* tracker) const {
799-
// If the Job is sync, then the CShakeConfig does not own the data.
800-
if (IsCryptoJobAsync(mode)) {
801-
tracker->TrackFieldWithSize("in", in.size());
802-
tracker->TrackFieldWithSize("function_name", function_name.size());
803-
tracker->TrackFieldWithSize("customization", customization.size());
804-
}
792+
tracker->TraitTrackInline(in, "in");
793+
tracker->TraitTrackInline(function_name, "function_name");
794+
tracker->TraitTrackInline(customization, "customization");
805795
}
806796

807797
MaybeLocal<Value> CShakeTraits::EncodeOutput(Environment* env,
@@ -817,8 +807,6 @@ Maybe<void> CShakeTraits::AdditionalConfig(
817807
CShakeConfig* params) {
818808
Environment* env = Environment::GetCurrent(args);
819809

820-
params->mode = mode;
821-
822810
CHECK(args[offset]->IsString()); // Algorithm name
823811
Utf8Value algorithm_name(env->isolate(), args[offset]);
824812
std::string_view algorithm_str = algorithm_name.ToStringView();

β€Žsrc/crypto/crypto_hash.hβ€Ž

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class Hash final : public BaseObject {
4242
};
4343

4444
structHashConfigfinal : public MemoryRetainer {
45-
CryptoJobMode mode;
4645
ByteSource in;
4746
constEVP_MD* digest;
4847
unsignedint length;
@@ -107,7 +106,6 @@ struct CShakeParams final {
107106
boolDeriveCShakeBits(const CShakeParams& params, ByteSource* out);
108107

109108
structCShakeConfigfinal : public MemoryRetainer {
110-
CryptoJobMode mode;
111109
ByteSource in;
112110
ByteSource function_name;
113111
ByteSource customization;

β€Žsrc/crypto/crypto_hkdf.ccβ€Ž

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ using v8::Value;
2020

2121
namespacecrypto {
2222
HKDFConfig::HKDFConfig(HKDFConfig&& other) noexcept
23-
: mode(other.mode),
24-
length(other.length),
23+
: length(other.length),
2524
digest(other.digest),
2625
key(std::move(other.key)),
2726
key_data(std::move(other.key_data)),
@@ -47,8 +46,6 @@ Maybe<void> HKDFTraits::AdditionalConfig(
4746
HKDFConfig* params) {
4847
Environment* env = Environment::GetCurrent(args);
4948

50-
params->mode = mode;
51-
5249
CHECK(args[offset]->IsString()); // Hash
5350
CHECK(KeyObjectHandle::HasInstance(env, args[offset + 1]) ||
5451
IsAnyBufferSource(args[offset + 1])); // Key
@@ -136,13 +133,12 @@ bool HKDFTraits::DeriveBits(Environment* env,
136133
}
137134

138135
voidHKDFConfig::MemoryInfo(MemoryTracker* tracker) const {
139-
if (key) tracker->TrackField("key", key);
140-
// If the job is sync, then the HKDFConfig does not own the data
141-
if (IsCryptoJobAsync(mode)) {
142-
if (!key) tracker->TrackFieldWithSize("key", key_data.size());
143-
tracker->TrackFieldWithSize("salt", salt.size());
144-
tracker->TrackFieldWithSize("info", info.size());
145-
}
136+
if (key)
137+
tracker->TrackField("key", key);
138+
else
139+
tracker->TraitTrackInline(key_data, "key");
140+
tracker->TraitTrackInline(salt, "salt");
141+
tracker->TraitTrackInline(info, "info");
146142
}
147143

148144
} // namespace crypto

0 commit comments

Comments
Β (0)