From cf2c055ac41b2f8c88b0226f1da39763c268bfe7 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sun, 24 Mar 2024 14:41:59 +0800 Subject: [PATCH] update: independent impl namespace --- src/impl/algorithm.inc | 8 ++++---- src/impl/constexpr.inc | 4 ++-- src/impl/core.cc | 14 ++++++-------- src/impl/inline.inc | 4 ++-- src/impl/wrapper.cc | 4 +--- src/md5.h | 10 ++++++++-- 6 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/impl/algorithm.inc b/src/impl/algorithm.inc index d45aac0..6514903 100644 --- a/src/impl/algorithm.inc +++ b/src/impl/algorithm.inc @@ -35,7 +35,7 @@ #include "sine.inc" -namespace md5 { +namespace md5::impl { /// Hexadecimal character mapping table. constexpr char HexTable[] = { @@ -77,8 +77,8 @@ consteval int S(int i) { /// MD5 T-table constant, input between 0 and 63. consteval uint32_t T(int i) { - auto val = math::sin(i + 1); - return static_cast(std::abs(val) * 0x100000000); + auto val = ::md5::math::sin(i + 1); + return static_cast(::std::abs(val) * 0x100000000); } -} // namespace md5 +} // namespace md5::impl diff --git a/src/impl/constexpr.inc b/src/impl/constexpr.inc index 43db932..25d0b43 100644 --- a/src/impl/constexpr.inc +++ b/src/impl/constexpr.inc @@ -2,7 +2,7 @@ #include -namespace md5 { +namespace md5::impl { struct md5_ctx_ce { uint32_t A = MD5_A; @@ -74,4 +74,4 @@ constexpr std::array MD5::HashCE(const char *data, uint64_t len) { return DigestCE({ctx.A, ctx.B, ctx.C, ctx.D}); } -} // namespace md5 +} // namespace md5::impl diff --git a/src/impl/core.cc b/src/impl/core.cc index c6c7559..1f2d286 100644 --- a/src/impl/core.cc +++ b/src/impl/core.cc @@ -2,7 +2,7 @@ #include "md5.h" -namespace md5 { +using ::md5::impl::MD5; static constexpr unsigned char Padding[64] { 0x80, /* 0x00, ... */ }; @@ -43,18 +43,16 @@ void MD5::FinalImpl(const void *data, uint64_t len) { } unsigned char buffer[128]; // 2 blocks - std::memcpy(buffer, data, len); + ::std::memcpy(buffer, data, len); uint64_t total = (ctx_.size + len) << 3; // total number in bit if (len < 56) { // len -> [0, 56) - std::memcpy(buffer + len, Padding, 56 - len); - std::memcpy(buffer + 56, &total, 8); + ::std::memcpy(buffer + len, Padding, 56 - len); + ::std::memcpy(buffer + 56, &total, 8); UpdateImpl(buffer, 64); // update 1 block } else { // len -> [56, 64 + 56) - std::memcpy(buffer + len, Padding, 120 - len); - std::memcpy(buffer + 120, &total, 8); + ::std::memcpy(buffer + len, Padding, 120 - len); + ::std::memcpy(buffer + 120, &total, 8); UpdateImpl(buffer, 128); // update 2 blocks } } - -} // namespace md5 diff --git a/src/impl/inline.inc b/src/impl/inline.inc index 71ba1db..e1d725f 100644 --- a/src/impl/inline.inc +++ b/src/impl/inline.inc @@ -1,6 +1,6 @@ #pragma once -namespace md5 { +namespace md5::impl { inline MD5& MD5::Reset() { ctx_.A = MD5_A; @@ -35,4 +35,4 @@ constexpr std::array MD5::HashCE(const std::string_view &data) { return HashCE(data.data(), data.size()); } -} // namespace md5 +} // namespace md5::impl diff --git a/src/impl/wrapper.cc b/src/impl/wrapper.cc index ca9a39b..b04f330 100644 --- a/src/impl/wrapper.cc +++ b/src/impl/wrapper.cc @@ -2,7 +2,7 @@ #include "md5.h" -namespace md5 { +using ::md5::impl::MD5; std::string MD5::Digest() const { std::string result {}; @@ -39,5 +39,3 @@ MD5& MD5::Update(const void *data, uint64_t len) { } return *this; } - -} // namespace md5 diff --git a/src/md5.h b/src/md5.h index 5fdc8ed..4524bda 100644 --- a/src/md5.h +++ b/src/md5.h @@ -12,7 +12,7 @@ static_assert(__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__, #include "impl/algorithm.inc" -namespace md5 { +namespace md5::impl { class MD5 { public: @@ -58,7 +58,13 @@ private: void FinalImpl(const void *data, uint64_t len); }; -} // namespace md5 +} // namespace md5::impl #include "impl/inline.inc" #include "impl/constexpr.inc" + +namespace md5 { + +using MD5 = ::md5::impl::MD5; + +} // namespace md5