Oid.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // Oid.cs - System.Security.Cryptography.Oid
  3. //
  4. // Author:
  5. // Sebastien Pouliot ([email protected])
  6. //
  7. // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
  8. //
  9. #if NET_1_2
  10. using System;
  11. namespace System.Security.Cryptography {
  12. // Note: Match the definition of framework version 1.2.3400.0 on http://longhorn.msdn.microsoft.com
  13. public sealed class Oid {
  14. private string _value;
  15. private string _name;
  16. // constructors
  17. public Oid () {}
  18. public Oid (string oid)
  19. {
  20. if (oid == null)
  21. throw new ArgumentNullException ("oid");
  22. _value = oid;
  23. _name = GetName (oid);
  24. }
  25. public Oid (string value, string friendlyName)
  26. {
  27. _value = value;
  28. _name = friendlyName;
  29. }
  30. public Oid (Oid oid)
  31. {
  32. // FIXME: compatibility with fx 1.2.3400.0
  33. // if (oid == null)
  34. // throw new ArgumentNullException ("oid");
  35. _value = oid.Value;
  36. _name = oid.FriendlyName;
  37. }
  38. // properties
  39. public string FriendlyName {
  40. get { return _name; }
  41. set {
  42. if (value == null)
  43. throw new ArgumentNullException ("value");
  44. _name = value;
  45. _value = GetValue (_name);
  46. }
  47. }
  48. public string Value {
  49. get { return _value; }
  50. set {
  51. if (value == null)
  52. throw new ArgumentNullException ("value");
  53. _value = value;
  54. _name = GetName (_value);
  55. }
  56. }
  57. // private methods
  58. // TODO - find the complete list
  59. private string GetName (string value)
  60. {
  61. switch (value) {
  62. case "1.2.840.113549.1.1.1":
  63. return "RSA";
  64. default:
  65. return _name;
  66. }
  67. }
  68. // TODO - find the complete list
  69. private string GetValue (string name)
  70. {
  71. switch (name) {
  72. case "RSA":
  73. return "1.2.840.113549.1.1.1";
  74. default:
  75. return _value;
  76. }
  77. }
  78. }
  79. }
  80. #endif