Skip to content

Commit

Permalink
fix hash size for component
Browse files Browse the repository at this point in the history
  • Loading branch information
bridiver authored and petemill committed Jan 27, 2020
1 parent 278fb27 commit 2d86102
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
1 change: 0 additions & 1 deletion components/ntp_sponsored_images/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ static_library("browser") {
"//brave/components/brave_rewards/common",
"//brave/components/brave_component_updater/browser",
"//components/component_updater",
"//components/crx_file",
"//components/keyed_service/core",
"//components/prefs",
"//content/public/browser",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@
#include "brave/components/ntp_sponsored_images/browser/regional_component_data.h"
#include "components/component_updater/component_installer.h"
#include "components/component_updater/component_updater_service.h"
#include "components/crx_file/id_util.h"
#include "crypto/sha2.h"

using brave_component_updater::BraveOnDemandUpdater;
using crx_file::id_util::kIdSize;

namespace {

constexpr char kNTPSponsoredImagesDisplayName[] = "NTP sponsored images";
constexpr char kNTPSponsoredImagesBaseDirectory[] = "NTPSponsoredImages";
constexpr size_t kHashSize = 32;

class NTPSponsoredImagesComponentInstallerPolicy
: public component_updater::ComponentInstallerPolicy {
Expand Down Expand Up @@ -56,7 +55,7 @@ class NTPSponsoredImagesComponentInstallerPolicy

private:
OnComponentReadyCallback ready_callback_;
uint8_t component_hash_[16];
uint8_t component_hash_[kHashSize];

DISALLOW_COPY_AND_ASSIGN(NTPSponsoredImagesComponentInstallerPolicy);
};
Expand All @@ -68,7 +67,7 @@ NTPSponsoredImagesComponentInstallerPolicy(
// Generate hash from public key.
std::string decoded_public_key;
base::Base64Decode(data.component_base64_public_key, &decoded_public_key);
crypto::SHA256HashString(decoded_public_key, component_hash_, kIdSize);
crypto::SHA256HashString(decoded_public_key, component_hash_, kHashSize);
}

NTPSponsoredImagesComponentInstallerPolicy::
Expand Down Expand Up @@ -113,7 +112,7 @@ base::FilePath NTPSponsoredImagesComponentInstallerPolicy::

void NTPSponsoredImagesComponentInstallerPolicy::GetHash(
std::vector<uint8_t>* hash) const {
hash->assign(component_hash_, component_hash_ + kIdSize);
hash->assign(component_hash_, component_hash_ + kHashSize);
}

std::string NTPSponsoredImagesComponentInstallerPolicy::GetName() const {
Expand Down

0 comments on commit 2d86102

Please sign in to comment.