CAST5CBCParameters.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Misc
  7. {
  8. public class Cast5CbcParameters
  9. : Asn1Encodable
  10. {
  11. private readonly DerInteger keyLength;
  12. private readonly Asn1OctetString iv;
  13. public static Cast5CbcParameters GetInstance(
  14. object o)
  15. {
  16. if (o is Cast5CbcParameters)
  17. {
  18. return (Cast5CbcParameters) o;
  19. }
  20. if (o is Asn1Sequence)
  21. {
  22. return new Cast5CbcParameters((Asn1Sequence) o);
  23. }
  24. throw new ArgumentException("unknown object in Cast5CbcParameters factory");
  25. }
  26. public Cast5CbcParameters(
  27. byte[] iv,
  28. int keyLength)
  29. {
  30. this.iv = new DerOctetString(iv);
  31. this.keyLength = new DerInteger(keyLength);
  32. }
  33. private Cast5CbcParameters(
  34. Asn1Sequence seq)
  35. {
  36. if (seq.Count != 2)
  37. throw new ArgumentException("Wrong number of elements in sequence", "seq");
  38. iv = (Asn1OctetString) seq[0];
  39. keyLength = (DerInteger) seq[1];
  40. }
  41. public byte[] GetIV()
  42. {
  43. return Arrays.Clone(iv.GetOctets());
  44. }
  45. public int KeyLength
  46. {
  47. get { return keyLength.IntValueExact; }
  48. }
  49. /**
  50. * Produce an object suitable for an Asn1OutputStream.
  51. * <pre>
  52. * cast5CBCParameters ::= Sequence {
  53. * iv OCTET STRING DEFAULT 0,
  54. * -- Initialization vector
  55. * keyLength Integer
  56. * -- Key length, in bits
  57. * }
  58. * </pre>
  59. */
  60. public override Asn1Object ToAsn1Object()
  61. {
  62. return new DerSequence(iv, keyLength);
  63. }
  64. }
  65. }
  66. #pragma warning restore
  67. #endif