summary refs log tree commit diff
path: root/crypto/src/util/BigIntegers.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/util/BigIntegers.cs')
-rw-r--r--crypto/src/util/BigIntegers.cs11
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;
         }