summaryrefslogtreecommitdiffstats
path: root/src/shared/import-util.c
diff options
context:
space:
mode:
authorPavel Odvody <podvody@redhat.com>2015-05-19 16:29:29 +0200
committerLennart Poettering <lennart@poettering.net>2015-05-19 18:21:46 +0200
commit74eff91e5f118224c1e556d2716d5360dd97a87d (patch)
tree3670882a05762c865c82f1561b4a70cc3cc3e5bb /src/shared/import-util.c
parentcore: when propagating restart requests due to deps, downgrade restart to try... (diff)
downloadsystemd-74eff91e5f118224c1e556d2716d5360dd97a87d.tar.xz
systemd-74eff91e5f118224c1e556d2716d5360dd97a87d.zip
shared/import-util: Tag renamed to reference
Added (sha256) digest validation function
Diffstat (limited to 'src/shared/import-util.c')
-rw-r--r--src/shared/import-util.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/shared/import-util.c b/src/shared/import-util.c
index 660d92ac5d..001a8a37e8 100644
--- a/src/shared/import-util.c
+++ b/src/shared/import-util.c
@@ -150,6 +150,27 @@ int raw_strip_suffixes(const char *p, char **ret) {
return 0;
}
+bool dkr_digest_is_valid(const char *digest) {
+ /* 7 chars for prefix, 64 chars for the digest itself */
+ if (strlen(digest) != 71)
+ return false;
+
+ return startswith(digest, "sha256:") && in_charset(digest + 7, "0123456789abcdef");
+}
+
+bool dkr_ref_is_valid(const char *ref) {
+ const char *colon;
+
+ if (isempty(ref))
+ return false;
+
+ colon = strchr(ref, ':');
+ if (!colon)
+ return filename_is_valid(ref);
+
+ return dkr_digest_is_valid(ref);
+}
+
bool dkr_name_is_valid(const char *name) {
const char *slash, *p;