Check.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto
  5. {
  6. internal class Check
  7. {
  8. internal static void DataLength(bool condition, string msg)
  9. {
  10. if (condition)
  11. throw new DataLengthException(msg);
  12. }
  13. internal static void DataLength(byte[] buf, int off, int len, string msg)
  14. {
  15. if (off > (buf.Length - len))
  16. throw new DataLengthException(msg);
  17. }
  18. internal static void OutputLength(byte[] buf, int off, int len, string msg)
  19. {
  20. if (off > (buf.Length - len))
  21. throw new OutputLengthException(msg);
  22. }
  23. #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
  24. internal static void DataLength(ReadOnlySpan<byte> input, int len, string msg)
  25. {
  26. if (input.Length < len)
  27. throw new DataLengthException(msg);
  28. }
  29. internal static void OutputLength(Span<byte> output, int len, string msg)
  30. {
  31. if (output.Length < len)
  32. throw new OutputLengthException(msg);
  33. }
  34. #endif
  35. }
  36. }
  37. #pragma warning restore
  38. #endif