TlsNullNullCipher.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto
  5. {
  6. /// <summary>The cipher for TLS_NULL_WITH_NULL_NULL.</summary>
  7. public sealed class TlsNullNullCipher
  8. : TlsCipher
  9. {
  10. public static readonly TlsNullNullCipher Instance = new TlsNullNullCipher();
  11. public int GetCiphertextDecodeLimit(int plaintextLimit)
  12. {
  13. return plaintextLimit;
  14. }
  15. public int GetCiphertextEncodeLimit(int plaintextLength, int plaintextLimit)
  16. {
  17. return plaintextLength;
  18. }
  19. public int GetPlaintextLimit(int ciphertextLimit)
  20. {
  21. return ciphertextLimit;
  22. }
  23. public TlsEncodeResult EncodePlaintext(long seqNo, short contentType, ProtocolVersion recordVersion,
  24. int headerAllocation, byte[] plaintext, int offset, int len)
  25. {
  26. byte[] result = new byte[headerAllocation + len];
  27. Array.Copy(plaintext, offset, result, headerAllocation, len);
  28. return new TlsEncodeResult(result, 0, result.Length, contentType);
  29. }
  30. #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
  31. public TlsEncodeResult EncodePlaintext(long seqNo, short contentType, ProtocolVersion recordVersion,
  32. int headerAllocation, ReadOnlySpan<byte> plaintext)
  33. {
  34. byte[] result = new byte[headerAllocation + plaintext.Length];
  35. plaintext.CopyTo(result.AsSpan(headerAllocation));
  36. return new TlsEncodeResult(result, 0, result.Length, contentType);
  37. }
  38. #endif
  39. public TlsDecodeResult DecodeCiphertext(long seqNo, short recordType, ProtocolVersion recordVersion,
  40. byte[] ciphertext, int offset, int len)
  41. {
  42. return new TlsDecodeResult(ciphertext, offset, len, recordType);
  43. }
  44. public void RekeyDecoder()
  45. {
  46. throw new TlsFatalAlert(AlertDescription.internal_error);
  47. }
  48. public void RekeyEncoder()
  49. {
  50. throw new TlsFatalAlert(AlertDescription.internal_error);
  51. }
  52. public bool UsesOpaqueRecordType
  53. {
  54. get { return false; }
  55. }
  56. }
  57. }
  58. #pragma warning restore
  59. #endif