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
- SchemaHelper.cs
- IPGlobalProperties.cs
- CancelEventArgs.cs
- ObjectSecurity.cs
- ClientRuntimeConfig.cs
- VisualBasic.cs
- WebPartTransformerAttribute.cs
- OleTxTransaction.cs
- DataGridAutoFormatDialog.cs
- ProcessProtocolHandler.cs
- UpdateTranslator.cs
- WindowsStartMenu.cs
- DataRelation.cs
- BitStack.cs
- BamlResourceSerializer.cs
- ApplicationServicesHostFactory.cs
- AdvancedBindingPropertyDescriptor.cs
- TextTreeText.cs
- WsatAdminException.cs
- GeneralTransform3DTo2DTo3D.cs
- QueueException.cs
- SharedPersonalizationStateInfo.cs
- CounterSample.cs
- HierarchicalDataBoundControl.cs
- UrlPath.cs
- XmlSerializerImportOptions.cs
- HttpCachePolicyElement.cs
- Soap.cs
- SessionState.cs
- PeerNearMe.cs
- TextElementEnumerator.cs
- SqlTypesSchemaImporter.cs
- CharacterBufferReference.cs
- WindowInteractionStateTracker.cs
- BitVec.cs
- DbProviderFactory.cs
- Marshal.cs
- _AutoWebProxyScriptWrapper.cs
- StyleCollection.cs
- WebPartTransformer.cs
- WmlValidatorAdapter.cs
- DataKeyCollection.cs
- OutgoingWebRequestContext.cs
- ClientCultureInfo.cs
- ZipPackagePart.cs
- AuthenticationModuleElement.cs
- BatchStream.cs
- Win32.cs
- ContainerVisual.cs
- StrongTypingException.cs
- SafeEventLogReadHandle.cs
- StringResourceManager.cs
- altserialization.cs
- QilUnary.cs
- DataSourceUtil.cs
- ToolStripLocationCancelEventArgs.cs
- HttpCookie.cs
- ChildTable.cs
- ArrayList.cs
- DataGridViewCellStateChangedEventArgs.cs
- SimpleType.cs
- CodeDomDesignerLoader.cs
- DataGridViewAutoSizeColumnModeEventArgs.cs
- WebBrowserEvent.cs
- ReflectEventDescriptor.cs
- XmlSchemaSimpleTypeRestriction.cs
- DataRowView.cs
- FileLevelControlBuilderAttribute.cs
- InteropAutomationProvider.cs
- OracleFactory.cs
- ColumnMap.cs
- DragCompletedEventArgs.cs
- SystemResourceKey.cs
- DATA_BLOB.cs
- DataGridViewComponentPropertyGridSite.cs
- HScrollProperties.cs
- SelectedDatesCollection.cs
- TextViewSelectionProcessor.cs
- WindowsEditBoxRange.cs
- XamlSerializationHelper.cs
- ListMarkerSourceInfo.cs
- AttributeInfo.cs
- WebControlParameterProxy.cs
- DesignerActionVerbList.cs
- ToolStripContainerActionList.cs
- RowBinding.cs
- ServerType.cs
- ThemeInfoAttribute.cs
- adornercollection.cs
- TextRunCache.cs
- AuthenticationService.cs
- AjaxFrameworkAssemblyAttribute.cs
- CellLabel.cs
- PreProcessInputEventArgs.cs
- StringComparer.cs
- SourceFileBuildProvider.cs
- XmlSerializerFactory.cs
- BaseValidator.cs
- SchemaCollectionPreprocessor.cs
- __TransparentProxy.cs