GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/publish/cmd_hash.cc
Date: 2026-05-19 11:45:12
Exec Total Coverage
Lines: 0 20 0.0%
Branches: 0 70 0.0%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM File System.
3 */
4
5
6 #include "cmd_hash.h"
7
8 #include <inttypes.h>
9 #include <stdint.h>
10
11 #include <cstdio>
12 #include <cstring>
13
14 #include "crypto/hash.h"
15 #include "publish/except.h"
16 #include "util/logging.h"
17
18 int publish::CmdHash::Main(const Options &options) {
19 const std::string algorithm = options.GetString("algorithm");
20 shash::Any hash(shash::ParseHashAlgorithm(algorithm));
21 // MD5 is not a content hash algorithm but we deal with it in this utility
22 // nevertheless
23 if (algorithm == "md5")
24 hash.algorithm = shash::kMd5;
25 if (hash.algorithm == shash::kAny)
26 throw EPublish("unknown hash algorithm: " + algorithm);
27
28 if (options.Has("input")) {
29 shash::HashString(options.GetString("input"), &hash);
30 } else {
31 shash::HashFd(fileno(stdin), &hash);
32 }
33 LogCvmfs(kLogCvmfs, kLogStdout | kLogNoLinebreak, "%s",
34 options.Has("fingerprint") ? hash.ToFingerprint().c_str()
35 : hash.ToString().c_str());
36 if (options.Has("split")) {
37 if (hash.algorithm != shash::kMd5)
38 throw EPublish("split int representation only supported for MD5");
39
40 uint64_t high, low;
41 shash::Md5 md5_hash;
42 memcpy(md5_hash.digest, hash.digest, shash::kDigestSizes[shash::kMd5]);
43 md5_hash.ToIntPair(&high, &low);
44 // SQLite uses int64, not uint64
45 LogCvmfs(kLogCvmfs, kLogStdout | kLogNoLinebreak,
46 " [%" PRId64 " %" PRId64 "]", static_cast<int64_t>(high),
47 static_cast<int64_t>(low));
48 }
49 LogCvmfs(kLogCvmfs, kLogStdout, "");
50
51 return 0;
52 }
53