CryptoStream.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //
  2. // System.Security.Cryptography CryptoStream.cs
  3. //
  4. // Author:
  5. // Thomas Neidhart ([email protected])
  6. //
  7. using System;
  8. using System.IO;
  9. namespace System.Security.Cryptography
  10. {
  11. public class CryptoStream : Stream
  12. {
  13. private CryptoStreamMode _mode;
  14. public CryptoStream(Stream stream, ICryptoTransform transform, CryptoStreamMode mode)
  15. {
  16. _mode = mode;
  17. }
  18. public override bool CanRead
  19. {
  20. get {
  21. switch (_mode) {
  22. case CryptoStreamMode.Read:
  23. return true;
  24. case CryptoStreamMode.Write:
  25. return false;
  26. default:
  27. return false;
  28. }
  29. }
  30. }
  31. public override bool CanSeek
  32. {
  33. get {
  34. return false;
  35. }
  36. }
  37. public override bool CanWrite
  38. {
  39. get {
  40. switch (_mode) {
  41. case CryptoStreamMode.Read:
  42. return false;
  43. case CryptoStreamMode.Write:
  44. return true;
  45. default:
  46. return false;
  47. }
  48. }
  49. }
  50. public override long Length
  51. {
  52. get {
  53. throw new NotSupportedException("Length property not supported by CryptoStream");
  54. }
  55. }
  56. public override long Position
  57. {
  58. get {
  59. throw new NotSupportedException("Position property not supported by CryptoStream");
  60. }
  61. set {
  62. throw new NotSupportedException("Position property not supported by CryptoStream");
  63. }
  64. }
  65. public override int Read(byte[] buffer, int offset, int count)
  66. {
  67. // TODO: implement
  68. return 0;
  69. }
  70. public override void Write(byte[] buffer, int offset, int count)
  71. {
  72. // TODO: implement
  73. }
  74. public override void Flush()
  75. {
  76. // TODO: implement
  77. }
  78. public void FlushFinalBlock()
  79. {
  80. if (_mode != CryptoStreamMode.Write)
  81. throw new NotSupportedException("cannot flush a non-writeable CryptoStream");
  82. // TODO: implement
  83. }
  84. public override long Seek(long offset, SeekOrigin origin)
  85. {
  86. throw new NotSupportedException("cannot seek a CryptoStream");
  87. }
  88. public override void SetLength(long value)
  89. {
  90. // LAMESPEC: should throw NotSupportedException like Seek??
  91. return;
  92. }
  93. } // CryptoStream
  94. } // System.Security.Cryptography