diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-01-21 16:46:07 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-01-21 16:46:07 +0700 |
commit | 95c58fd065df852598412fa8b7d06c3cee72c29c (patch) | |
tree | 01d8a520a72b008656881a37ec88d0ab2c98c361 /crypto/src/util | |
parent | Merge branch 'pkix-validator-throw' of git://github.com/jstedfast/bc-csharp i... (diff) | |
parent | Port HMac optimisation using Memoable digests from bc-java. (diff) | |
download | BouncyCastle.NET-ed25519-95c58fd065df852598412fa8b7d06c3cee72c29c.tar.xz |
Merge branch 'feature/threefish-skein-memoable-sm3' of git://github.com/timw/bc-csharp into timw-feature/threefish-skein-memoable-sm3
Conflicts: crypto/crypto.mdp crypto/src/util/Arrays.cs
Diffstat (limited to 'crypto/src/util')
-rw-r--r-- | crypto/src/util/Arrays.cs | 24 | ||||
-rw-r--r-- | crypto/src/util/IMemoable.cs | 29 | ||||
-rw-r--r-- | crypto/src/util/MemoableResetException.cs | 27 |
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) + { + } + } + +} + |