Skip to content

Commit

Permalink
make checksumtypes an enum class
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Dreik committed Jun 17, 2023
1 parent 0b47581 commit 767f5cd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
24 changes: 12 additions & 12 deletions Checksum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ Checksum::Checksum(checksumtypes type)
: m_checksumtype(type)
{
switch (m_checksumtype) {
case SHA1: {
case checksumtypes::SHA1: {
sha1_init(&m_state.sha1);
} break;
case SHA256: {
case checksumtypes::SHA256: {
sha256_init(&m_state.sha256);
} break;
case MD5: {
case checksumtypes::MD5: {
md5_init(&m_state.md5);
} break;
default:
Expand All @@ -38,13 +38,13 @@ int
Checksum::update(std::size_t length, const unsigned char* buffer)
{
switch (m_checksumtype) {
case SHA1:
case checksumtypes::SHA1:
sha1_update(&m_state.sha1, length, buffer);
break;
case SHA256:
case checksumtypes::SHA256:
sha256_update(&m_state.sha256, length, buffer);
break;
case MD5:
case checksumtypes::MD5:
md5_update(&m_state.md5, length, buffer);
break;
default:
Expand Down Expand Up @@ -103,11 +103,11 @@ int
Checksum::getDigestLength() const
{
switch (m_checksumtype) {
case SHA1:
case checksumtypes::SHA1:
return SHA1_DIGEST_SIZE;
case SHA256:
case checksumtypes::SHA256:
return SHA256_DIGEST_SIZE;
case MD5:
case checksumtypes::MD5:
return MD5_DIGEST_SIZE;
default:
return -1;
Expand All @@ -122,7 +122,7 @@ Checksum::printToBuffer(void* buffer, std::size_t N)
assert(buffer);

switch (m_checksumtype) {
case SHA1:
case checksumtypes::SHA1:
if (N >= SHA1_DIGEST_SIZE) {
sha1_digest(
&m_state.sha1, SHA1_DIGEST_SIZE, static_cast<unsigned char*>(buffer));
Expand All @@ -131,7 +131,7 @@ Checksum::printToBuffer(void* buffer, std::size_t N)
return -1;
}
break;
case SHA256:
case checksumtypes::SHA256:
if (N >= SHA256_DIGEST_SIZE) {
sha256_digest(&m_state.sha256,
SHA256_DIGEST_SIZE,
Expand All @@ -141,7 +141,7 @@ Checksum::printToBuffer(void* buffer, std::size_t N)
return -1;
}
break;
case MD5:
case checksumtypes::MD5:
if (N >= MD5_DIGEST_SIZE) {
md5_digest(
&m_state.md5, MD5_DIGEST_SIZE, static_cast<unsigned char*>(buffer));
Expand Down
4 changes: 2 additions & 2 deletions Checksum.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Checksum
{
public:
// these are the checksums that can be calculated
enum checksumtypes
enum class checksumtypes
{
NOTSET = 0,
MD5,
Expand All @@ -46,7 +46,7 @@ public:

private:
// to know what type of checksum we are doing
const int m_checksumtype = NOTSET;
const checksumtypes m_checksumtype = checksumtypes::NOTSET;
// the checksum calculation internal state
union ChecksumStruct
{
Expand Down
10 changes: 5 additions & 5 deletions Fileinfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Fileinfo::fillwithbytes(enum readtobuffermode filltype,
return -1;
}

auto checksumtype = Checksum::NOTSET;
auto checksumtype = Checksum::checksumtypes::NOTSET;
// read some bytes
switch (filltype) {
case readtobuffermode::READ_FIRST_BYTES:
Expand All @@ -61,20 +61,20 @@ Fileinfo::fillwithbytes(enum readtobuffermode filltype,
f1.read(m_somebytes.data(), SomeByteSize);
break;
case readtobuffermode::CREATE_MD5_CHECKSUM:
checksumtype = Checksum::MD5;
checksumtype = Checksum::checksumtypes::MD5;
break;
case readtobuffermode::CREATE_SHA1_CHECKSUM:
checksumtype = Checksum::SHA1;
checksumtype = Checksum::checksumtypes::SHA1;
break;
case readtobuffermode::CREATE_SHA256_CHECKSUM:
checksumtype = Checksum::SHA256;
checksumtype = Checksum::checksumtypes::SHA256;
break;
default:
std::cerr << "does not know how to do that filltype:"
<< static_cast<long>(filltype) << std::endl;
}

if (checksumtype != Checksum::NOTSET) {
if (checksumtype != Checksum::checksumtypes::NOTSET) {
Checksum chk(checksumtype);

char buffer[4096];
Expand Down

0 comments on commit 767f5cd

Please sign in to comment.