mirror of
https://github.com/azaion/admin.git
synced 2026-04-22 07:06:34 +00:00
put StreamToString to extensions
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
using System.Text;
|
||||
|
||||
namespace Azaion.Common.Extensions;
|
||||
|
||||
public static class StreamExtensions
|
||||
{
|
||||
public static string ConvertToString(this Stream stream)
|
||||
{
|
||||
stream.Position = 0;
|
||||
using var reader = new StreamReader(stream, Encoding.UTF8);
|
||||
var result = reader.ReadToEnd();
|
||||
stream.Position = 0;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,5 @@
|
||||
using Azaion.Common;
|
||||
using Azaion.Common.Configs;
|
||||
using Azaion.Common.Database;
|
||||
using Azaion.Common.Entities;
|
||||
using LinqToDB;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
@@ -52,5 +52,6 @@ public static class Security
|
||||
int bytesRead;
|
||||
while ((bytesRead = await cryptoStream.ReadAsync(buffer, cancellationToken)) > 0)
|
||||
await toStream.WriteAsync(buffer.AsMemory(0, bytesRead), cancellationToken);
|
||||
toStream.Seek(0, SeekOrigin.Begin);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Azaion.Common.Extensions;
|
||||
using Azaion.Services;
|
||||
using FluentAssertions;
|
||||
using Newtonsoft.Json;
|
||||
@@ -27,7 +28,7 @@ public class SecurityTest
|
||||
await encryptedStream.DecryptTo(decryptedStream, key);
|
||||
encryptedStream.Close();
|
||||
|
||||
var str = StreamToString(decryptedStream);
|
||||
var str = decryptedStream.ConvertToString();
|
||||
str.Should().Be(testString);
|
||||
}
|
||||
|
||||
@@ -91,17 +92,9 @@ public class SecurityTest
|
||||
return stream;
|
||||
}
|
||||
|
||||
private static string StreamToString(Stream stream)
|
||||
{
|
||||
stream.Position = 0;
|
||||
using var reader = new StreamReader(stream, Encoding.UTF8);
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
|
||||
private static Stream StringToStream(string src)
|
||||
{
|
||||
var byteArray = Encoding.UTF8.GetBytes(src);
|
||||
return new MemoryStream(byteArray);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user