PublicKeyAndChallenge.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Mozilla
  7. {
  8. /**
  9. * This is designed to parse
  10. * the PublicKeyAndChallenge created by the KEYGEN tag included by
  11. * Mozilla based browsers.
  12. * <pre>
  13. * PublicKeyAndChallenge ::= SEQUENCE {
  14. * spki SubjectPublicKeyInfo,
  15. * challenge IA5STRING
  16. * }
  17. *
  18. * </pre>
  19. */
  20. public class PublicKeyAndChallenge
  21. : Asn1Encodable
  22. {
  23. private Asn1Sequence pkacSeq;
  24. private SubjectPublicKeyInfo spki;
  25. private DerIA5String challenge;
  26. public static PublicKeyAndChallenge GetInstance(
  27. object obj)
  28. {
  29. if (obj is PublicKeyAndChallenge)
  30. {
  31. return (PublicKeyAndChallenge) obj;
  32. }
  33. if (obj is Asn1Sequence)
  34. {
  35. return new PublicKeyAndChallenge((Asn1Sequence) obj);
  36. }
  37. throw new ArgumentException(
  38. "unknown object in 'PublicKeyAndChallenge' factory : "
  39. + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj) + ".");
  40. }
  41. public PublicKeyAndChallenge(
  42. Asn1Sequence seq)
  43. {
  44. pkacSeq = seq;
  45. spki = SubjectPublicKeyInfo.GetInstance(seq[0]);
  46. challenge = DerIA5String.GetInstance(seq[1]);
  47. }
  48. public override Asn1Object ToAsn1Object()
  49. {
  50. return pkacSeq;
  51. }
  52. public SubjectPublicKeyInfo SubjectPublicKeyInfo
  53. {
  54. get { return spki; }
  55. }
  56. public DerIA5String Challenge
  57. {
  58. get { return challenge; }
  59. }
  60. }
  61. }
  62. #pragma warning restore
  63. #endif