CngProvider.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //
  2. // System.Security.Cryptography.CngProvider
  3. //
  4. // Authors:
  5. // Sebastien Pouliot <[email protected]>
  6. //
  7. // Copyright (C) 2008 Novell, Inc (http://www.novell.com)
  8. // Copyright (C) 2011 Juho Vähä-Herttua
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System;
  30. namespace System.Security.Cryptography {
  31. // note: CNG stands for "Cryptography API: Next Generation"
  32. [Serializable]
  33. public sealed class CngProvider : IEquatable<CngProvider> {
  34. private string m_Provider;
  35. public CngProvider (string provider)
  36. {
  37. if (provider == null)
  38. throw new ArgumentNullException ("provider");
  39. if (provider.Length == 0)
  40. throw new ArgumentException ("provider");
  41. m_Provider = provider;
  42. }
  43. public string Provider {
  44. get { return m_Provider; }
  45. }
  46. public bool Equals (CngProvider other)
  47. {
  48. if (other == null)
  49. return false;
  50. return m_Provider == other.m_Provider;
  51. }
  52. public override bool Equals (object obj)
  53. {
  54. return Equals (obj as CngProvider);
  55. }
  56. public override int GetHashCode ()
  57. {
  58. return m_Provider.GetHashCode ();
  59. }
  60. public override string ToString ()
  61. {
  62. return m_Provider;
  63. }
  64. // static
  65. private static CngProvider microsoftSmartCardKeyStorageProvider;
  66. private static CngProvider microsoftSoftwareKeyStorageProvider;
  67. public static CngProvider MicrosoftSmartCardKeyStorageProvider {
  68. get {
  69. if (microsoftSmartCardKeyStorageProvider == null)
  70. microsoftSmartCardKeyStorageProvider = new CngProvider ("Microsoft Smart Card Key Storage Provider");
  71. return microsoftSmartCardKeyStorageProvider;
  72. }
  73. }
  74. public static CngProvider MicrosoftSoftwareKeyStorageProvider {
  75. get {
  76. if (microsoftSoftwareKeyStorageProvider == null)
  77. microsoftSoftwareKeyStorageProvider = new CngProvider ("Microsoft Software Key Storage Provider");
  78. return microsoftSoftwareKeyStorageProvider;
  79. }
  80. }
  81. public static bool operator == (CngProvider left, CngProvider right)
  82. {
  83. if ((object)left == null)
  84. return ((object)right == null);
  85. return left.Equals (right);
  86. }
  87. public static bool operator != (CngProvider left, CngProvider right)
  88. {
  89. if ((object)left == null)
  90. return ((object)right != null);
  91. return !left.Equals (right);
  92. }
  93. }
  94. }