1 /* Transport Security Layer (TLS)
2 * Copyright (c) 2003 Carlos Guzmán Álvarez
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
26 using System.Collections;
27 using System.Globalization;
28 using System.Security.Cryptography;
30 namespace Mono.Security.Protocol.Tls
32 internal sealed class TlsCipherSuiteCollection : ArrayList
36 private TlsProtocol protocol;
42 public CipherSuite this[string name]
44 get { return (CipherSuite)this[IndexOf(name)]; }
45 set { this[IndexOf(name)] = (CipherSuite)value; }
48 public CipherSuite this[short code]
50 get { return (CipherSuite)base[IndexOf(code)]; }
51 set { base[IndexOf(code)] = (CipherSuite)value; }
54 public new CipherSuite this[int code]
56 get { return (CipherSuite)base[code]; }
57 set { base[code] = (CipherSuite)value; }
64 public TlsCipherSuiteCollection(TlsProtocol protocol) : base()
66 this.protocol = protocol;
73 public bool Contains(string name)
75 return(-1 != IndexOf(name));
78 public int IndexOf(string name)
81 foreach (CipherSuite suite in this)
83 if (cultureAwareCompare(suite.Name, name))
92 public int IndexOf(short code)
95 foreach (CipherSuite suite in this)
97 if (suite.Code == code)
106 public void RemoveAt(string errorMessage)
108 RemoveAt(IndexOf(errorMessage));
111 public CipherSuite Add(short code, string name, string algName, string hashName, bool exportable, bool blockMode, byte keyMaterialSize, byte expandedKeyMaterialSize, short effectiveKeyBytes, byte ivSize, byte blockSize)
113 switch (this.protocol)
115 case TlsProtocol.Tls1:
117 new TlsCipherSuite(code, name, algName, hashName, exportable, blockMode, keyMaterialSize, expandedKeyMaterialSize, effectiveKeyBytes, ivSize, blockSize));
119 case TlsProtocol.Ssl3:
121 new TlsSslCipherSuite(code, name, algName, hashName, exportable, blockMode, keyMaterialSize, expandedKeyMaterialSize, effectiveKeyBytes, ivSize, blockSize));
124 throw new NotSupportedException();
128 private TlsCipherSuite add(TlsCipherSuite cipherSuite)
130 base.Add(cipherSuite);
135 private TlsSslCipherSuite add(TlsSslCipherSuite cipherSuite)
137 base.Add(cipherSuite);
142 private bool cultureAwareCompare(string strA, string strB)
146 return CultureInfo.CurrentCulture.CompareInfo.Compare(strA, strB, CompareOptions.IgnoreKanaType | CompareOptions.IgnoreWidth | CompareOptions.IgnoreCase) == 0 ? true : false;
148 catch (NotSupportedException)
150 return strA.ToUpper() == strB.ToUpper() ? true : false;