summary refs log tree commit diff
path: root/crypto/src
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2021-11-06 11:14:41 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2021-11-06 11:14:41 +0700
commit07fd9c25ff3aae8f3f4209b6e1815fa65a1b5685 (patch)
tree49f90b9dbfe42458ffe8a5e3eb597a2adf806541 /crypto/src
parentTLS: Improve ASN.1 parsing (diff)
downloadBouncyCastle.NET-ed25519-07fd9c25ff3aae8f3f4209b6e1815fa65a1b5685.tar.xz
Refactoring
Diffstat (limited to 'crypto/src')
-rw-r--r--crypto/src/security/DotNetUtilities.cs14
-rw-r--r--crypto/src/util/BigIntegers.cs11
2 files changed, 8 insertions, 17 deletions
diff --git a/crypto/src/security/DotNetUtilities.cs b/crypto/src/security/DotNetUtilities.cs

index df9d327de..f0064fb3d 100644 --- a/crypto/src/security/DotNetUtilities.cs +++ b/crypto/src/security/DotNetUtilities.cs
@@ -9,6 +9,7 @@ using Org.BouncyCastle.Asn1.X509; using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Math; +using Org.BouncyCastle.Utilities; using Org.BouncyCastle.X509; namespace Org.BouncyCastle.Security @@ -223,20 +224,9 @@ namespace Org.BouncyCastle.Security return rp; } - // TODO Move functionality to more general class private static byte[] ConvertRSAParametersField(BigInteger n, int size) { - byte[] bs = n.ToByteArrayUnsigned(); - - if (bs.Length == size) - return bs; - - if (bs.Length > size) - throw new ArgumentException("Specified size too small", "size"); - - byte[] padded = new byte[size]; - Array.Copy(bs, 0, padded, size - bs.Length, bs.Length); - return padded; + return BigIntegers.AsUnsignedByteArray(size, n); } private static RSA CreateRSAProvider(RSAParameters rp) diff --git a/crypto/src/util/BigIntegers.cs b/crypto/src/util/BigIntegers.cs
index d9c898676..a61824394 100644 --- a/crypto/src/util/BigIntegers.cs +++ b/crypto/src/util/BigIntegers.cs
@@ -38,15 +38,16 @@ namespace Org.BouncyCastle.Utilities public static byte[] AsUnsignedByteArray(int length, BigInteger n) { byte[] bytes = n.ToByteArrayUnsigned(); + int bytesLength = bytes.Length; - if (bytes.Length > length) - throw new ArgumentException("standard length exceeded", "n"); - - if (bytes.Length == length) + if (bytesLength == length) return bytes; + if (bytesLength > length) + throw new ArgumentException("standard length exceeded", "n"); + byte[] tmp = new byte[length]; - Array.Copy(bytes, 0, tmp, tmp.Length - bytes.Length, bytes.Length); + Array.Copy(bytes, 0, tmp, length - bytesLength, bytesLength); return tmp; }