SimpleBlockResult.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto
  5. {
  6. /// <summary>
  7. /// A simple block result object which just carries a byte array.
  8. /// </summary>
  9. public class SimpleBlockResult
  10. : IBlockResult
  11. {
  12. private readonly byte[] result;
  13. /// <summary>
  14. /// Base constructor - a wrapper for the passed in byte array.
  15. /// </summary>
  16. /// <param name="result">The byte array to be wrapped.</param>
  17. public SimpleBlockResult(byte[] result)
  18. {
  19. this.result = result;
  20. }
  21. /// <summary>
  22. /// Return the number of bytes in the result
  23. /// </summary>
  24. /// <value>The length of the result in bytes.</value>
  25. public int Length
  26. {
  27. get { return result.Length; }
  28. }
  29. /// <summary>
  30. /// Return the final result of the operation.
  31. /// </summary>
  32. /// <returns>A block of bytes, representing the result of an operation.</returns>
  33. public byte[] Collect()
  34. {
  35. return result;
  36. }
  37. /// <summary>
  38. /// Store the final result of the operation by copying it into the destination array.
  39. /// </summary>
  40. /// <returns>The number of bytes copied into destination.</returns>
  41. /// <param name="destination">The byte array to copy the result into.</param>
  42. /// <param name="offset">The offset into destination to start copying the result at.</param>
  43. public int Collect(byte[] destination, int offset)
  44. {
  45. Array.Copy(result, 0, destination, offset, result.Length);
  46. return result.Length;
  47. }
  48. }
  49. }
  50. #pragma warning restore
  51. #endif