From 50b6b69fcfbe492d9bac3ed1c9d0cd7cc400a5de Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Sat, 30 Dec 2023 20:23:31 +0530 Subject: pass/add: trim gpg fingerprint --- pass_util.c | 1 + util.c | 12 ++++++++++++ util.h | 1 + 3 files changed, 14 insertions(+) diff --git a/pass_util.c b/pass_util.c index d9d6fc3..3ce3784 100644 --- a/pass_util.c +++ b/pass_util.c @@ -145,6 +145,7 @@ int pass_add(const char *path, const char *pass, size_t n) if (!rc) err_die(1, "failed to read %s", gpg_id_path); fclose(gpg_id); + util_strtrim(fpr); r = gpg_key_validate(fpr); if (r) diff --git a/util.c b/util.c index 6e6079e..14dfeaa 100644 --- a/util.c +++ b/util.c @@ -2,6 +2,7 @@ #include #include #include +#include #include "util.h" @@ -31,3 +32,14 @@ int r_mkdir(const char *path, mode_t mode) return mkdir(path, mode); } + +void util_strtrim(char *s) +{ + char *rend; + + for (rend = s; *s; ++s) + if (!isspace(*s)) + rend = s; + + rend[1] = '\0'; +} diff --git a/util.h b/util.h index 04c5b88..d3b4168 100644 --- a/util.h +++ b/util.h @@ -11,6 +11,7 @@ } int r_mkdir(const char *path, mode_t mode); +void util_strtrim(char *s); #define UTIL_H #endif -- cgit v1.2.3