Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Core / System / Security / Cryptography / CngAlgorithmGroup.cs / 1305376 / CngAlgorithmGroup.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== using System; using System.Diagnostics.Contracts; namespace System.Security.Cryptography { ////// Utility class to strongly type algorithm groups used with CNG. Since all CNG APIs which require or /// return an algorithm group name take the name as a string, we use this string wrapper class to /// specifically mark which parameters and return values are expected to be algorithm groups. We also /// provide a list of well known algorithm group names, which helps Intellisense users find a set of /// good algorithm group names to use. /// [Serializable] [System.Security.Permissions.HostProtection(MayLeakOnAbort = true)] public sealed class CngAlgorithmGroup : IEquatable{ private static CngAlgorithmGroup s_dh; private static CngAlgorithmGroup s_dsa; private static CngAlgorithmGroup s_ecdh; private static CngAlgorithmGroup s_ecdsa; private static CngAlgorithmGroup s_rsa; private string m_algorithmGroup; public CngAlgorithmGroup(string algorithmGroup) { Contract.Ensures(!String.IsNullOrEmpty(m_algorithmGroup)); if (algorithmGroup == null) { throw new ArgumentNullException("algorithmGroup"); } if (algorithmGroup.Length == 0) { throw new ArgumentException(SR.GetString(SR.Cryptography_InvalidAlgorithmGroup, algorithmGroup), "algorithmGroup"); } m_algorithmGroup = algorithmGroup; } /// /// Name of the algorithm group /// public string AlgorithmGroup { get { Contract.Ensures(!String.IsNullOrEmpty(Contract.Result())); return m_algorithmGroup; } } [Pure] public static bool operator ==(CngAlgorithmGroup left, CngAlgorithmGroup right) { if (Object.ReferenceEquals(left, null)) { return Object.ReferenceEquals(right, null); } return left.Equals(right); } [Pure] public static bool operator !=(CngAlgorithmGroup left, CngAlgorithmGroup right) { if (Object.ReferenceEquals(left, null)) { return !Object.ReferenceEquals(right, null); } return !left.Equals(right); } public override bool Equals(object obj) { Contract.Assert(m_algorithmGroup != null); return Equals(obj as CngAlgorithmGroup); } public bool Equals(CngAlgorithmGroup other) { if (Object.ReferenceEquals(other, null)) { return false; } return m_algorithmGroup.Equals(other.AlgorithmGroup); } public override int GetHashCode() { Contract.Assert(m_algorithmGroup != null); return m_algorithmGroup.GetHashCode(); } public override string ToString() { Contract.Assert(m_algorithmGroup != null); return m_algorithmGroup; } // // Well known algorithm groups // public static CngAlgorithmGroup DiffieHellman { get { Contract.Ensures(Contract.Result () != null); if (s_dh == null) { s_dh = new CngAlgorithmGroup("DH"); // NCRYPT_DH_ALGORITHM_GROUP } return s_dh; } } public static CngAlgorithmGroup Dsa { get { Contract.Ensures(Contract.Result () != null); if (s_dsa == null) { s_dsa = new CngAlgorithmGroup("DSA"); // NCRYPT_DSA_ALGORITHM_GROUP } return s_dsa; } } public static CngAlgorithmGroup ECDiffieHellman { [Pure] get { Contract.Ensures(Contract.Result () != null); if (s_ecdh == null) { s_ecdh = new CngAlgorithmGroup("ECDH"); // NCRYPT_ECDH_ALGORITHM_GROUP } return s_ecdh; } } public static CngAlgorithmGroup ECDsa { [Pure] get { Contract.Ensures(Contract.Result () != null); if (s_ecdsa == null) { s_ecdsa = new CngAlgorithmGroup("ECDSA"); // NCRYPT_ECDSA_ALGORITHM_GROUP } return s_ecdsa; } } public static CngAlgorithmGroup Rsa { get { Contract.Ensures(Contract.Result () != null); if (s_rsa == null) { s_rsa = new CngAlgorithmGroup("RSA"); // NCRYPT_RSA_ALGORITHM_GROUP } return s_rsa; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== using System; using System.Diagnostics.Contracts; namespace System.Security.Cryptography { /// /// Utility class to strongly type algorithm groups used with CNG. Since all CNG APIs which require or /// return an algorithm group name take the name as a string, we use this string wrapper class to /// specifically mark which parameters and return values are expected to be algorithm groups. We also /// provide a list of well known algorithm group names, which helps Intellisense users find a set of /// good algorithm group names to use. /// [Serializable] [System.Security.Permissions.HostProtection(MayLeakOnAbort = true)] public sealed class CngAlgorithmGroup : IEquatable{ private static CngAlgorithmGroup s_dh; private static CngAlgorithmGroup s_dsa; private static CngAlgorithmGroup s_ecdh; private static CngAlgorithmGroup s_ecdsa; private static CngAlgorithmGroup s_rsa; private string m_algorithmGroup; public CngAlgorithmGroup(string algorithmGroup) { Contract.Ensures(!String.IsNullOrEmpty(m_algorithmGroup)); if (algorithmGroup == null) { throw new ArgumentNullException("algorithmGroup"); } if (algorithmGroup.Length == 0) { throw new ArgumentException(SR.GetString(SR.Cryptography_InvalidAlgorithmGroup, algorithmGroup), "algorithmGroup"); } m_algorithmGroup = algorithmGroup; } /// /// Name of the algorithm group /// public string AlgorithmGroup { get { Contract.Ensures(!String.IsNullOrEmpty(Contract.Result())); return m_algorithmGroup; } } [Pure] public static bool operator ==(CngAlgorithmGroup left, CngAlgorithmGroup right) { if (Object.ReferenceEquals(left, null)) { return Object.ReferenceEquals(right, null); } return left.Equals(right); } [Pure] public static bool operator !=(CngAlgorithmGroup left, CngAlgorithmGroup right) { if (Object.ReferenceEquals(left, null)) { return !Object.ReferenceEquals(right, null); } return !left.Equals(right); } public override bool Equals(object obj) { Contract.Assert(m_algorithmGroup != null); return Equals(obj as CngAlgorithmGroup); } public bool Equals(CngAlgorithmGroup other) { if (Object.ReferenceEquals(other, null)) { return false; } return m_algorithmGroup.Equals(other.AlgorithmGroup); } public override int GetHashCode() { Contract.Assert(m_algorithmGroup != null); return m_algorithmGroup.GetHashCode(); } public override string ToString() { Contract.Assert(m_algorithmGroup != null); return m_algorithmGroup; } // // Well known algorithm groups // public static CngAlgorithmGroup DiffieHellman { get { Contract.Ensures(Contract.Result () != null); if (s_dh == null) { s_dh = new CngAlgorithmGroup("DH"); // NCRYPT_DH_ALGORITHM_GROUP } return s_dh; } } public static CngAlgorithmGroup Dsa { get { Contract.Ensures(Contract.Result () != null); if (s_dsa == null) { s_dsa = new CngAlgorithmGroup("DSA"); // NCRYPT_DSA_ALGORITHM_GROUP } return s_dsa; } } public static CngAlgorithmGroup ECDiffieHellman { [Pure] get { Contract.Ensures(Contract.Result () != null); if (s_ecdh == null) { s_ecdh = new CngAlgorithmGroup("ECDH"); // NCRYPT_ECDH_ALGORITHM_GROUP } return s_ecdh; } } public static CngAlgorithmGroup ECDsa { [Pure] get { Contract.Ensures(Contract.Result () != null); if (s_ecdsa == null) { s_ecdsa = new CngAlgorithmGroup("ECDSA"); // NCRYPT_ECDSA_ALGORITHM_GROUP } return s_ecdsa; } } public static CngAlgorithmGroup Rsa { get { Contract.Ensures(Contract.Result () != null); if (s_rsa == null) { s_rsa = new CngAlgorithmGroup("RSA"); // NCRYPT_RSA_ALGORITHM_GROUP } return s_rsa; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DataControlFieldCell.cs
- StrokeNodeOperations.cs
- _NativeSSPI.cs
- PaperSize.cs
- WebRequestModuleElement.cs
- InvalidProgramException.cs
- DownloadProgressEventArgs.cs
- ImpersonateTokenRef.cs
- IList.cs
- InputBinder.cs
- Stream.cs
- FileSystemWatcher.cs
- DiscoveryDocumentSerializer.cs
- OdbcConnectionString.cs
- ConditionCollection.cs
- base64Transforms.cs
- QuaternionAnimationBase.cs
- SystemException.cs
- XmlExpressionDumper.cs
- COM2Enum.cs
- TextServicesContext.cs
- KeysConverter.cs
- ParentQuery.cs
- GenericAuthenticationEventArgs.cs
- SecurityContext.cs
- ReadOnlyTernaryTree.cs
- OutKeywords.cs
- TreeNodeBindingCollection.cs
- SqlDataSourceCommandEventArgs.cs
- ActivityStateQuery.cs
- TextReader.cs
- UserMapPath.cs
- codemethodreferenceexpression.cs
- ObjectTag.cs
- HitTestWithPointDrawingContextWalker.cs
- XPathSelectionIterator.cs
- PeerNameRecord.cs
- XNodeNavigator.cs
- Translator.cs
- PageCache.cs
- DisplayInformation.cs
- MsmqInputChannelListenerBase.cs
- DataTableMapping.cs
- NameTable.cs
- BitmapMetadataEnumerator.cs
- PropertyDescriptors.cs
- InheritablePropertyChangeInfo.cs
- RtfNavigator.cs
- TemplateBindingExtensionConverter.cs
- RsaSecurityKey.cs
- SchemaElementLookUpTableEnumerator.cs
- TileBrush.cs
- DataGridViewTopLeftHeaderCell.cs
- DataSysAttribute.cs
- BaseProcessor.cs
- RedirectionProxy.cs
- ResourcesBuildProvider.cs
- ToolStripDropDownItem.cs
- ExpressionValueEditor.cs
- COAUTHINFO.cs
- SrgsGrammarCompiler.cs
- GlyphTypeface.cs
- Latin1Encoding.cs
- BasicSecurityProfileVersion.cs
- Point.cs
- CryptographicAttribute.cs
- MessageSecurityOverMsmqElement.cs
- CopyOnWriteList.cs
- ContainerSelectorBehavior.cs
- PngBitmapEncoder.cs
- Barrier.cs
- SmiTypedGetterSetter.cs
- DataGridView.cs
- HandleCollector.cs
- PageCatalogPart.cs
- SubMenuStyle.cs
- DataColumnMapping.cs
- ChannelManager.cs
- StrongNameUtility.cs
- DataKeyArray.cs
- TableLayoutCellPaintEventArgs.cs
- TimeManager.cs
- invalidudtexception.cs
- AdRotator.cs
- BindableTemplateBuilder.cs
- FileUtil.cs
- PathSegmentCollection.cs
- QuaternionAnimation.cs
- DataGridViewCellValidatingEventArgs.cs
- DataRecordObjectView.cs
- UInt32Storage.cs
- DocumentApplication.cs
- AssemblyAssociatedContentFileAttribute.cs
- MatrixIndependentAnimationStorage.cs
- KerberosTicketHashIdentifierClause.cs
- DesignerTransactionCloseEvent.cs
- QilTernary.cs
- NotSupportedException.cs
- ImageListImageEditor.cs
- _NTAuthentication.cs