X509DefaultEntryConverter.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. using System;
  3. using System.IO;
  4. namespace Org.BouncyCastle.Asn1.X509
  5. {
  6. /**
  7. * The default converter for X509 DN entries when going from their
  8. * string value to ASN.1 strings.
  9. */
  10. public class X509DefaultEntryConverter
  11. : X509NameEntryConverter
  12. {
  13. /**
  14. * Apply default conversion for the given value depending on the oid
  15. * and the character range of the value.
  16. *
  17. * @param oid the object identifier for the DN entry
  18. * @param value the value associated with it
  19. * @return the ASN.1 equivalent for the string value.
  20. */
  21. public override Asn1Object GetConvertedValue(
  22. DerObjectIdentifier oid,
  23. string value)
  24. {
  25. if (value.Length != 0 && value[0] == '#')
  26. {
  27. try
  28. {
  29. return ConvertHexEncoded(value, 1);
  30. }
  31. catch (IOException)
  32. {
  33. throw new Exception("can't recode value for oid " + oid.Id);
  34. }
  35. }
  36. if (value.Length != 0 && value[0] == '\\')
  37. {
  38. value = value.Substring(1);
  39. }
  40. if (oid.Equals(X509Name.EmailAddress) || oid.Equals(X509Name.DC))
  41. {
  42. return new DerIA5String(value);
  43. }
  44. if (oid.Equals(X509Name.DateOfBirth)) // accept time string as well as # (for compatibility)
  45. {
  46. return new DerGeneralizedTime(value);
  47. }
  48. if (oid.Equals(X509Name.C)
  49. || oid.Equals(X509Name.SerialNumber)
  50. || oid.Equals(X509Name.DnQualifier)
  51. || oid.Equals(X509Name.TelephoneNumber))
  52. {
  53. return new DerPrintableString(value);
  54. }
  55. return new DerUtf8String(value);
  56. }
  57. }
  58. }
  59. #endif