feat(ViperOpenSSLProject): 以模板新建 OpenSSL FFI 测试工程(版本+摘要 demo,链接目标待定)

This commit is contained in:
TermiNexus committed 2026-09-02 16:19:23 +08:00
1 parent ab068df348
commit dee1e19c62
5 files changed
+164

No files matched your search

+13
View File
@@ -0,0 +1,13 @@
*.o
*.obj
*.exe
*.img
*.iso
**/__pycache__/
.cache/
*.pyc
# 编译
**/output/
**/temp/
**/.tpv_build/
+45
View File
@@ -0,0 +1,45 @@
# main.vp — ViperOpenSSLProject:版本 + 摘要演示
#
# 使用 includes/openssl FFI 层(import openssl):
# 1) 打印 OpenSSL 版本号
# 2) 计算 "hello openssl" 的 MD5 / SHA256 十六进制摘要
#
# 链接目标尚未定(msys2 预装 3.6.2 动态库 或 openssl_358_C 自编译),
# 配好 project.vpj 的 -lcrypto/-lssl(或 static_libs)后才可链接运行。
import t, c
import stdlib
import binascii
import openssl
import w32.win32console as w32cmd
def print_digest(name: str, buf: bytes, length: int):
hex_str: str = binascii.hexlify(buf, length)
print(f"{name}: {hex_str}")
def main() -> int:
w32cmd.SetConsoleOutputCP(65001)
w32cmd.SetConsoleCP(65001)
# ---- 1) 版本 ----
ver: str = openssl.OpenSSL_version(openssl.OpenSslVersion)
print("OpenSSL version:", ver)
num: t.CUInt32T = openssl.OpenSSL_version_num()
print(f"Version number : 0x{num:x}")
# ---- 2) 摘要 ----
data: str = "hello openssl"
dlen: int = len(data)
md5_buf: bytes = stdlib.malloc(openssl.Md5DigestLength)
openssl.MD5(data, dlen, md5_buf)
print_digest("MD5 ", md5_buf, openssl.Md5DigestLength)
stdlib.free(md5_buf)
sha256_buf: bytes = stdlib.malloc(openssl.Sha256DigestLength)
openssl.SHA256(data, dlen, sha256_buf)
print_digest("SHA256", sha256_buf, openssl.Sha256DigestLength)
stdlib.free(sha256_buf)
return 0
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2026 TermiNexus
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+48
View File
@@ -0,0 +1,48 @@
# ViperOpenSSLProject
基于 [ViperTemplateProject](../ViperTemplateProject) 模板创建的 **OpenSSL 3.x FFI 测试工程**,
用来验证 `includes/openssl` FFI 层(摘要/哈希、EVP、证书 PKI、SSL/TLS)的链接与调用。
## 说明
- FFI 层源码在 `../includes/openssl/`(`import openssl` 使用)。
- 当前 App/main.vp 为「版本 + SHA256/MD5 摘要」演示。
- 尚未决定链接目标(msys2 预装 3.6.2 动态库 或 openssl_358_C 自编译静态库),
本工程 `project.vpj` **暂未配置 openssl 链接参数**,需要时再补。
## 目录结构
```
ViperOpenSSLProject/
├── .gitignore
├── LICENSE
├── README.md
├── project.vpj # 编译/链接配置(openssl 链接目标待定)
└── App/
└── main.vp # 版本 + 摘要演示
```
## 链接参考(后续选择其一填入 project.vpj)
### 方式 A:msys2 预装 3.6.2 动态库(推荐先试)
在 `project.vpj` 的 `linker.flags` 中加入:
```
"-L D:/msys64/mingw64/lib",
"-lcrypto",
"-lssl"
```
运行 app.exe 前需把 `D:/msys64/mingw64/bin` 加入 PATH(`libcrypto-3-x64.dll` / `libssl-3-x64.dll`)。
### 方式 B:openssl_358_C 源码自编译静态库
先用 perl Configure + mingw 编译 `../includes/openssl/openssl_358_C`,再把
生成的 `libcrypto.a` / `libssl.a` 填入 `linker.static_libs`。
## 编译运行
```powershell
cd D:\Users\TermiNexus\Desktop\TransPyC\ViperOpenSSLProject
python ..\Projectrans.py --project .\project.vpj --clean-cache=false
.\output\app.exe # 注意:openssl 链接参数配好前编译/链接会失败
```
+37
View File
@@ -0,0 +1,37 @@
{
"name": "ViperOpenSSLProject - OpenSSL 3.x FFI Test",
"version": "1.0.0",
"source_dir": "./App",
"build_dir": "./.tpv_build",
"compiler": {
"cmd": "llc",
"flags": [
"-filetype=obj",
"-relocation-model=pic"
]
},
"linker": {
"cmd": "clang++",
"flags": [
"-lmsvcrt",
"-lucrt",
"-lpthread",
"-lmingwex",
"-lkernel32",
"-Wl,--allow-multiple-definition"
],
"output": "app.exe"
},
"includes": [
"../includes"
],
"target": {
"triple": "x86_64-pc-windows-gnu",
"datalayout": "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
},
"options": {
"slice_level": 3,
"target": "llvm",
"strict_mode": true
}
}