2 // System.Web.Configuration.MachineKeyValidationConverter
5 // Chris Toshok (toshok@ximian.com)
6 // Sebastien Pouliot <sebastien@ximian.com>
8 // Copyright (C) 2005, 2010 Novell, Inc (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.ComponentModel;
33 using System.Configuration;
34 using System.Globalization;
37 namespace System.Web.Configuration {
39 public sealed class MachineKeyValidationConverter : ConfigurationConverterBase
41 const string InvalidValue = "The enumeration value must be one of the following: SHA1, MD5, 3DES, AES, HMACSHA256, HMACSHA384, HMACSHA512.";
42 public MachineKeyValidationConverter ()
46 public override object ConvertFrom (ITypeDescriptorContext ctx, CultureInfo ci, object data)
48 switch ((string) data) {
50 return MachineKeyValidation.MD5;
52 return MachineKeyValidation.SHA1;
54 return MachineKeyValidation.TripleDES;
56 return MachineKeyValidation.AES;
58 return MachineKeyValidation.HMACSHA256;
60 return MachineKeyValidation.HMACSHA384;
62 return MachineKeyValidation.HMACSHA512;
64 throw new ArgumentException (InvalidValue);
68 public override object ConvertTo (ITypeDescriptorContext ctx, CultureInfo ci, object value, Type type)
70 if ((value == null) || (value.GetType () != typeof (MachineKeyValidation)))
71 throw new ArgumentException (InvalidValue);
73 switch ((MachineKeyValidation) value) {
74 case MachineKeyValidation.MD5:
76 case MachineKeyValidation.SHA1:
78 case MachineKeyValidation.TripleDES:
80 case MachineKeyValidation.AES:
82 case MachineKeyValidation.HMACSHA256:
84 case MachineKeyValidation.HMACSHA384:
86 case MachineKeyValidation.HMACSHA512:
89 // includes MachineKeyValidation.Custom
90 throw new ArgumentException (InvalidValue);