diff --git a/Checksum.cc b/Checksum.cc index 6d1fb29..e8231a6 100644 --- a/Checksum.cc +++ b/Checksum.cc @@ -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: @@ -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: @@ -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; @@ -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(buffer)); @@ -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, @@ -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(buffer)); diff --git a/Checksum.hh b/Checksum.hh index cf14516..5354478 100644 --- a/Checksum.hh +++ b/Checksum.hh @@ -19,7 +19,7 @@ class Checksum { public: // these are the checksums that can be calculated - enum checksumtypes + enum class checksumtypes { NOTSET = 0, MD5, @@ -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 { diff --git a/Fileinfo.cc b/Fileinfo.cc index a30539e..7362832 100644 --- a/Fileinfo.cc +++ b/Fileinfo.cc @@ -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: @@ -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(filltype) << std::endl; } - if (checksumtype != Checksum::NOTSET) { + if (checksumtype != Checksum::checksumtypes::NOTSET) { Checksum chk(checksumtype); char buffer[4096];