Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Web / Configuration / MachineKeyValidationConverter.cs / 1305376 / MachineKeyValidationConverter.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- using System; using System.Collections; using System.IO; using System.Reflection; using System.Security.Permissions; using System.Xml; using System.Collections.Specialized; using System.Globalization; using System.ComponentModel; using System.Security; using System.Text; using System.Configuration; namespace System.Web.Configuration { [System.Security.Permissions.HostProtection(MayLeakOnAbort = true)] public sealed class MachineKeyValidationConverter : ConfigurationConverterBase { public override object ConvertTo(ITypeDescriptorContext ctx, CultureInfo ci, object value, Type type) { if (!(value is MachineKeyValidation)) { throw new ArgumentException(SR.GetString(SR.Config_Invalid_enum_value, "SHA1, MD5, 3DES, AES, HMACSHA256, HMACSHA384, HMACSHA512")); } return ConvertFromEnum((MachineKeyValidation)value); } public override object ConvertFrom(ITypeDescriptorContext ctx, CultureInfo ci, object data) { return ConvertToEnum((string)data); } internal static string ConvertFromEnum(MachineKeyValidation enumValue) { switch (enumValue) { case MachineKeyValidation.SHA1: return "SHA1"; case MachineKeyValidation.MD5: return "MD5"; case MachineKeyValidation.TripleDES: return "3DES"; case MachineKeyValidation.AES: return "AES"; case MachineKeyValidation.HMACSHA256: return "HMACSHA256"; case MachineKeyValidation.HMACSHA384: return "HMACSHA384"; case MachineKeyValidation.HMACSHA512: return "HMACSHA512"; default: throw new ArgumentException(SR.GetString(SR.Wrong_validation_enum)); } } internal static MachineKeyValidation ConvertToEnum(string strValue) { if (strValue==null) return MachineKeySection.DefaultValidation; switch (strValue) { case "SHA1": return MachineKeyValidation.SHA1; case "MD5": return MachineKeyValidation.MD5; case "3DES": return MachineKeyValidation.TripleDES; case "AES": return MachineKeyValidation.AES; case "HMACSHA256": return MachineKeyValidation.HMACSHA256; case "HMACSHA384": return MachineKeyValidation.HMACSHA384; case "HMACSHA512": return MachineKeyValidation.HMACSHA512; default: if (strValue.StartsWith("alg:", StringComparison.Ordinal)) return MachineKeyValidation.Custom; throw new ArgumentException(SR.GetString(SR.Wrong_validation_enum)); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- using System; using System.Collections; using System.IO; using System.Reflection; using System.Security.Permissions; using System.Xml; using System.Collections.Specialized; using System.Globalization; using System.ComponentModel; using System.Security; using System.Text; using System.Configuration; namespace System.Web.Configuration { [System.Security.Permissions.HostProtection(MayLeakOnAbort = true)] public sealed class MachineKeyValidationConverter : ConfigurationConverterBase { public override object ConvertTo(ITypeDescriptorContext ctx, CultureInfo ci, object value, Type type) { if (!(value is MachineKeyValidation)) { throw new ArgumentException(SR.GetString(SR.Config_Invalid_enum_value, "SHA1, MD5, 3DES, AES, HMACSHA256, HMACSHA384, HMACSHA512")); } return ConvertFromEnum((MachineKeyValidation)value); } public override object ConvertFrom(ITypeDescriptorContext ctx, CultureInfo ci, object data) { return ConvertToEnum((string)data); } internal static string ConvertFromEnum(MachineKeyValidation enumValue) { switch (enumValue) { case MachineKeyValidation.SHA1: return "SHA1"; case MachineKeyValidation.MD5: return "MD5"; case MachineKeyValidation.TripleDES: return "3DES"; case MachineKeyValidation.AES: return "AES"; case MachineKeyValidation.HMACSHA256: return "HMACSHA256"; case MachineKeyValidation.HMACSHA384: return "HMACSHA384"; case MachineKeyValidation.HMACSHA512: return "HMACSHA512"; default: throw new ArgumentException(SR.GetString(SR.Wrong_validation_enum)); } } internal static MachineKeyValidation ConvertToEnum(string strValue) { if (strValue==null) return MachineKeySection.DefaultValidation; switch (strValue) { case "SHA1": return MachineKeyValidation.SHA1; case "MD5": return MachineKeyValidation.MD5; case "3DES": return MachineKeyValidation.TripleDES; case "AES": return MachineKeyValidation.AES; case "HMACSHA256": return MachineKeyValidation.HMACSHA256; case "HMACSHA384": return MachineKeyValidation.HMACSHA384; case "HMACSHA512": return MachineKeyValidation.HMACSHA512; default: if (strValue.StartsWith("alg:", StringComparison.Ordinal)) return MachineKeyValidation.Custom; throw new ArgumentException(SR.GetString(SR.Wrong_validation_enum)); } } } } // 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
- WinFormsComponentEditor.cs
- CommandBinding.cs
- SqlDataReader.cs
- StyleSheetDesigner.cs
- XpsPartBase.cs
- DynamicAttribute.cs
- TimeSpan.cs
- DemultiplexingClientMessageFormatter.cs
- EndOfStreamException.cs
- MetadataSerializer.cs
- TreeIterator.cs
- PrinterResolution.cs
- UIElementParagraph.cs
- TraceContextEventArgs.cs
- FlowDocumentReaderAutomationPeer.cs
- QilXmlReader.cs
- DataDocumentXPathNavigator.cs
- SqlNotificationRequest.cs
- AssemblyNameProxy.cs
- BinHexEncoder.cs
- versioninfo.cs
- SystemDropShadowChrome.cs
- SqlInternalConnectionSmi.cs
- DocComment.cs
- Delegate.cs
- SQLMoney.cs
- StreamWithDictionary.cs
- EastAsianLunisolarCalendar.cs
- XPathDocumentIterator.cs
- PageContentCollection.cs
- UIElement3DAutomationPeer.cs
- _NestedMultipleAsyncResult.cs
- CFStream.cs
- safemediahandle.cs
- ToolstripProfessionalRenderer.cs
- SchemaManager.cs
- OracleDataAdapter.cs
- UserMapPath.cs
- FixedPageStructure.cs
- HwndPanningFeedback.cs
- ResourceLoader.cs
- GenericTransactionFlowAttribute.cs
- DataKeyCollection.cs
- FontCacheUtil.cs
- parserscommon.cs
- WindowHideOrCloseTracker.cs
- TranslateTransform3D.cs
- NativeMethods.cs
- Accessible.cs
- ServicePoint.cs
- FamilyMap.cs
- StdValidatorsAndConverters.cs
- RSAPKCS1SignatureDeformatter.cs
- DbProviderFactoriesConfigurationHandler.cs
- DrawToolTipEventArgs.cs
- ConnectionsZone.cs
- ValidationHelper.cs
- Accessors.cs
- EllipseGeometry.cs
- OleDbParameterCollection.cs
- TreeViewImageKeyConverter.cs
- wmiprovider.cs
- ToolStripItem.cs
- ExpressionNode.cs
- UrlAuthorizationModule.cs
- TextSpan.cs
- CheckBoxBaseAdapter.cs
- CompilerInfo.cs
- AssemblyHash.cs
- documentation.cs
- FixedSOMPageConstructor.cs
- ReferencedAssembly.cs
- GridItemProviderWrapper.cs
- SynchronizationContext.cs
- ClickablePoint.cs
- DrawingContextDrawingContextWalker.cs
- MissingManifestResourceException.cs
- ErrorRuntimeConfig.cs
- WebPartPersonalization.cs
- Transform.cs
- Wizard.cs
- ADRoleFactoryConfiguration.cs
- PathSegmentCollection.cs
- CollectionView.cs
- SqlNotificationRequest.cs
- ValidateNames.cs
- AmbientValueAttribute.cs
- Int64.cs
- CodeDomDesignerLoader.cs
- Assert.cs
- IdentityReference.cs
- PeerPresenceInfo.cs
- FunctionOverloadResolver.cs
- DataListItemEventArgs.cs
- ContentIterators.cs
- Adorner.cs
- WebConfigurationFileMap.cs
- StringComparer.cs
- ClockController.cs
- TextSerializer.cs