Skip to content

Commit

Permalink
src: remove KeyObjectData::symmetric_key_len_
Browse files Browse the repository at this point in the history
symmetric_key_len_ is always equal to symmetric_key_.size(). Storing it
separately is redundant and has no significant benefit.

PR-URL: #44346
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
  • Loading branch information
tniessen authored and juanarbol committed Oct 11, 2022
1 parent be863b7 commit a6ce1de
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
15 changes: 4 additions & 11 deletions src/crypto/crypto_keys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -838,20 +838,13 @@ ManagedEVPPKey ManagedEVPPKey::GetParsedKey(Environment* env,
return ManagedEVPPKey(std::move(pkey));
}

KeyObjectData::KeyObjectData(
ByteSource symmetric_key)
KeyObjectData::KeyObjectData(ByteSource symmetric_key)
: key_type_(KeyType::kKeyTypeSecret),
symmetric_key_(std::move(symmetric_key)),
symmetric_key_len_(symmetric_key_.size()),
asymmetric_key_() {}

KeyObjectData::KeyObjectData(
KeyType type,
const ManagedEVPPKey& pkey)
: key_type_(type),
symmetric_key_(),
symmetric_key_len_(0),
asymmetric_key_{pkey} {}
KeyObjectData::KeyObjectData(KeyType type, const ManagedEVPPKey& pkey)
: key_type_(type), symmetric_key_(), asymmetric_key_{pkey} {}

void KeyObjectData::MemoryInfo(MemoryTracker* tracker) const {
switch (GetKeyType()) {
Expand Down Expand Up @@ -896,7 +889,7 @@ const char* KeyObjectData::GetSymmetricKey() const {

size_t KeyObjectData::GetSymmetricKeySize() const {
CHECK_EQ(key_type_, kKeyTypeSecret);
return symmetric_key_len_;
return symmetric_key_.size();
}

v8::Local<v8::Function> KeyObjectHandle::Initialize(Environment* env) {
Expand Down
1 change: 0 additions & 1 deletion src/crypto/crypto_keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ class KeyObjectData : public MemoryRetainer {

const KeyType key_type_;
const ByteSource symmetric_key_;
const unsigned int symmetric_key_len_;
const ManagedEVPPKey asymmetric_key_;
};

Expand Down

0 comments on commit a6ce1de

Please sign in to comment.