GOST28147Parameters.cs 1.8 KB

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