refactor: 优化 NBPF 模块 - 缓存导入/合并重复方法/减少I/O
Some checks failed
CI / test (3.10) (push) Has been cancelled
CI / test (3.11) (push) Has been cancelled
CI / test (3.12) (push) Has been cancelled
CI / test (3.13) (push) Has been cancelled

- crypto.py: 8个_imp_*方法改为_ModuleCache类缓存导入
- crypto.py: outer/inner加解密合并为_layer_encrypt/decrypt
- crypto.py: 提取公共摘要计算方法,拆分长方法
- compiler.py: 删除_obfuscate_code中未使用的死代码
- loader.py: 3次ZIP扫描合并为1次缓存读取
- format.py: 更新为使用_ModuleCache
- 合计减少205行代码(1707→1502)
This commit is contained in:
2026-05-17 15:36:45 +08:00
parent 1736bb5801
commit e67d2d8ef6
20 changed files with 324 additions and 527 deletions

View File

@@ -32,7 +32,7 @@ from pathlib import Path
from typing import Optional
from oss.logger.logger import Log
from .crypto import NBPCrypto, NBPCryptoError
from .crypto import NBPCrypto, NBPCryptoError, _ModuleCache
from .compiler import NIRCompiler, NIRCompileError
@@ -148,11 +148,10 @@ class NBPFPacker:
zf.writestr(NBPFFormatter.SIGNER_PEM, ed25519_public_key)
else:
# 从私钥派生公钥
ed25519_mod = NBPCrypto._imp_ed25519()
key = ed25519_mod.Ed25519PrivateKey.from_private_bytes(ed25519_private_key)
key = _ModuleCache.ed25519().Ed25519PrivateKey.from_private_bytes(ed25519_private_key)
s = _ModuleCache.serialization()
pub_bytes = key.public_key().public_bytes(
NBPCrypto._imp_serialization().Encoding.Raw,
NBPCrypto._imp_serialization().PublicFormat.Raw
s.Encoding.Raw, s.PublicFormat.Raw
)
zf.writestr(NBPFFormatter.SIGNER_PEM, pub_bytes)