X509DefaultEntryConverter.cs 1.7 KB

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