TlsCipher.cs 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.IO;
  5. namespace Best.HTTP.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. #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
  39. TlsEncodeResult EncodePlaintext(long seqNo, short contentType, ProtocolVersion recordVersion,
  40. int headerAllocation, ReadOnlySpan<byte> plaintext);
  41. #endif
  42. /// <summary>Decode the passed in ciphertext using the current bulk cipher.</summary>
  43. /// <param name="seqNo">sequence number of the message represented by ciphertext.</param>
  44. /// <param name="recordType">content type used in the record for this message.</param>
  45. /// <param name="recordVersion"><see cref="ProtocolVersion"/> used for the record.</param>
  46. /// <param name="ciphertext">array holding input ciphertext to the cipher.</param>
  47. /// <param name="offset">offset into input array the ciphertext starts at.</param>
  48. /// <param name="len">length of the ciphertext in the array.</param>
  49. /// <returns>A <see cref="TlsDecodeResult"/> containing the result of decoding.</returns>
  50. /// <exception cref="IOException"/>
  51. TlsDecodeResult DecodeCiphertext(long seqNo, short recordType, ProtocolVersion recordVersion,
  52. byte[] ciphertext, int offset, int len);
  53. /// <exception cref="IOException"/>
  54. void RekeyDecoder();
  55. /// <exception cref="IOException"/>
  56. void RekeyEncoder();
  57. bool UsesOpaqueRecordType { get; }
  58. }
  59. }
  60. #pragma warning restore
  61. #endif