refactor: convert HashAlgorithm to enum class (#38233)
This commit is contained in:
parent
3dbc0a365f
commit
88a9962e22
6 changed files with 12 additions and 12 deletions
|
@ -46,11 +46,11 @@ void AsarFileValidator::OnRead(base::span<char> buffer,
|
|||
if (!current_hash_) {
|
||||
current_hash_byte_count_ = 0;
|
||||
switch (integrity_.algorithm) {
|
||||
case HashAlgorithm::SHA256:
|
||||
case HashAlgorithm::kSHA256:
|
||||
current_hash_ =
|
||||
crypto::SecureHash::Create(crypto::SecureHash::SHA256);
|
||||
break;
|
||||
case HashAlgorithm::NONE:
|
||||
case HashAlgorithm::kNone:
|
||||
CHECK(false);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -89,10 +89,10 @@ class Archive : public node::ObjectWrap {
|
|||
gin_helper::Dictionary integrity(isolate, v8::Object::New(isolate));
|
||||
asar::HashAlgorithm algorithm = info.integrity.value().algorithm;
|
||||
switch (algorithm) {
|
||||
case asar::HashAlgorithm::SHA256:
|
||||
case asar::HashAlgorithm::kSHA256:
|
||||
integrity.Set("algorithm", "SHA256");
|
||||
break;
|
||||
case asar::HashAlgorithm::NONE:
|
||||
case asar::HashAlgorithm::kNone:
|
||||
CHECK(false);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -138,7 +138,7 @@ bool FillFileInfoWithNode(Archive::FileInfo* info,
|
|||
}
|
||||
}
|
||||
if (*algorithm == "SHA256") {
|
||||
integrity_payload.algorithm = HashAlgorithm::SHA256;
|
||||
integrity_payload.algorithm = HashAlgorithm::kSHA256;
|
||||
info->integrity = std::move(integrity_payload);
|
||||
}
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ bool FillFileInfoWithNode(Archive::FileInfo* info,
|
|||
} // namespace
|
||||
|
||||
IntegrityPayload::IntegrityPayload()
|
||||
: algorithm(HashAlgorithm::NONE), block_size(0) {}
|
||||
: algorithm(HashAlgorithm::kNone), block_size(0) {}
|
||||
IntegrityPayload::~IntegrityPayload() = default;
|
||||
IntegrityPayload::IntegrityPayload(const IntegrityPayload& other) = default;
|
||||
|
||||
|
@ -252,7 +252,7 @@ bool Archive::Init() {
|
|||
// Currently we only support the sha256 algorithm, we can add support for
|
||||
// more below ensure we read them in preference order from most secure to
|
||||
// least
|
||||
if (integrity.value().algorithm != HashAlgorithm::NONE) {
|
||||
if (integrity.value().algorithm != HashAlgorithm::kNone) {
|
||||
ValidateIntegrityOrDie(header.c_str(), header.length(),
|
||||
integrity.value());
|
||||
} else {
|
||||
|
|
|
@ -20,9 +20,9 @@ namespace asar {
|
|||
|
||||
class ScopedTemporaryFile;
|
||||
|
||||
enum HashAlgorithm {
|
||||
SHA256,
|
||||
NONE,
|
||||
enum class HashAlgorithm {
|
||||
kSHA256,
|
||||
kNone,
|
||||
};
|
||||
|
||||
struct IntegrityPayload {
|
||||
|
|
|
@ -56,7 +56,7 @@ absl::optional<IntegrityPayload> Archive::HeaderIntegrity() const {
|
|||
NSString* hash = [integrity_payload objectForKey:@"hash"];
|
||||
if (algorithm && hash && [algorithm isEqualToString:@"SHA256"]) {
|
||||
IntegrityPayload header_integrity;
|
||||
header_integrity.algorithm = HashAlgorithm::SHA256;
|
||||
header_integrity.algorithm = HashAlgorithm::kSHA256;
|
||||
header_integrity.hash = base::SysNSStringToUTF8(hash);
|
||||
return header_integrity;
|
||||
}
|
||||
|
|
|
@ -152,7 +152,7 @@ bool ReadFileToString(const base::FilePath& path, std::string* contents) {
|
|||
void ValidateIntegrityOrDie(const char* data,
|
||||
size_t size,
|
||||
const IntegrityPayload& integrity) {
|
||||
if (integrity.algorithm == HashAlgorithm::SHA256) {
|
||||
if (integrity.algorithm == HashAlgorithm::kSHA256) {
|
||||
uint8_t hash[crypto::kSHA256Length];
|
||||
auto hasher = crypto::SecureHash::Create(crypto::SecureHash::SHA256);
|
||||
hasher->Update(data, size);
|
||||
|
|
Loading…
Reference in a new issue