GOST28147Parameters.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Collections;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.CryptoPro
  7. {
  8. public class Gost28147Parameters
  9. : Asn1Encodable
  10. {
  11. private readonly Asn1OctetString iv;
  12. private readonly DerObjectIdentifier paramSet;
  13. public static Gost28147Parameters GetInstance(
  14. Asn1TaggedObject obj,
  15. bool explicitly)
  16. {
  17. return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
  18. }
  19. public static Gost28147Parameters GetInstance(
  20. object obj)
  21. {
  22. if (obj == null || obj is Gost28147Parameters)
  23. {
  24. return (Gost28147Parameters) obj;
  25. }
  26. if (obj is Asn1Sequence)
  27. {
  28. return new Gost28147Parameters((Asn1Sequence) obj);
  29. }
  30. throw new ArgumentException("Invalid GOST3410Parameter: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj));
  31. }
  32. private Gost28147Parameters(
  33. Asn1Sequence seq)
  34. {
  35. if (seq.Count != 2)
  36. throw new ArgumentException("Wrong number of elements in sequence", "seq");
  37. this.iv = Asn1OctetString.GetInstance(seq[0]);
  38. this.paramSet = DerObjectIdentifier.GetInstance(seq[1]);
  39. }
  40. /**
  41. * <pre>
  42. * Gost28147-89-Parameters ::=
  43. * SEQUENCE {
  44. * iv Gost28147-89-IV,
  45. * encryptionParamSet OBJECT IDENTIFIER
  46. * }
  47. *
  48. * Gost28147-89-IV ::= OCTET STRING (SIZE (8))
  49. * </pre>
  50. */
  51. public override Asn1Object ToAsn1Object()
  52. {
  53. return new DerSequence(iv, paramSet);
  54. }
  55. }
  56. }
  57. #pragma warning restore
  58. #endif