Run clang-format on missed files It turnes out I missed a few files when doing the merge (crrev.com/c/2363183). Hopefully these are the last of them. No manual changes. Just clang-format on a copy in platform2/verity and rsynced back to platform/verity. BUG=chromium:886953 TEST=CQ passes Change-Id: Ib28f34bd23f19185770873dca9c5ef0b9549e634 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/dm-verity/+/2363568 Tested-by: Amin Hassani <ahassani@chromium.org> Auto-Submit: Amin Hassani <ahassani@chromium.org> Reviewed-by: Mike Frysinger <vapier@chromium.org> Reviewed-by: Jorge Lucangeli Obes <jorgelo@chromium.org> Commit-Queue: Amin Hassani <ahassani@chromium.org>
diff --git a/dm-bht.h b/dm-bht.h index eac9663..0a4b2b2 100644 --- a/dm-bht.h +++ b/dm-bht.h
@@ -20,14 +20,14 @@ * max to use for now. */ #define DM_BHT_MAX_DIGEST_SIZE 128 /* 1k hashes are unlikely for now */ -#define DM_BHT_SALT_SIZE 32 /* 256 bits of salt is a lot */ +#define DM_BHT_SALT_SIZE 32 /* 256 bits of salt is a lot */ /* UNALLOCATED, PENDING, READY, and VERIFIED are valid states. All other * values are entry-related return codes. */ -#define DM_BHT_ENTRY_VERIFIED 8 /* 'nodes' has been checked against parent */ -#define DM_BHT_ENTRY_READY 4 /* 'nodes' is loaded and available */ -#define DM_BHT_ENTRY_PENDING 2 /* 'nodes' is being loaded */ +#define DM_BHT_ENTRY_VERIFIED 8 /* 'nodes' has been checked against parent */ +#define DM_BHT_ENTRY_READY 4 /* 'nodes' is loaded and available */ +#define DM_BHT_ENTRY_PENDING 2 /* 'nodes' is being loaded */ #define DM_BHT_ENTRY_UNALLOCATED 0 /* untouched */ #define DM_BHT_ENTRY_ERROR -1 /* entry is unsuitable for use */ #define DM_BHT_ENTRY_ERROR_IO -2 /* I/O error on load */
diff --git a/file_hasher_unittest.cc b/file_hasher_unittest.cc index 84b2360..f13b054 100644 --- a/file_hasher_unittest.cc +++ b/file_hasher_unittest.cc
@@ -12,8 +12,8 @@ #include "verity/simple_file/mock_file.h" #include "verity/utils.h" -using ::testing::_; // wildcard mock matcher -using ::testing::AtLeast; // Times modifier +using ::testing::_; // wildcard mock matcher +using ::testing::AtLeast; // Times modifier using ::testing::DefaultValue; // allow for easy default return value change using ::testing::InSequence; using ::testing::Invoke; // mock Invoke action @@ -21,9 +21,8 @@ class FileHasherTest : public ::testing::Test { public: - FileHasherTest() : - src_(new simple_file::MockFile()), - dst_(new simple_file::MockFile()) { } + FileHasherTest() + : src_(new simple_file::MockFile()), dst_(new simple_file::MockFile()) {} ~FileHasherTest() { delete src_; delete dst_; @@ -35,24 +34,24 @@ delete hasher_; hasher_ = new verity::FileHasher(); } + protected: - simple_file::MockFile *src_; - simple_file::MockFile *dst_; - verity::FileHasher *hasher_; + simple_file::MockFile* src_; + simple_file::MockFile* dst_; + verity::FileHasher* hasher_; }; MATCHER_P(DigestMatch, a, "given hexdigest matches binary digest arg") { - static char last_digest_match[256] = { 0 }; - char *hexdigest = new char[strlen(a) + 1]; - verity_utils::to_hex(hexdigest, arg, strlen(a)/2); + static char last_digest_match[256] = {0}; + char* hexdigest = new char[strlen(a) + 1]; + verity_utils::to_hex(hexdigest, arg, strlen(a) / 2); bool ok = !strcmp(a, hexdigest); - LOG(INFO) << "DigestMatcher: " - << hexdigest << (ok? " == " : " != ") << a; - delete [] hexdigest; + LOG(INFO) << "DigestMatcher: " << hexdigest << (ok ? " == " : " != ") << a; + delete[] hexdigest; // Store this away globally so we can easily re use it. // Later this needs to be supported by a MockFile. - if (sizeof(last_digest_match) > strlen(a)/2) { - memcpy(last_digest_match, arg, strlen(a)/2); + if (sizeof(last_digest_match) > strlen(a) / 2) { + memcpy(last_digest_match, arg, strlen(a) / 2); } return ok; }
diff --git a/simple_file/env.cc b/simple_file/env.cc index bb8b0a6..5ecaee9 100644 --- a/simple_file/env.cc +++ b/simple_file/env.cc
@@ -7,6 +7,6 @@ namespace simple_file { -Env::Env() { } +Env::Env() {} } // namespace simple_file
diff --git a/simple_file/file.cc b/simple_file/file.cc index c4a672b..ed3dca3 100644 --- a/simple_file/file.cc +++ b/simple_file/file.cc
@@ -7,16 +7,14 @@ namespace simple_file { -const Env *File::env() const { +const Env* File::env() const { if (env_) { return env_; } return default_env_; } -bool File::Initialize(const char *path, - int flags, - const Env *new_env) { +bool File::Initialize(const char* path, int flags, const Env* new_env) { if (fd_ >= 0) { LOG(ERROR) << "Attempted to Initialize while in use"; return false; @@ -30,7 +28,7 @@ if (flags & O_CREAT) { // TODO(wad) less hacky - fd_ = env()->Create(path, flags, S_IRUSR|S_IWUSR); + fd_ = env()->Create(path, flags, S_IRUSR | S_IWUSR); } else { fd_ = env()->Open(path, flags); } @@ -72,7 +70,7 @@ return offset_; } -bool File::Read(int bytes, uint8_t *buf) { +bool File::Read(int bytes, uint8_t* buf) { if (!ReadAt(bytes, buf, offset_)) { return false; } @@ -80,7 +78,7 @@ return true; } -bool File::ReadAt(int bytes, uint8_t *buf, off_t offset) { +bool File::ReadAt(int bytes, uint8_t* buf, off_t offset) { if (fd_ < 0) { LOG(ERROR) << "Read called with an invalid fd"; return false; @@ -102,7 +100,7 @@ return false; } -int64_t File::Size() const { +int64_t File::Size() const { if (fd_ < 0) { LOG(ERROR) << "Size called with an invalid fd"; return false; @@ -124,7 +122,7 @@ return size; } -bool File::WriteAt(int bytes, const uint8_t *buf, off_t offset) { +bool File::WriteAt(int bytes, const uint8_t* buf, off_t offset) { if (fd_ < 0) { LOG(ERROR) << "Write called with an invalid fd"; return false; @@ -145,7 +143,7 @@ return false; } -bool File::Write(int bytes, const uint8_t *buf) { +bool File::Write(int bytes, const uint8_t* buf) { if (!WriteAt(bytes, buf, offset_)) { return false; }
diff --git a/utils.cc b/utils.cc index 5ffb1a3..5f6c826 100644 --- a/utils.cc +++ b/utils.cc
@@ -9,12 +9,12 @@ namespace verity_utils { -void to_hex(char *hexdigest, - const uint8_t *digest, +void to_hex(char* hexdigest, + const uint8_t* digest, unsigned int digest_length) { - for (unsigned int i = 0; i < digest_length ; i++) { + for (unsigned int i = 0; i < digest_length; i++) { // NOLINTNEXTLINE(runtime/printf) - sprintf(hexdigest+(2*i), "%02x", static_cast<int>(digest[i])); + sprintf(hexdigest + (2 * i), "%02x", static_cast<int>(digest[i])); } }
diff --git a/verity_main.cc b/verity_main.cc index 97e042c..0fb1dca 100644 --- a/verity_main.cc +++ b/verity_main.cc
@@ -13,49 +13,51 @@ #include "verity/utils.h" namespace { -void print_usage(const char *name) { +void print_usage(const char* name) { // We used to advertise more algorithms, but they've never been implemented: // sha512 sha384 sha mdc2 ripemd160 md4 md2 - fprintf(stderr, -"Usage:\n" -" %s <arg>=<value>...\n" -"Options:\n" -" mode One of 'create' or 'verify'\n" -" alg Hash algorithm to use. One of:\n" -" sha256 sha224 sha1 md5\n" -" payload Path to the image to hash\n" -" payload_blocks Size of the image, in blocks (4096 bytes)\n" -" hashtree Path to a hash tree to create or read from\n" -" root_hexdigest Digest of the root node (in hex) for verification\n" -" salt Salt (in hex)\n" -"\n", name); + fprintf( + stderr, + "Usage:\n" + " %s <arg>=<value>...\n" + "Options:\n" + " mode One of 'create' or 'verify'\n" + " alg Hash algorithm to use. One of:\n" + " sha256 sha224 sha1 md5\n" + " payload Path to the image to hash\n" + " payload_blocks Size of the image, in blocks (4096 bytes)\n" + " hashtree Path to a hash tree to create or read from\n" + " root_hexdigest Digest of the root node (in hex) for verification\n" + " salt Salt (in hex)\n" + "\n", + name); } typedef enum { VERITY_NONE = 0, VERITY_CREATE, VERITY_VERIFY } verity_mode_t; -static unsigned int parse_blocks(const char *block_s) { +static unsigned int parse_blocks(const char* block_s) { return (unsigned int)strtoul(block_s, NULL, 0); } } // namespace -static int verity_create(const char *alg, - const char *image_path, +static int verity_create(const char* alg, + const char* image_path, unsigned int image_blocks, - const char *hash_path, - const char *salt); + const char* hash_path, + const char* salt); -void splitarg(char *arg, char **key, char **val) { - char *sp = NULL; +void splitarg(char* arg, char** key, char** val) { + char* sp = NULL; *key = strtok_r(arg, "=", &sp); *val = strtok_r(NULL, "=", &sp); } -int main(int argc, char **argv) { +int main(int argc, char** argv) { verity_mode_t mode = VERITY_CREATE; - const char *alg = NULL; - const char *payload = NULL; - const char *hashtree = NULL; - const char *salt = NULL; + const char* alg = NULL; + const char* payload = NULL; + const char* hashtree = NULL; + const char* salt = NULL; unsigned int payload_blocks = 0; int i; char *key, *val; @@ -91,10 +93,8 @@ } if (!alg || !payload || !hashtree) { - fprintf(stderr, "missing data: %s%s%s\n", - alg ? "" : "alg ", - payload ? "" : "payload ", - hashtree ? "" : "hashtree"); + fprintf(stderr, "missing data: %s%s%s\n", alg ? "" : "alg ", + payload ? "" : "payload ", hashtree ? "" : "hashtree"); print_usage(argv[0]); return -1; } @@ -107,36 +107,30 @@ return -1; } -static int verity_create(const char *alg, - const char *image_path, +static int verity_create(const char* alg, + const char* image_path, unsigned int image_blocks, - const char *hash_path, - const char *salt) { + const char* hash_path, + const char* salt) { // Configure files simple_file::Env env; simple_file::File source; LOG_IF(FATAL, !source.Initialize(image_path, O_RDONLY, &env)) - << "Failed to open the source file: " << image_path; + << "Failed to open the source file: " << image_path; simple_file::File destination; - LOG_IF(FATAL, !destination.Initialize(hash_path, - O_CREAT|O_RDWR|O_TRUNC, - &env)) - << "Failed to open destination file: " << hash_path; + LOG_IF(FATAL, + !destination.Initialize(hash_path, O_CREAT | O_RDWR | O_TRUNC, &env)) + << "Failed to open destination file: " << hash_path; // Create the actual worker and create the hash image. verity::FileHasher hasher; - LOG_IF(FATAL, !hasher.Initialize(&source, - &destination, - image_blocks, - alg)) - << "Failed to initialize hasher"; + LOG_IF(FATAL, !hasher.Initialize(&source, &destination, image_blocks, alg)) + << "Failed to initialize hasher"; if (salt) hasher.set_salt(salt); - LOG_IF(FATAL, !hasher.Hash()) - << "Failed to hash hasher"; - LOG_IF(FATAL, !hasher.Store()) - << "Failed to store hasher"; + LOG_IF(FATAL, !hasher.Hash()) << "Failed to hash hasher"; + LOG_IF(FATAL, !hasher.Store()) << "Failed to store hasher"; hasher.PrintTable(true); return 0; }