forked from lix-project/lix
hash.cc/hash.h: Minor C++ improvements
This commit is contained in:
parent
3dcb83409d
commit
e7abf60a0c
|
@ -52,7 +52,7 @@ struct Hash
|
||||||
/**
|
/**
|
||||||
* Create a zero-filled hash object.
|
* Create a zero-filled hash object.
|
||||||
*/
|
*/
|
||||||
Hash(HashType type);
|
explicit Hash(HashType type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse the hash from a string representation in the format
|
* Parse the hash from a string representation in the format
|
||||||
|
@ -103,7 +103,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Returns the length of a base-16 representation of this hash.
|
* Returns the length of a base-16 representation of this hash.
|
||||||
*/
|
*/
|
||||||
size_t base16Len() const
|
[[nodiscard]] size_t base16Len() const
|
||||||
{
|
{
|
||||||
return hashSize * 2;
|
return hashSize * 2;
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Returns the length of a base-32 representation of this hash.
|
* Returns the length of a base-32 representation of this hash.
|
||||||
*/
|
*/
|
||||||
size_t base32Len() const
|
[[nodiscard]] size_t base32Len() const
|
||||||
{
|
{
|
||||||
return (hashSize * 8 - 1) / 5 + 1;
|
return (hashSize * 8 - 1) / 5 + 1;
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Returns the length of a base-64 representation of this hash.
|
* Returns the length of a base-64 representation of this hash.
|
||||||
*/
|
*/
|
||||||
size_t base64Len() const
|
[[nodiscard]] size_t base64Len() const
|
||||||
{
|
{
|
||||||
return ((4 * hashSize / 3) + 3) & ~3;
|
return ((4 * hashSize / 3) + 3) & ~3;
|
||||||
}
|
}
|
||||||
|
@ -129,14 +129,14 @@ public:
|
||||||
* or base-64. By default, this is prefixed by the hash type
|
* or base-64. By default, this is prefixed by the hash type
|
||||||
* (e.g. "sha256:").
|
* (e.g. "sha256:").
|
||||||
*/
|
*/
|
||||||
std::string to_string(HashFormat hashFormat, bool includeType) const;
|
[[nodiscard]] std::string to_string(HashFormat hashFormat, bool includeType) const;
|
||||||
|
|
||||||
std::string gitRev() const
|
[[nodiscard]] std::string gitRev() const
|
||||||
{
|
{
|
||||||
return to_string(HashFormat::Base16, false);
|
return to_string(HashFormat::Base16, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string gitShortRev() const
|
[[nodiscard]] std::string gitShortRev() const
|
||||||
{
|
{
|
||||||
return std::string(to_string(HashFormat::Base16, false), 0, 7);
|
return std::string(to_string(HashFormat::Base16, false), 0, 7);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ struct CmdHashBase : Command
|
||||||
std::vector<std::string> paths;
|
std::vector<std::string> paths;
|
||||||
std::optional<std::string> modulus;
|
std::optional<std::string> modulus;
|
||||||
|
|
||||||
CmdHashBase(FileIngestionMethod mode) : mode(mode)
|
explicit CmdHashBase(FileIngestionMethod mode) : mode(mode)
|
||||||
{
|
{
|
||||||
addFlag({
|
addFlag({
|
||||||
.longName = "sri",
|
.longName = "sri",
|
||||||
|
|
Loading…
Reference in a new issue