cpp-libp2p icon indicating copy to clipboard operation
cpp-libp2p copied to clipboard

Add MSVC support and implement ECDSA key validation

Open alienx5499 opened this issue 4 months ago • 1 comments

Summary

This PR adds MSVC compiler support and implements basic ECDSA key validation functionality. The changes address existing TODO items and improve code quality.

Changes

MSVC Compiler Support

  • File: CMakeLists.txt
  • Change: Replaced TODO comment with MSVC compiler flags
  • Details: Added comprehensive MSVC flags for warnings, C++ standards compliance, and code quality
  • Impact: Enables Windows development and CI/CD support

ECDSA Key Validation

  • File: src/crypto/key_validator/key_validator_impl.cpp
  • Change: Implemented basic ECDSA key validation (replacing TODO comments)
  • Details:
    • Private key validation: checks size (32-66 bytes) and prevents all-zero keys
    • Public key validation: checks size (33-133 bytes) and prevents all-zero keys
    • Returns appropriate error codes for invalid keys
  • Impact: Addresses issue #103 and improves security

Code Quality

  • File: src/storage/sqlite.cpp
  • Change: Added const correctness to error handling methods
  • Details: Made getErrorCode() and getErrorMessage() const methods

Testing

The ECDSA validation logic was tested with various key sizes and formats:

  • Valid private key (32 bytes): PASS
  • Invalid private key (16 bytes): PASS (correctly rejected)
  • Zero private key (32 bytes): PASS (correctly rejected)
  • Valid public key (33 bytes): PASS
  • Invalid public key (16 bytes): PASS (correctly rejected)
  • Valid public key (64 bytes): PASS

All tests passed successfully.

Technical Details

The MSVC flags include standard warning levels, C++ compliance settings, and code quality checks. The ECDSA validation follows conservative validation patterns - rejecting invalid keys rather than accepting them.

Files Changed

  • CMakeLists.txt - Added MSVC compiler flags
  • src/crypto/key_validator/key_validator_impl.cpp - Implemented ECDSA validation
  • src/storage/sqlite.cpp - Added const correctness

Verification

  • Code compiles without errors
  • ECDSA validation logic verified with test cases
  • No breaking changes to existing functionality
  • Follows project coding standards

alienx5499 avatar Sep 05 '25 07:09 alienx5499

@turuslan Could you please review this PR when you get a chance?

alienx5499 avatar Sep 09 '25 12:09 alienx5499