diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2021-11-06 11:14:41 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2021-11-06 11:14:41 +0700 |
commit | 07fd9c25ff3aae8f3f4209b6e1815fa65a1b5685 (patch) | |
tree | 49f90b9dbfe42458ffe8a5e3eb597a2adf806541 /crypto/src/util | |
parent | TLS: Improve ASN.1 parsing (diff) | |
download | BouncyCastle.NET-ed25519-07fd9c25ff3aae8f3f4209b6e1815fa65a1b5685.tar.xz |
Refactoring
Diffstat (limited to 'crypto/src/util')
-rw-r--r-- | crypto/src/util/BigIntegers.cs | 11 |
1 files changed, 6 insertions, 5 deletions
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; } |