mirror of
https://github.com/openharmony/third_party_fsverity-utils.git
synced 2026-07-01 10:05:35 -04:00
programs: make the test programs show libfsverity error messages
Signed-off-by: Eric Biggers <ebiggers@google.com>
This commit is contained in:
+1
-6
@@ -200,16 +200,11 @@ u32 get_default_block_size(void)
|
||||
return n;
|
||||
}
|
||||
|
||||
static void print_libfsverity_error(const char *msg)
|
||||
{
|
||||
error_msg("%s", msg);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const struct fsverity_command *cmd;
|
||||
|
||||
libfsverity_set_error_callback(print_libfsverity_error);
|
||||
install_libfsverity_error_handler();
|
||||
|
||||
if (argc < 2) {
|
||||
error_msg("no command specified");
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*
|
||||
* Copyright 2020 Google LLC
|
||||
*/
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#define SHA256_DIGEST_SIZE 32
|
||||
@@ -43,6 +44,8 @@ int main(void)
|
||||
"\x86\x52";
|
||||
int err;
|
||||
|
||||
install_libfsverity_error_handler();
|
||||
|
||||
f.data = xmalloc(f.size);
|
||||
for (i = 0; i < f.size; i++)
|
||||
f.data[i] = (i % 11) + (i % 439) + (i % 1103);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*
|
||||
* Copyright 2020 Google LLC
|
||||
*/
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#define SHA256_DIGEST_SIZE 32
|
||||
@@ -11,6 +12,8 @@
|
||||
|
||||
int main(void)
|
||||
{
|
||||
install_libfsverity_error_handler();
|
||||
|
||||
ASSERT(libfsverity_get_digest_size(0) == -1);
|
||||
ASSERT(libfsverity_get_hash_name(0) == NULL);
|
||||
ASSERT(libfsverity_find_hash_alg_by_name("bad") == 0);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*
|
||||
* Copyright 2020 Google LLC
|
||||
*/
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
@@ -24,6 +25,8 @@ int main(void)
|
||||
u64 expected_sig_size;
|
||||
int err;
|
||||
|
||||
install_libfsverity_error_handler();
|
||||
|
||||
d->digest_algorithm = FS_VERITY_HASH_ALG_SHA256;
|
||||
d->digest_size = SHA256_DIGEST_SIZE;
|
||||
memcpy(d->digest,
|
||||
|
||||
@@ -84,6 +84,16 @@ __noreturn void assertion_failed(const char *expr, const char *file, int line)
|
||||
fatal_error("Assertion failed: %s at %s:%d", expr, file, line);
|
||||
}
|
||||
|
||||
static void print_libfsverity_error(const char *msg)
|
||||
{
|
||||
error_msg("%s", msg);
|
||||
}
|
||||
|
||||
void install_libfsverity_error_handler(void)
|
||||
{
|
||||
libfsverity_set_error_callback(print_libfsverity_error);
|
||||
}
|
||||
|
||||
/* ========== File utilities ========== */
|
||||
|
||||
bool open_file(struct filedes *file, const char *filename, int flags, int mode)
|
||||
|
||||
@@ -27,6 +27,8 @@ __cold __noreturn void assertion_failed(const char *expr,
|
||||
|
||||
#define ASSERT(e) ({ if (!(e)) assertion_failed(#e, __FILE__, __LINE__); })
|
||||
|
||||
void install_libfsverity_error_handler(void);
|
||||
|
||||
struct filedes {
|
||||
int fd;
|
||||
char *name; /* filename, for logging or error messages */
|
||||
|
||||
Reference in New Issue
Block a user