Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<ItemGroup>
<ProjectReference Include="..\ref\System.Security.Cryptography.Primitives.csproj">
<ProjectReference Include="..\ref\System.Security.Cryptography.Primitives.builds">
<SupportedFramework>net463;netcoreapp1.1;$(AllXamarinFrameworks)</SupportedFramework>
</ProjectReference>
<ProjectReference Include="..\src\System.Security.Cryptography.Primitives.builds" />
Expand All @@ -16,4 +16,4 @@
<InboxOnTargetFramework Include="xamarinwatchos10" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<ItemGroup>
<Project Include="System.Security.Cryptography.Primitives.csproj" />
<Project Include="System.Security.Cryptography.Primitives.csproj">
<TargetGroup>netcoreapp1.1</TargetGroup>
</Project>
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.traversal.targets))\dir.traversal.targets" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public CryptographicUnexpectedOperationException(string format, string insert) {
public partial class CryptoStream : System.IO.Stream, System.IDisposable
{
public CryptoStream(System.IO.Stream stream, System.Security.Cryptography.ICryptoTransform transform, System.Security.Cryptography.CryptoStreamMode mode) { }
#if netcoreapp11
public CryptoStream(System.IO.Stream stream, System.Security.Cryptography.ICryptoTransform transform, System.Security.Cryptography.CryptoStreamMode mode, bool leaveOpen) { }
#endif
public override bool CanRead { get { throw null; } }
public override bool CanSeek { get { throw null; } }
public override bool CanWrite { get { throw null; } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<OutputType>Library</OutputType>
<NuGetTargetMoniker>.NETStandard,Version=v1.7</NuGetTargetMoniker>
<NuGetTargetMoniker Condition="'$(TargetGroup)'==''">.NETStandard,Version=v1.7</NuGetTargetMoniker>
<DefineConstants Condition="'$(TargetGroup)' == 'netcoreapp1.1'">$(DefineConstants);netcoreapp11</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="System.Security.Cryptography.Primitives.cs" />
Expand All @@ -12,4 +13,4 @@
<None Include="project.json" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>
</Project>
7 changes: 2 additions & 5 deletions src/System.Security.Cryptography.Primitives/ref/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
"System.Threading.Tasks": "4.4.0-beta-24615-03"
},
"frameworks": {
"netstandard1.7": {
"imports": [
"dotnet5.8"
]
}
"netstandard1.7": {},
"netcoreapp1.1": {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,22 @@ public class CryptoStream : Stream, IDisposable
private bool _canWrite;
private bool _finalBlockTransformed;
private SemaphoreSlim _lazyAsyncActiveSemaphore;

private readonly bool _leaveOpen;

// Constructors

public CryptoStream(Stream stream, ICryptoTransform transform, CryptoStreamMode mode)
: this(stream, transform, mode, false)
{
}

public CryptoStream(Stream stream, ICryptoTransform transform, CryptoStreamMode mode, bool leaveOpen)
{

_stream = stream;
_transformMode = mode;
_transform = transform;
_leaveOpen = leaveOpen;
switch (_transformMode)
{
case CryptoStreamMode.Read:
Expand Down Expand Up @@ -523,7 +530,10 @@ protected override void Dispose(bool disposing)
{
FlushFinalBlock();
}
_stream.Dispose();
if (!_leaveOpen)
{
_stream.Dispose();
}
}
}
finally
Expand Down
31 changes: 29 additions & 2 deletions src/System.Security.Cryptography.Primitives/tests/CryptoStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,38 @@ public static void NestedCryptoStreams()
public static void MultipleDispose()
{
ICryptoTransform encryptor = new IdentityTransform(1, 1, true);

using (MemoryStream output = new MemoryStream())
{
using (CryptoStream encryptStream = new CryptoStream(output, encryptor, CryptoStreamMode.Write))
{
encryptStream.Dispose();
}

Assert.Equal(false, output.CanRead);
}

#if netcoreapp11
using (MemoryStream output = new MemoryStream())
{
using (CryptoStream encryptStream = new CryptoStream(output, encryptor, CryptoStreamMode.Write, leaveOpen: false))
{
encryptStream.Dispose();
}

Assert.Equal(false, output.CanRead);
}

using (MemoryStream output = new MemoryStream())
using (CryptoStream encryptStream = new CryptoStream(output, encryptor, CryptoStreamMode.Write))
{
encryptStream.Dispose();
using (CryptoStream encryptStream = new CryptoStream(output, encryptor, CryptoStreamMode.Write, leaveOpen: true))
{
encryptStream.Dispose();
}

Assert.Equal(true, output.CanRead);
}
#endif
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think elsewhere we've been separating out such tests that depend on new surface area into separate files.

}

private const string LoremText =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
<OSGroup>Windows_NT</OSGroup>
<TestTFMs>netcoreapp1.0</TestTFMs>
</Project>
<Project Include="System.Security.Cryptography.Primitives.Tests.csproj">
<TargetGroup>netcoreapp1.1</TargetGroup>
<TestTFMs>netcoreapp1.1</TestTFMs>
</Project>
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.traversal.targets))\dir.traversal.targets" />
</Project>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<AssemblyName>System.Security.Cryptography.Primitives.Tests</AssemblyName>
<RootNamespace>System.Security.Cryptography.Primitives.Tests</RootNamespace>
<NugetTargetMoniker Condition="'$(TargetGroup)'==''">.NETStandard,Version=v1.7</NugetTargetMoniker>
<DefineConstants Condition="'$(TargetGroup)' == 'netcoreapp1.1'">$(DefineConstants);netcoreapp11</DefineConstants>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\pkg\System.Security.Cryptography.Primitives.pkgproj">
Expand Down