keygen-sh / example-cpp-cryptographic-license-files

Example of verifying cryptographically signed and encrypted license files using C++, OpenSSL, Ed25519 and AES-256-GCM.
https://keygen.sh
MIT License
9 stars 8 forks source link

Template function is_empty() is possibly incorrect #10

Closed pstavirs closed 11 months ago

pstavirs commented 11 months ago

is_empty() is defined assuming a struct with std::string(s) will be all zero - which may not be true. I fixed it using template specializations. Also included in PR #9.

diff --git a/main.cpp b/main.cpp
index b1f5146..4362782 100644
--- a/main.cpp
+++ b/main.cpp
@@ -175,6 +175,21 @@ bool is_empty(T data) {
   return (*mm == 0) && memcmp(mm, mm + 1, sizeof(T) - 1) == 0;
 }

+template <>
+bool is_empty(license_file data) {
+  return data.enc.empty();
+}
+
+template <>
+bool is_empty(license data) {
+  return data.id.empty();
+}
+
+template <>
+bool is_empty(machine data) {
+  return data.id.empty();
+}
+
ezekg commented 11 months ago

I removed the template methods in https://github.com/keygen-sh/example-cpp-cryptographic-license-files/commit/4a378498080ef053e73d75e6308e47183e2239f3.

pstavirs commented 11 months ago

Thanks Zeke!

Srivats

On Thu, Dec 7, 2023 at 10:03 PM Zeke Gabrielse @.***> wrote:

I removed the template methods in 4a37849 https://github.com/keygen-sh/example-cpp-cryptographic-license-files/commit/4a378498080ef053e73d75e6308e47183e2239f3 .

— Reply to this email directly, view it on GitHub https://github.com/keygen-sh/example-cpp-cryptographic-license-files/issues/10#issuecomment-1845663024, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACABSRZBXTC4QHZTK4FOGZ3YIHVV3AVCNFSM6AAAAABAHGWOAWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNBVGY3DGMBSGQ . You are receiving this because you authored the thread.Message ID: <keygen-sh/example-cpp-cryptographic-license-files/issues/10/1845663024@ github.com>