search and ai stabilization work, localization stablized.
This commit is contained in:
@@ -3,6 +3,7 @@ using Org.BouncyCastle.Asn1;
|
||||
using Org.BouncyCastle.Math;
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using static StellaOps.Localization.T;
|
||||
|
||||
namespace StellaOps.Cryptography;
|
||||
|
||||
@@ -41,13 +42,13 @@ public static class GostSignatureEncoding
|
||||
{
|
||||
if (!IsDer(der))
|
||||
{
|
||||
throw new CryptographicException("Signature is not DER encoded.");
|
||||
throw new CryptographicException(_t("crypto.gost.not_der"));
|
||||
}
|
||||
|
||||
var sequence = Asn1Sequence.GetInstance(Asn1Object.FromByteArray(der.ToArray()));
|
||||
if (sequence.Count != 2)
|
||||
{
|
||||
throw new CryptographicException("Invalid DER structure for GOST signature.");
|
||||
throw new CryptographicException(_t("crypto.gost.invalid_der"));
|
||||
}
|
||||
|
||||
var r = NormalizeCoordinate(((DerInteger)sequence[0]).PositiveValue.ToByteArrayUnsigned(), coordinateLength);
|
||||
@@ -63,7 +64,7 @@ public static class GostSignatureEncoding
|
||||
{
|
||||
if (raw.Length != coordinateLength * 2)
|
||||
{
|
||||
throw new CryptographicException($"Raw GOST signature must be {coordinateLength * 2} bytes.");
|
||||
throw new CryptographicException(_t("crypto.gost.raw_length", coordinateLength * 2));
|
||||
}
|
||||
|
||||
var s = raw[..coordinateLength].ToArray();
|
||||
@@ -83,7 +84,7 @@ public static class GostSignatureEncoding
|
||||
var sequence = Asn1Sequence.GetInstance(Asn1Object.FromByteArray(signature.ToArray()));
|
||||
if (sequence.Count != 2)
|
||||
{
|
||||
throw new CryptographicException("Invalid DER structure for GOST signature.");
|
||||
throw new CryptographicException(_t("crypto.gost.invalid_der"));
|
||||
}
|
||||
|
||||
return (((DerInteger)sequence[0]).PositiveValue, ((DerInteger)sequence[1]).PositiveValue);
|
||||
@@ -98,7 +99,7 @@ public static class GostSignatureEncoding
|
||||
return (new BigInteger(1, r), new BigInteger(1, s));
|
||||
}
|
||||
|
||||
throw new CryptographicException("Signature payload is neither DER nor raw GOST format.");
|
||||
throw new CryptographicException(_t("crypto.gost.neither_format"));
|
||||
}
|
||||
|
||||
private static byte[] NormalizeCoordinate(ReadOnlySpan<byte> value, int coordinateLength)
|
||||
@@ -106,7 +107,7 @@ public static class GostSignatureEncoding
|
||||
var trimmed = TrimLeadingZeros(value);
|
||||
if (trimmed.Length > coordinateLength)
|
||||
{
|
||||
throw new CryptographicException("Coordinate exceeds expected length.");
|
||||
throw new CryptographicException(_t("crypto.gost.coordinate_overflow"));
|
||||
}
|
||||
|
||||
var output = new byte[coordinateLength];
|
||||
|
||||
Reference in New Issue
Block a user