3 files changed, 80 insertions, 0 deletions
diff --git a/crypto/src/util/Arrays.cs b/crypto/src/util/Arrays.cs
index 5eab42bd7..d90bbdd90 100644
--- a/crypto/src/util/Arrays.cs
+++ b/crypto/src/util/Arrays.cs
@@ -236,6 +236,30 @@ namespace Org.BouncyCastle.Utilities
}
}
+ [CLSCompliantAttribute(false)]
+ public static ulong[] Clone(
+ ulong[] data)
+ {
+ return data == null ? null : (ulong[]) data.Clone();
+ }
+
+ [CLSCompliantAttribute(false)]
+ public static ulong[] Clone(
+ ulong[] data,
+ ulong[] existing)
+ {
+ 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 byte[] Copy(byte[] data, int off, int len)
{
byte[] result = new byte[len];
diff --git a/crypto/src/util/IMemoable.cs b/crypto/src/util/IMemoable.cs
new file mode 100644
index 000000000..befc10fbf
--- /dev/null
+++ b/crypto/src/util/IMemoable.cs
@@ -0,0 +1,29 @@
+using System;
+
+namespace Org.BouncyCastle.Utilities
+{
+ public interface IMemoable
+ {
+ /// <summary>
+ /// Produce a copy of this object with its configuration and in its current state.
+ /// </summary>
+ /// <remarks>
+ /// The returned object may be used simply to store the state, or may be used as a similar object
+ /// starting from the copied state.
+ /// </remarks>
+ IMemoable Copy();
+
+ /// <summary>
+ /// Restore a copied object state into this object.
+ /// </summary>
+ /// <remarks>
+ /// Implementations of this method <em>should</em> try to avoid or minimise memory allocation to perform the reset.
+ /// </remarks>
+ /// <param name="other">an object originally {@link #copy() copied} from an object of the same type as this instance.</param>
+ /// <exception cref="ClassCastException">if the provided object is not of the correct type.</exception>
+ /// <exception cref="MemoableResetException">if the <b>other</b> parameter is in some other way invalid.</exception>
+ void Reset(IMemoable other);
+ }
+
+}
+
diff --git a/crypto/src/util/MemoableResetException.cs b/crypto/src/util/MemoableResetException.cs
new file mode 100644
index 000000000..d9542dab2
--- /dev/null
+++ b/crypto/src/util/MemoableResetException.cs
@@ -0,0 +1,27 @@
+using System;
+
+namespace Org.BouncyCastle.Utilities
+{
+ /**
+ * Exception to be thrown on a failure to reset an object implementing Memoable.
+ * <p>
+ * The exception extends ClassCastException to enable users to have a single handling case,
+ * only introducing specific handling of this one if required.
+ * </p>
+ */
+ public class MemoableResetException
+ : InvalidCastException
+ {
+ /**
+ * Basic Constructor.
+ *
+ * @param msg message to be associated with this exception.
+ */
+ public MemoableResetException(string msg)
+ : base(msg)
+ {
+ }
+ }
+
+}
+
|