-
Notifications
You must be signed in to change notification settings - Fork 19
Comprehensive improvements: Cross-platform support, bundled libraries, code quality, and extensive test coverage #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
...braries, code quality, and extensive test coverage ## Major Improvements ### 1. Bundled Cross-Platform Libraries - Add pre-compiled GmSSL libraries in src/gmssl/_libs/ - Support 4 platforms: Linux x64/ARM64, macOS Universal, Windows x64 - Smart library loading: system library first, bundled library as fallback - Enable pip install gmssl-python to work out-of-the-box ### 2. Cross-Platform Compatibility Fixes - Fix Windows FILE* cross-DLL boundary issue with elegant wrapper - Fix macOS SM9 PEM import buffer flush issue - Add complete Linux aarch64 (ARM64) support - Fix all SM2/SM9 PEM import/export operations on Windows ### 3. Test Coverage Enhancement (552% increase) - Add 105 new tests (from 19 to 124 tests) - Error handling tests (34 tests) - Edge case tests (28 tests) - Additional method tests (15 tests) - Performance and stress tests (13 tests) - Thread safety tests (10 tests) - Overall coverage: 77%, SM9 module: 86% ### 4. Code Quality Improvements - Introduce _GmsslProxy class to reduce 136 lines of boilerplate - Refactor PEM utilities to eliminate 80 lines of duplication - Add pre-commit configuration (ruff format and check) - Fix ctypes structure definitions (SM2_KEY, Sm4Gcm) ### 5. API Enhancements - Add Sm4.decrypt() method for better API clarity - Runtime validation to prevent misuse - Maintain backward compatibility ### 6. Documentation Updates - Add thread safety warnings for Sm4Gcm - Update installation guide with bundled library info - Add library loading priority documentation - Update test running guide ### 7. Build and CI Optimization - Update bundled GmSSL libraries to master branch - Optimize GitHub Actions workflows - Add platform selection options - Use Release mode for better performance All 124 tests passing. Backward compatible.
This was referenced Oct 18, 2025
Open
Open
Open
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📋 概述
本 PR 对 GmSSL-Python 进行了全面改进,主要包括:跨平台兼容性修复、自包含动态库支持、代码质量提升、API 优化以及大幅增强的测试覆盖率。这些改进使得 GmSSL-Python 更加健壮、易用,并且可以开箱即用。
✨ 主要改进
1. 🎁 自包含跨平台动态库支持
问题背景:
解决方案:
src/gmssl/_libs/)智能库加载策略:
用户体验提升:
pip install gmssl-python即可直接使用,无需额外安装2. 🔧 跨平台兼容性修复
Windows 平台修复
004d60a- 解决 FILE* 跨 DLL 边界问题9af3697- 添加 Windows 兼容的 PEM 工具7a293bd,bd84323- 修复指针类型处理macOS 平台修复
fflush()7e734cbLinux ARM64 支持
4734f50,324af043. 📈 测试覆盖率大幅提升
测试数量:从 19 个增加到 124 个(增长 552%)
新增测试套件:
tests/test_errors.pytests/test_edge_cases.pytests/test_additional_methods.pytests/test_pygmssl_missing.pytests/test_thread_safety.py代码覆盖率:
测试通过率:100% (124/124)
4. 🎨 代码质量提升
重构 1:引入
_GmsslProxy类问题:大量重复的错误处理代码
改进:使用代理模式自动检查错误
效果:减少约 136 行样板代码
相关提交:
1b99b31重构 2:消除 PEM 工具函数重复
问题:4 个 PEM 函数有 ~80 行重复代码
解决:提取通用逻辑到
_call_platform_pem_function()效果:
相关提交:
1d4df87其他改进
5. 🚀 API 改进
新增
Sm4.decrypt()方法问题:之前加密和解密都使用
encrypt()方法,语义不清晰改进:添加专用的
decrypt()方法特性:
decrypt()会抛出异常encrypt()方法相关提交:
cf9b0596. 📚 文档和线程安全说明
线程安全警告
Sm4Gcm不是线程安全的文档更新
7. 🔄 库更新和构建优化
🧪 测试证明
所有改进均通过完整测试验证:
覆盖率报告:
✅ 向后兼容性
Sm4.decrypt()是可选的,不影响现有代码📦 影响范围
受益用户:
包大小变化:
🔗 相关 Issue
#4 #8 #9 #12 #16 #20 #21
📝 Checklist
🙏 致谢
感谢 GmSSL 项目提供优秀的国密算法实现!