summary refs log tree commit diff
path: root/crypto/src/util/encoders/HexEncoder.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2021-08-07 18:39:30 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2021-08-07 18:39:30 +0700
commitcba353364f04c58ad93dbbbac7a4414ea781b3a7 (patch)
tree28004ec3fbfd3c0c30fd0580e2eeced04050a0d6 /crypto/src/util/encoders/HexEncoder.cs
parentCleanup (diff)
downloadBouncyCastle.NET-ed25519-cba353364f04c58ad93dbbbac7a4414ea781b3a7.tar.xz
Fix Encode return values
Diffstat (limited to '')
-rw-r--r--crypto/src/util/encoders/HexEncoder.cs14
1 files changed, 7 insertions, 7 deletions
diff --git a/crypto/src/util/encoders/HexEncoder.cs b/crypto/src/util/encoders/HexEncoder.cs
index 090c9d7e3..bf68aff9d 100644
--- a/crypto/src/util/encoders/HexEncoder.cs
+++ b/crypto/src/util/encoders/HexEncoder.cs
@@ -63,14 +63,18 @@ namespace Org.BouncyCastle.Utilities.Encoders
         */
         public int Encode(byte[] buf, int off, int len, Stream outStream)
         {
+            if (len < 0)
+                return 0;
+
             byte[] tmp = new byte[72];
-            while (len > 0)
+            int remaining = len;
+            while (remaining > 0)
             {
-                int inLen = System.Math.Min(36, len);
+                int inLen = System.Math.Min(36, remaining);
                 int outLen = Encode(buf, off, inLen, tmp, 0);
                 outStream.Write(tmp, 0, outLen);
                 off += inLen;
-                len -= inLen;
+                remaining -= inLen;
             }
             return len * 2;
         }
@@ -101,9 +105,7 @@ namespace Org.BouncyCastle.Utilities.Encoders
             while (end > off)
             {
                 if (!Ignore((char)data[end - 1]))
-                {
                     break;
-                }
 
                 end--;
             }
@@ -166,9 +168,7 @@ namespace Org.BouncyCastle.Utilities.Encoders
             while (end > 0)
             {
                 if (!Ignore(data[end - 1]))
-                {
                     break;
-                }
 
                 end--;
             }