summary refs log tree commit diff
path: root/crypto/src/util
diff options
context:
space:
mode:
authorTim Whittington <bc@whittington.net.nz>2013-10-12 19:46:25 +1300
committerTim Whittington <bc@whittington.net.nz>2013-10-20 21:32:33 +1300
commitf64b37993aaec3f2baaab236af58c295b06c9f92 (patch)
treeced19bc4695aafe6112dbada80601d5cf8def51f /crypto/src/util
parentPort SkeinDigest and SkeinMac from bc-java. (diff)
downloadBouncyCastle.NET-ed25519-f64b37993aaec3f2baaab236af58c295b06c9f92.tar.xz
Port Memoable digest support from bc-java.
Diffstat (limited to 'crypto/src/util')
-rw-r--r--crypto/src/util/IMemoable.cs29
-rw-r--r--crypto/src/util/MemoableResetException.cs27
2 files changed, 56 insertions, 0 deletions
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)
+		{
+		}
+	}
+
+}
+