TlsCipher.cs 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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.Tls.Crypto
  6. {
  7. /// <summary>Base interface for a TLS bulk cipher.</summary>
  8. public interface TlsCipher
  9. {
  10. /// <summary>Return the maximum input size for a ciphertext given a maximum output size for the plaintext of
  11. /// plaintextLimit bytes.</summary>
  12. /// <param name="plaintextLimit">the maximum output size for the plaintext.</param>
  13. /// <returns>the maximum input size of the ciphertext for plaintextlimit bytes of output.</returns>
  14. int GetCiphertextDecodeLimit(int plaintextLimit);
  15. /// <summary>Return the maximum output size for a ciphertext given an actual input plaintext size of
  16. /// plaintextLength bytes and a maximum input plaintext size of plaintextLimit bytes.</summary>
  17. /// <param name="plaintextLength">the actual input size for the plaintext.</param>
  18. /// <param name="plaintextLimit">the maximum input size for the plaintext.</param>
  19. /// <returns>the maximum output size of the ciphertext for plaintextlimit bytes of input.</returns>
  20. int GetCiphertextEncodeLimit(int plaintextLength, int plaintextLimit);
  21. /// <summary>Return the maximum size for the plaintext given ciphertextlimit bytes of ciphertext.</summary>
  22. /// <param name="ciphertextLimit">the maximum number of bytes of ciphertext.</param>
  23. /// <returns>the maximum size of the plaintext for ciphertextlimit bytes of input.</returns>
  24. int GetPlaintextLimit(int ciphertextLimit);
  25. /// <summary>Encode the passed in plaintext using the current bulk cipher.</summary>
  26. /// <param name="seqNo">sequence number of the message represented by plaintext.</param>
  27. /// <param name="contentType">content type of the message represented by plaintext.</param>
  28. /// <param name="recordVersion"><see cref="ProtocolVersion"/> used for the record.</param>
  29. /// <param name="headerAllocation">extra bytes to allocate at start of returned byte array.</param>
  30. /// <param name="plaintext">array holding input plaintext to the cipher.</param>
  31. /// <param name="offset">offset into input array the plaintext starts at.</param>
  32. /// <param name="len">length of the plaintext in the array.</param>
  33. /// <returns>A <see cref="TlsEncodeResult"/> containing the result of encoding (after 'headerAllocation' unused
  34. /// bytes).</returns>
  35. /// <exception cref="IOException"/>
  36. TlsEncodeResult EncodePlaintext(long seqNo, short contentType, ProtocolVersion recordVersion,
  37. int headerAllocation, byte[] plaintext, int offset, int len);
  38. /// <summary>Decode the passed in ciphertext using the current bulk cipher.</summary>
  39. /// <param name="seqNo">sequence number of the message represented by ciphertext.</param>
  40. /// <param name="recordType">content type used in the record for this message.</param>
  41. /// <param name="recordVersion"><see cref="ProtocolVersion"/> used for the record.</param>
  42. /// <param name="ciphertext">array holding input ciphertext to the cipher.</param>
  43. /// <param name="offset">offset into input array the ciphertext starts at.</param>
  44. /// <param name="len">length of the ciphertext in the array.</param>
  45. /// <returns>A <see cref="TlsDecodeResult"/> containing the result of decoding.</returns>
  46. /// <exception cref="IOException"/>
  47. TlsDecodeResult DecodeCiphertext(long seqNo, short recordType, ProtocolVersion recordVersion,
  48. byte[] ciphertext, int offset, int len);
  49. /// <exception cref="IOException"/>
  50. void RekeyDecoder();
  51. /// <exception cref="IOException"/>
  52. void RekeyEncoder();
  53. bool UsesOpaqueRecordType { get; }
  54. }
  55. }
  56. #pragma warning restore
  57. #endif