search and ai stabilization work, localization stablized.

This commit is contained in:
master
2026-02-24 23:29:36 +02:00
parent 4f947a8b61
commit b07d27772e
766 changed files with 55299 additions and 3221 deletions

View File

@@ -1,4 +1,3 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
@@ -15,6 +14,7 @@ using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using static StellaOps.Localization.T;
namespace StellaOps.Cryptography.Plugin.SmSoft;
@@ -61,14 +61,14 @@ public sealed class SmSoftCryptoProvider : ICryptoProvider, ICryptoProviderDiagn
}
public IPasswordHasher GetPasswordHasher(string algorithmId)
=> throw new NotSupportedException("SM provider does not expose password hashing.");
=> throw new NotSupportedException(_t("crypto.sm.no_password_hashing"));
public ICryptoHasher GetHasher(string algorithmId)
{
EnsureAllowed();
if (!string.Equals(algorithmId, HashAlgorithms.Sm3, StringComparison.OrdinalIgnoreCase))
{
throw new InvalidOperationException($"Hash algorithm '{algorithmId}' is not supported by provider '{Name}'.");
throw new InvalidOperationException(_t("crypto.provider.hash_not_supported", algorithmId, Name));
}
return new Sm3CryptoHasher();
@@ -81,12 +81,12 @@ public sealed class SmSoftCryptoProvider : ICryptoProvider, ICryptoProviderDiagn
if (!string.Equals(algorithmId, SignatureAlgorithms.Sm2, StringComparison.OrdinalIgnoreCase))
{
throw new InvalidOperationException($"Signing algorithm '{algorithmId}' is not supported by provider '{Name}'.");
throw new InvalidOperationException(_t("crypto.provider.algorithm_not_supported", algorithmId, Name));
}
if (!keys.TryGetValue(keyReference.KeyId, out var entry))
{
throw new KeyNotFoundException($"Signing key '{keyReference.KeyId}' is not registered with provider '{Name}'.");
throw new KeyNotFoundException(_t("crypto.provider.key_not_registered", keyReference.KeyId, Name));
}
return new Sm2SoftSigner(entry);
@@ -99,13 +99,13 @@ public sealed class SmSoftCryptoProvider : ICryptoProvider, ICryptoProviderDiagn
if (!string.Equals(signingKey.AlgorithmId, SignatureAlgorithms.Sm2, StringComparison.OrdinalIgnoreCase))
{
throw new InvalidOperationException($"Signing algorithm '{signingKey.AlgorithmId}' is not supported by provider '{Name}'.");
throw new InvalidOperationException(_t("crypto.provider.algorithm_not_supported", signingKey.AlgorithmId, Name));
}
// Accept raw key bytes (PKCS#8 DER) or ECParameters are not SM2-compatible in BCL.
if (signingKey.PrivateKey.IsEmpty)
{
throw new InvalidOperationException("SM2 provider requires raw private key bytes (PKCS#8 DER).");
throw new InvalidOperationException(_t("crypto.sm.raw_key_required"));
}
var keyPair = LoadKeyPair(signingKey.PrivateKey.ToArray());
@@ -158,8 +158,7 @@ public sealed class SmSoftCryptoProvider : ICryptoProvider, ICryptoProviderDiagn
{
if (!GateEnabled())
{
throw new InvalidOperationException(
$"Provider '{Name}' is disabled. Set {EnvGate}=1 (or disable RequireEnvironmentGate) to enable software SM2/SM3.");
throw new InvalidOperationException(_t("crypto.sm.disabled", Name, EnvGate));
}
}
@@ -215,7 +214,7 @@ public sealed class SmSoftCryptoProvider : ICryptoProvider, ICryptoProviderDiagn
return new AsymmetricCipherKeyPair(pub, ecPriv);
}
throw new InvalidOperationException("Unsupported SM2 key format. Expect PEM or PKCS#8 DER.");
throw new InvalidOperationException(_t("crypto.sm.unsupported_format"));
}
}

View File

@@ -15,5 +15,6 @@
<ItemGroup>
<ProjectReference Include="..\StellaOps.Cryptography\StellaOps.Cryptography.csproj" />
<ProjectReference Include="..\StellaOps.Plugin\StellaOps.Plugin.csproj" />
<ProjectReference Include="..\StellaOps.Localization\StellaOps.Localization.csproj" />
</ItemGroup>
</Project>