123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
- using System;
- using System.Globalization;
- using System.IO;
- using System.Text;
- #if SILVERLIGHT || NETFX_CORE || UNITY_WP8 || PORTABLE
- using System.Collections.Generic;
- #else
- using System.Collections;
- #endif
- namespace Org.BouncyCastle.Utilities
- {
- internal abstract class Platform
- {
- private static readonly CompareInfo InvariantCompareInfo = CultureInfo.InvariantCulture.CompareInfo;
- #if NETCF_1_0 || NETCF_2_0
- private static string GetNewLine()
- {
- MemoryStream buf = new MemoryStream();
- StreamWriter w = new StreamWriter(buf, Encoding.UTF8);
- w.WriteLine();
- Dispose(w);
- byte[] bs = buf.ToArray();
- return Encoding.UTF8.GetString(bs, 0, bs.Length);
- }
- #else
- private static string GetNewLine()
- {
- return Environment.NewLine;
- }
- #endif
- internal static bool EqualsIgnoreCase(string a, string b)
- {
- return String.Compare(a, b, StringComparison.OrdinalIgnoreCase) == 0;
- }
- #if NETCF_1_0 || NETCF_2_0 || SILVERLIGHT || NETFX_CORE || PORTABLE
- internal static string GetEnvironmentVariable(
- string variable)
- {
- return null;
- }
- #else
- internal static string GetEnvironmentVariable(
- string variable)
- {
- try
- {
- return Environment.GetEnvironmentVariable(variable);
- }
- catch (System.Security.SecurityException)
- {
- // We don't have the required permission to read this environment variable,
- // which is fine, just act as if it's not set
- return null;
- }
- }
- #endif
- #if NETCF_1_0
- internal static Exception CreateNotImplementedException(
- string message)
- {
- return new Exception("Not implemented: " + message);
- }
- internal static bool Equals(
- object a,
- object b)
- {
- return a == b || (a != null && b != null && a.Equals(b));
- }
- #else
- internal static Exception CreateNotImplementedException(
- string message)
- {
- return new NotImplementedException(message);
- }
- #endif
- #if SILVERLIGHT || NETFX_CORE || UNITY_WP8 || PORTABLE
- internal static System.Collections.IList CreateArrayList()
- {
- return new List<object>();
- }
- internal static System.Collections.IList CreateArrayList(int capacity)
- {
- return new List<object>(capacity);
- }
- internal static System.Collections.IList CreateArrayList(System.Collections.ICollection collection)
- {
- System.Collections.IList result = new List<object>(collection.Count);
- foreach (object o in collection)
- {
- result.Add(o);
- }
- return result;
- }
- internal static System.Collections.IList CreateArrayList(System.Collections.IEnumerable collection)
- {
- System.Collections.IList result = new List<object>();
- foreach (object o in collection)
- {
- result.Add(o);
- }
- return result;
- }
- internal static System.Collections.IDictionary CreateHashtable()
- {
- return new Dictionary<object, object>();
- }
- internal static System.Collections.IDictionary CreateHashtable(int capacity)
- {
- return new Dictionary<object, object>(capacity);
- }
- internal static System.Collections.IDictionary CreateHashtable(System.Collections.IDictionary dictionary)
- {
- System.Collections.IDictionary result = new Dictionary<object, object>(dictionary.Count);
- foreach (System.Collections.DictionaryEntry entry in dictionary)
- {
- result.Add(entry.Key, entry.Value);
- }
- return result;
- }
- #else
- internal static System.Collections.IList CreateArrayList()
- {
- return new ArrayList();
- }
- internal static System.Collections.IList CreateArrayList(int capacity)
- {
- return new ArrayList(capacity);
- }
- internal static System.Collections.IList CreateArrayList(System.Collections.ICollection collection)
- {
- return new ArrayList(collection);
- }
- internal static System.Collections.IList CreateArrayList(System.Collections.IEnumerable collection)
- {
- ArrayList result = new ArrayList();
- foreach (object o in collection)
- {
- result.Add(o);
- }
- return result;
- }
- internal static System.Collections.IDictionary CreateHashtable()
- {
- return new Hashtable();
- }
- internal static System.Collections.IDictionary CreateHashtable(int capacity)
- {
- return new Hashtable(capacity);
- }
- internal static System.Collections.IDictionary CreateHashtable(System.Collections.IDictionary dictionary)
- {
- return new Hashtable(dictionary);
- }
- #endif
- internal static string ToLowerInvariant(string s)
- {
- #if NETFX_CORE || PORTABLE
- return s.ToLower();
- #else
- return s.ToLower(CultureInfo.InvariantCulture);
- #endif
- }
- internal static string ToUpperInvariant(string s)
- {
- #if NETFX_CORE || PORTABLE
- return s.ToUpper();
- #else
- return s.ToUpper(CultureInfo.InvariantCulture);
- #endif
- }
- internal static readonly string NewLine = GetNewLine();
- #if PORTABLE || NETFX_CORE
- internal static void Dispose(IDisposable d)
- {
- d.Dispose();
- }
- #else
- internal static void Dispose(Stream s)
- {
- s.Close();
- }
- internal static void Dispose(TextWriter t)
- {
- t.Close();
- }
- #endif
- internal static int IndexOf(string source, string value)
- {
- return InvariantCompareInfo.IndexOf(source, value, CompareOptions.Ordinal);
- }
- internal static int LastIndexOf(string source, string value)
- {
- return InvariantCompareInfo.LastIndexOf(source, value, CompareOptions.Ordinal);
- }
- internal static bool StartsWith(string source, string prefix)
- {
- return InvariantCompareInfo.IsPrefix(source, prefix, CompareOptions.Ordinal);
- }
- internal static bool EndsWith(string source, string suffix)
- {
- return InvariantCompareInfo.IsSuffix(source, suffix, CompareOptions.Ordinal);
- }
- internal static string GetTypeName(object obj)
- {
- return obj.GetType().FullName;
- }
- }
- }
- #endif
|