X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2Fcorlib%2FSystem.Security.Cryptography%2FAsymmetricAlgorithm.cs;h=9447908dd9233a69934207617aa120309fa49ba1;hb=5760f579fb341ebc89adef52db260d78535cb7da;hp=651906bbf8df12b591e6b428b6a02032b3ac51c6;hpb=22fa9bf079cf1db58244ddbd0b49fe262061974d;p=mono.git diff --git a/mcs/class/corlib/System.Security.Cryptography/AsymmetricAlgorithm.cs b/mcs/class/corlib/System.Security.Cryptography/AsymmetricAlgorithm.cs old mode 100755 new mode 100644 index 651906bbf8d..9447908dd92 --- a/mcs/class/corlib/System.Security.Cryptography/AsymmetricAlgorithm.cs +++ b/mcs/class/corlib/System.Security.Cryptography/AsymmetricAlgorithm.cs @@ -1,134 +1,97 @@ -// -// System.Security.Cryptography.AsymmetricAlgorithm Class implementation -// -// Authors: -// Thomas Neidhart (tome@sbox.tugraz.at) -// Sebastien Pouliot (spouliot@motus.com) -// -// Portions (C) 2002 Motus Technologies Inc. (http://www.motus.com) -// - -using System; -using System.Xml; - -namespace System.Security.Cryptography { - - /// - /// Abstract base class for all cryptographic asymmetric algorithms. - /// Available algorithms include: - /// RSA, DSA - /// - public abstract class AsymmetricAlgorithm : IDisposable { - - protected int KeySizeValue; // The size of the secret key used by the symmetric algorithm in bits. - protected KeySizes[] LegalKeySizesValue; // Specifies the key sizes that are supported by the symmetric algorithm. - - /// - /// Called from constructor of derived class. - /// - protected AsymmetricAlgorithm () {} - - /// - /// Gets the key exchange algorithm - /// - public abstract string KeyExchangeAlgorithm {get;} - - /// - /// Gets or sets the actual key size - /// - public virtual int KeySize { - get { - return this.KeySizeValue; - } - set { - if (!IsLegalKeySize(this.LegalKeySizesValue, value)) - throw new CryptographicException("key size not supported by algorithm"); - - this.KeySizeValue = value; - } - } - - /// - /// Gets all legal key sizes - /// - public virtual KeySizes[] LegalKeySizes { - get { - return this.LegalKeySizesValue; - } - } - - /// - /// Gets the signature algorithm - /// - public abstract string SignatureAlgorithm {get;} - - void System.IDisposable.Dispose() - { - } - - public void Clear() - { -// Dispose(); - } - - protected abstract void Dispose (bool disposing); - - // helper function for FromXmlString (used in RSA and DSA) - protected byte[] GetElement (XmlDocument xml, string tag) - { - XmlNodeList xnl = xml.GetElementsByTagName (tag); - if (xnl.Count > 0) - return Convert.FromBase64String (xnl[0].InnerText); - else - return null; - } - - /// - /// Reconstructs the AsymmetricAlgorithm Object from an XML-string - /// - public abstract void FromXmlString(string xmlString); - - /// - /// Returns an XML string representation the current AsymmetricAlgorithm object - /// - public abstract string ToXmlString(bool includePrivateParameters); - - private bool IsLegalKeySize(KeySizes[] LegalKeys, int Size) - { - foreach (KeySizes LegalKeySize in LegalKeys) { - for (int i=LegalKeySize.MinSize; i<=LegalKeySize.MaxSize; i+=LegalKeySize.SkipSize) { - if (i == Size) - return true; - } - } - return false; - } - - /// - /// Checks wether the given keyLength is valid for the current algorithm - /// - /// the given keyLength - public bool ValidKeySize(int bitLength) - { - return IsLegalKeySize(LegalKeySizesValue, bitLength); - } - - /// - /// Creates the default implementation of the default asymmetric algorithm (RSA). - /// - public static AsymmetricAlgorithm Create () - { - return Create ("System.Security.Cryptography.AsymmetricAlgorithm"); - } - - /// - /// Creates a specific implementation of the given asymmetric algorithm. - /// - /// Specifies which derived class to create - public static AsymmetricAlgorithm Create (string algName) - { - return (AsymmetricAlgorithm) CryptoConfig.CreateFromName (algName); - } - } -} - +// +// System.Security.Cryptography.AsymmetricAlgorithm Class implementation +// +// Authors: +// Thomas Neidhart (tome@sbox.tugraz.at) +// Sebastien Pouliot (sebastien@ximian.com) +// +// Portions (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) +// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System.Globalization; +using System.Runtime.InteropServices; + +namespace System.Security.Cryptography { + +#if NET_2_0 + [ComVisible (true)] +#endif + public abstract class AsymmetricAlgorithm : IDisposable { + + protected int KeySizeValue; + protected KeySizes[] LegalKeySizesValue; + + protected AsymmetricAlgorithm () + { + } + + public abstract string KeyExchangeAlgorithm { + get; + } + + public virtual int KeySize { + get { return this.KeySizeValue; } + set { + if (!KeySizes.IsLegalKeySize (this.LegalKeySizesValue, value)) + throw new CryptographicException (Locale.GetText ("Key size not supported by algorithm.")); + + this.KeySizeValue = value; + } + } + + public virtual KeySizes[] LegalKeySizes { + get { return this.LegalKeySizesValue; } + } + + public abstract string SignatureAlgorithm { + get; + } + + void IDisposable.Dispose () + { + Dispose (true); + GC.SuppressFinalize (this); // Finalization is now unnecessary + } + + public void Clear () + { + Dispose (false); + } + + protected abstract void Dispose (bool disposing); + + public abstract void FromXmlString (string xmlString); + + public abstract string ToXmlString (bool includePrivateParameters); + + public static AsymmetricAlgorithm Create () + { + return Create ("System.Security.Cryptography.AsymmetricAlgorithm"); + } + + public static AsymmetricAlgorithm Create (string algName) + { + return (AsymmetricAlgorithm) CryptoConfig.CreateFromName (algName); + } + } +}