X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2Freferencesource%2FSystem.Core%2FSystem%2FSecurity%2FCryptography%2FECDsa.cs;h=22fb8b505282c8c34974ef47c336b90df0c1e7ba;hb=215901f51bf00e9d1e58cada05033aae8283e336;hp=a161a6a186f59fda7436f49a8ff6520281006fac;hpb=10e54be5f860d412d2ab5b193de582e232ceeb7e;p=mono.git diff --git a/mcs/class/referencesource/System.Core/System/Security/Cryptography/ECDsa.cs b/mcs/class/referencesource/System.Core/System/Security/Cryptography/ECDsa.cs index a161a6a186f..22fb8b50528 100644 --- a/mcs/class/referencesource/System.Core/System/Security/Cryptography/ECDsa.cs +++ b/mcs/class/referencesource/System.Core/System/Security/Cryptography/ECDsa.cs @@ -5,6 +5,7 @@ // ==--== using System; +using System.IO; namespace System.Security.Cryptography { /// @@ -44,7 +45,97 @@ namespace System.Security.Cryptography { // Signature operations // + // ECDsa does not encode the algorithm identifier into the signature blob, therefore SignHash and VerifyHash + // do not need the HashAlgorithmName value, only SignData and VerifyData do. public abstract byte[] SignHash(byte[] hash); public abstract bool VerifyHash(byte[] hash, byte[] signature); + + protected virtual byte[] HashData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm) { + throw DerivedClassMustOverride(); + } + + protected virtual byte[] HashData(Stream data, HashAlgorithmName hashAlgorithm) { + throw DerivedClassMustOverride(); + } + + public virtual byte[] SignData(byte[] data, HashAlgorithmName hashAlgorithm) { + if (data == null) { + throw new ArgumentNullException("data"); + } + return SignData(data, 0, data.Length, hashAlgorithm); + } + + public virtual byte[] SignData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm) { + if (data == null) { throw new ArgumentNullException("data"); } + if (offset < 0 || offset > data.Length) { throw new ArgumentOutOfRangeException("offset"); } + if (count < 0 || count > data.Length - offset) { throw new ArgumentOutOfRangeException("count"); } + if (String.IsNullOrEmpty(hashAlgorithm.Name)) { throw HashAlgorithmNameNullOrEmpty(); } + + byte[] hash = HashData(data, offset, count, hashAlgorithm); + return SignHash(hash); + } + + public virtual byte[] SignData(Stream data, HashAlgorithmName hashAlgorithm) { + if (data == null) { + throw new ArgumentNullException("data"); + } + if (String.IsNullOrEmpty(hashAlgorithm.Name)) { + throw HashAlgorithmNameNullOrEmpty(); + } + + byte[] hash = HashData(data, hashAlgorithm); + return SignHash(hash); + } + + public bool VerifyData(byte[] data, byte[] signature, HashAlgorithmName hashAlgorithm) { + if (data == null) { + throw new ArgumentNullException("data"); + } + return VerifyData(data, 0, data.Length, signature, hashAlgorithm); + } + + public virtual bool VerifyData(byte[] data, int offset, int count, byte[] signature, HashAlgorithmName hashAlgorithm) { + if (data == null) { + throw new ArgumentNullException("data"); + } + if (offset < 0 || offset > data.Length) { + throw new ArgumentOutOfRangeException("offset"); + } + if (count < 0 || count > data.Length - offset) { + throw new ArgumentOutOfRangeException("count"); + } + if (signature == null) { + throw new ArgumentNullException("signature"); + } + if (String.IsNullOrEmpty(hashAlgorithm.Name)) { + throw HashAlgorithmNameNullOrEmpty(); + } + + byte[] hash = HashData(data, offset, count, hashAlgorithm); + return VerifyHash(hash, signature); + } + + public bool VerifyData(Stream data, byte[] signature, HashAlgorithmName hashAlgorithm) { + if (data == null) { + throw new ArgumentNullException("data"); + } + if (signature == null) { + throw new ArgumentNullException("signature"); + } + if (String.IsNullOrEmpty(hashAlgorithm.Name)) { + throw HashAlgorithmNameNullOrEmpty(); + } + + byte[] hash = HashData(data, hashAlgorithm); + return VerifyHash(hash, signature); + } + + private static Exception DerivedClassMustOverride() { + return new NotImplementedException(SR.GetString(SR.NotSupported_SubclassOverride)); + } + + internal static Exception HashAlgorithmNameNullOrEmpty() { + return new ArgumentException(SR.GetString(SR.Cryptography_HashAlgorithmNameNullOrEmpty), "hashAlgorithm"); + } } }