1 files changed, 27 insertions, 11 deletions
diff --git a/crypto/src/util/Arrays.cs b/crypto/src/util/Arrays.cs
index d90bbdd90..59c91bdd1 100644
--- a/crypto/src/util/Arrays.cs
+++ b/crypto/src/util/Arrays.cs
@@ -219,21 +219,26 @@ namespace Org.BouncyCastle.Utilities
return data == null ? null : (byte[]) data.Clone();
}
- public static int[] Clone(
- int[] data)
+ public static byte[] Clone(
+ byte[] data,
+ byte[] existing)
{
- return data == null ? null : (int[]) data.Clone();
+ if (data == null)
+ {
+ return null;
+ }
+ if ((existing == null) || (existing.Length != data.Length))
+ {
+ return Clone(data);
+ }
+ Array.Copy(data, 0, existing, 0, existing.Length);
+ return existing;
}
- public static void Fill(
- byte[] buf,
- byte b)
+ public static int[] Clone(
+ int[] data)
{
- int i = buf.Length;
- while (i > 0)
- {
- buf[--i] = b;
- }
+ return data == null ? null : (int[]) data.Clone();
}
[CLSCompliantAttribute(false)]
@@ -260,6 +265,17 @@ namespace Org.BouncyCastle.Utilities
return existing;
}
+ public static void Fill(
+ byte[] buf,
+ byte b)
+ {
+ int i = buf.Length;
+ while (i > 0)
+ {
+ buf[--i] = b;
+ }
+ }
+
public static byte[] Copy(byte[] data, int off, int len)
{
byte[] result = new byte[len];
|