Skip to content

Commit 435d1a9

Browse files
committed
Fix unused parameter, Block async methods.
1 parent f891be6 commit 435d1a9

2 files changed

Lines changed: 85 additions & 6 deletions

File tree

CryptoMemoryStream/IO/CryptoMemoryStream.cs

Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Threading.Tasks;
66
using System.IO;
77
using System.Security.Cryptography;
8+
using System.Threading;
89

910
namespace CryptoMemoryStream.IO
1011
{
@@ -79,7 +80,7 @@ public override void Write(byte[] buffer, int offset, int count)
7980
{
8081
byte[] encryptBytes = (byte[])buffer.Clone();
8182

82-
CTRCryptor(encryptBytes, offset, count);
83+
CTRCryptor(encryptBytes, count);
8384
base.Write(encryptBytes, offset, count);
8485
}
8586

@@ -120,7 +121,7 @@ public void Encrypt(byte[] buffer, int offset, int count)
120121
public int Decrypt(byte[] buffer, int offset, int count)
121122
{
122123
int readedSize = Read(buffer, offset, count);
123-
CTRCryptor(buffer, offset, readedSize);
124+
CTRCryptor(buffer, readedSize);
124125

125126
return readedSize;
126127
}
@@ -136,7 +137,9 @@ public override void Close()
136137
base.Close();
137138
}
138139

139-
private void CTRCryptor(byte[] buffer, int offset, int count)
140+
141+
142+
private void CTRCryptor(byte[] buffer, int count)
140143
{
141144
Queue<byte> xorMask = new Queue<byte>();
142145
int blockSize = aesManaged.BlockSize / 8;
@@ -162,5 +165,81 @@ private void CTRCryptor(byte[] buffer, int offset, int count)
162165
buffer[i] = (byte)(buffer[i] ^ xorMask.Dequeue());
163166
}
164167
}
168+
169+
protected override void Dispose(bool disposing)
170+
{
171+
base.Dispose(disposing);
172+
aesManaged.Dispose();
173+
cryptor.Dispose();
174+
}
175+
176+
public override void WriteByte(byte value)
177+
{
178+
Write(new byte[] { value }, 0, 1);
179+
}
180+
181+
/// <summary>
182+
/// MemoryStream.BeginRead 메소드를 재정의하여 아무것도 하지 않도록 합니다.
183+
/// </summary>
184+
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
185+
{
186+
throw new InvalidOperationException("사용이 불가능한 메소드입니다.");
187+
}
188+
189+
/// <summary>
190+
/// MemoryStream.EndRead 메소드를 재정의하여 아무것도 하지 않도록 합니다.
191+
/// </summary>
192+
public override int EndRead(IAsyncResult asyncResult)
193+
{
194+
throw new InvalidOperationException("사용이 불가능한 메소드입니다.");
195+
}
196+
197+
/// <summary>
198+
/// MemoryStream.BeginWrite 메소드를 재정의하여 아무것도 하지 않도록 합니다.
199+
/// </summary>
200+
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
201+
{
202+
throw new InvalidOperationException("사용이 불가능한 메소드입니다.");
203+
}
204+
205+
/// <summary>
206+
/// MemoryStream.EndWrite 메소드를 재정의하여 아무것도 하지 않도록 합니다.
207+
/// </summary>
208+
public override void EndWrite(IAsyncResult asyncResult)
209+
{
210+
throw new InvalidOperationException("사용이 불가능한 메소드입니다.");
211+
}
212+
213+
/// <summary>
214+
/// MemoryStream.FlushAsync 메소드를 재정의하여 아무것도 하지 않도록 합니다.
215+
/// </summary>
216+
public override Task FlushAsync(CancellationToken cancellationToken)
217+
{
218+
throw new InvalidOperationException("사용이 불가능한 메소드입니다.");
219+
}
220+
221+
/// <summary>
222+
/// MemoryStream.ReadAsync 메소드를 재정의하여 아무것도 하지 않도록 합니다.
223+
/// </summary>
224+
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
225+
{
226+
throw new InvalidOperationException("사용이 불가능한 메소드입니다.");
227+
}
228+
229+
/// <summary>
230+
/// MemoryStream.CopyToAsync 메소드를 재정의하여 아무것도 하지 않도록 합니다.
231+
/// </summary>
232+
public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
233+
{
234+
throw new InvalidOperationException("사용이 불가능한 메소드입니다.");
235+
}
236+
237+
/// <summary>
238+
/// MemoryStream.WriteAsync 메소드를 재정의하여 아무것도 하지 않도록 합니다.
239+
/// </summary>
240+
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
241+
{
242+
throw new InvalidOperationException("사용이 불가능한 메소드입니다.");
243+
}
165244
}
166245
}

CryptoMemoryStreamTests/IO/CryptoMemoryStreamTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ public class CryptoMemoryStreamTests
1717
[TestMethod()]
1818
public void WriteTest()
1919
{
20-
CryptoMemoryStream memoryStream = new CryptoMemoryStream(1024, plainKey);
20+
CryptoMemoryStream memoryStream = new CryptoMemoryStream(1024, plainKey, plainKey);
2121

2222
memoryStream.Write(data, 0, data.Length);
2323
}
2424

2525
[TestMethod()]
2626
public void ReadTest()
2727
{
28-
CryptoMemoryStream memoryStream = new CryptoMemoryStream(1024, plainKey);
28+
CryptoMemoryStream memoryStream = new CryptoMemoryStream(1024, plainKey, plainKey);
2929
byte[] buffer = new byte[16];
3030

3131
memoryStream.Write(data, 0, data.Length);
@@ -36,7 +36,7 @@ public void ReadTest()
3636
[TestMethod()]
3737
public void DuplexRWTest()
3838
{
39-
CryptoMemoryStream memoryStream = new CryptoMemoryStream(1024, plainKey);
39+
CryptoMemoryStream memoryStream = new CryptoMemoryStream(1024, plainKey, plainKey);
4040
byte[] buffer = new byte[16];
4141

4242
for (int i = 0; i < 2; i++)

0 commit comments

Comments
 (0)