Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corefx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSteve Harter <steveharter@users.noreply.github.com>2016-10-06 18:35:29 +0300
committerGitHub <noreply@github.com>2016-10-06 18:35:29 +0300
commita8b4cb2fa68b2c3e1703f176b8819b99f4ead67f (patch)
tree24bebb49ea03b667f514d0a86c9468043630f194 /src
parentf88851644dde16929040b54f23fee4752ef7e9ec (diff)
S.S.C.Algorithms and .Encoding ns2.0 misc additions (#12410)
Diffstat (limited to 'src')
-rw-r--r--src/System.Security.Cryptography.Algorithms/ref/System.Security.Cryptography.Algorithms.cs10
-rw-r--r--src/System.Security.Cryptography.Algorithms/src/System.Security.Cryptography.Algorithms.csproj1
-rw-r--r--src/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/ECDiffieHellmanPublicKey.cs43
-rw-r--r--src/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/HMACSHA1.cs11
-rw-r--r--src/System.Security.Cryptography.Algorithms/tests/ECDiffieHellmanPublicKeyTests.cs40
-rw-r--r--src/System.Security.Cryptography.Algorithms/tests/HmacSha1Tests.cs24
-rw-r--r--src/System.Security.Cryptography.Algorithms/tests/HmacTests.cs12
-rw-r--r--src/System.Security.Cryptography.Algorithms/tests/System.Security.Cryptography.Algorithms.Tests.csproj1
-rw-r--r--src/System.Security.Cryptography.Encoding/ref/System.Security.Cryptography.Encoding.cs9
-rw-r--r--src/System.Security.Cryptography.Encoding/src/System/Security/Cryptography/AsnEncodedDataCollection.cs4
-rw-r--r--src/System.Security.Cryptography.Encoding/src/System/Security/Cryptography/Oid.cs2
-rw-r--r--src/System.Security.Cryptography.Encoding/src/System/Security/Cryptography/OidCollection.cs4
-rw-r--r--src/System.Security.Cryptography.Encoding/tests/Oid.cs6
-rw-r--r--src/System.Security.Cryptography.Encoding/tests/System.Security.Cryptography.Encoding.Tests.csproj1
14 files changed, 156 insertions, 12 deletions
diff --git a/src/System.Security.Cryptography.Algorithms/ref/System.Security.Cryptography.Algorithms.cs b/src/System.Security.Cryptography.Algorithms/ref/System.Security.Cryptography.Algorithms.cs
index aa6b710b3e..4cec6758ba 100644
--- a/src/System.Security.Cryptography.Algorithms/ref/System.Security.Cryptography.Algorithms.cs
+++ b/src/System.Security.Cryptography.Algorithms/ref/System.Security.Cryptography.Algorithms.cs
@@ -151,6 +151,14 @@ namespace System.Security.Cryptography
public static System.Security.Cryptography.ECCurve nistP521 { get { return default(System.Security.Cryptography.ECCurve); } }
}
}
+ public abstract partial class ECDiffieHellmanPublicKey : System.IDisposable
+ {
+ protected ECDiffieHellmanPublicKey(byte[] keyBlob) { }
+ public void Dispose() { }
+ protected virtual void Dispose(bool disposing) { }
+ public virtual byte[] ToByteArray() { return default(byte[]); }
+ public virtual string ToXmlString() { return default(string); }
+ }
public abstract partial class ECDsa : System.Security.Cryptography.AsymmetricAlgorithm
{
protected ECDsa() { }
@@ -201,6 +209,8 @@ namespace System.Security.Cryptography
{
public HMACSHA1() { }
public HMACSHA1(byte[] key) { }
+ [System.ComponentModel.EditorBrowsableAttribute((System.ComponentModel.EditorBrowsableState)(1))]
+ public HMACSHA1(byte[] key, bool useManagedSha1) { }
public override int HashSize { get { return default(int); } }
public override byte[] Key { get { return default(byte[]); } set { } }
protected override void Dispose(bool disposing) { }
diff --git a/src/System.Security.Cryptography.Algorithms/src/System.Security.Cryptography.Algorithms.csproj b/src/System.Security.Cryptography.Algorithms/src/System.Security.Cryptography.Algorithms.csproj
index 14c8ffee66..4f5139776c 100644
--- a/src/System.Security.Cryptography.Algorithms/src/System.Security.Cryptography.Algorithms.csproj
+++ b/src/System.Security.Cryptography.Algorithms/src/System.Security.Cryptography.Algorithms.csproj
@@ -38,6 +38,7 @@
<Compile Include="System\Security\Cryptography\ECCurve.cs" />
<Compile Include="System\Security\Cryptography\ECCurve.ECCurveType.cs" />
<Compile Include="System\Security\Cryptography\ECCurve.NamedCurves.cs" />
+ <Compile Include="System\Security\Cryptography\ECDiffieHellmanPublicKey.cs" />
<Compile Include="System\Security\Cryptography\ECDsa.cs" />
<Compile Include="System\Security\Cryptography\ECParameters.cs" />
<Compile Include="System\Security\Cryptography\ECPoint.cs" />
diff --git a/src/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/ECDiffieHellmanPublicKey.cs b/src/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/ECDiffieHellmanPublicKey.cs
new file mode 100644
index 0000000000..78b04674d1
--- /dev/null
+++ b/src/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/ECDiffieHellmanPublicKey.cs
@@ -0,0 +1,43 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace System.Security.Cryptography
+{
+ /// <summary>
+ /// Wrapper for public key material passed between parties during Diffie-Hellman key material generation
+ /// </summary>
+ [Serializable]
+ public abstract class ECDiffieHellmanPublicKey : IDisposable
+ {
+ private readonly byte[] _keyBlob;
+
+ protected ECDiffieHellmanPublicKey(byte[] keyBlob)
+ {
+ if (keyBlob == null)
+ {
+ throw new ArgumentNullException(nameof(keyBlob));
+ }
+
+ _keyBlob = keyBlob.Clone() as byte[];
+ }
+
+ public void Dispose()
+ {
+ Dispose(true);
+ }
+
+ protected virtual void Dispose(bool disposing) { }
+
+ public virtual byte[] ToByteArray()
+ {
+ return _keyBlob.Clone() as byte[];
+ }
+
+ // This method must be implemented by derived classes. In order to conform to the contract, it cannot be abstract.
+ public virtual string ToXmlString()
+ {
+ throw new NotImplementedException(SR.NotSupported_SubclassOverride);
+ }
+ }
+}
diff --git a/src/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/HMACSHA1.cs b/src/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/HMACSHA1.cs
index 4af80f794c..f12fef68a0 100644
--- a/src/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/HMACSHA1.cs
+++ b/src/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/HMACSHA1.cs
@@ -2,11 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System;
-using System.Diagnostics;
-using System.Security.Cryptography;
-
using Internal.Cryptography;
+using System.ComponentModel;
namespace System.Security.Cryptography
{
@@ -29,6 +26,12 @@ namespace System.Security.Cryptography
base.Key = _hMacCommon.ActualKey;
}
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public HMACSHA1(byte[] key, bool useManagedSha1) : this(key)
+ {
+ // useManagedSha1 is ignored
+ }
+
public override int HashSize
{
get
diff --git a/src/System.Security.Cryptography.Algorithms/tests/ECDiffieHellmanPublicKeyTests.cs b/src/System.Security.Cryptography.Algorithms/tests/ECDiffieHellmanPublicKeyTests.cs
new file mode 100644
index 0000000000..c05419d65c
--- /dev/null
+++ b/src/System.Security.Cryptography.Algorithms/tests/ECDiffieHellmanPublicKeyTests.cs
@@ -0,0 +1,40 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using Xunit;
+
+namespace System.Security.Cryptography.ECDiffieHellman.Tests
+{
+ public class ECDiffieHellmanPublicKeyTests
+ {
+ private class TestDerived : ECDiffieHellmanPublicKey
+ {
+ public TestDerived(byte[] keyBlob) : base(keyBlob) { }
+ }
+
+ [Fact]
+ public void TestInvalidConstructorArgs()
+ {
+ Assert.Throws<ArgumentNullException>("keyBlob", () => new TestDerived(null));
+ }
+
+ [Fact]
+ public void TestToByteArray()
+ {
+ byte[] arg = new byte[1] { 1 };
+ var pk = new TestDerived(arg);
+
+ Assert.Equal(1, pk.ToByteArray()[0]);
+ }
+
+ [Fact]
+ public void TestToXmlString()
+ {
+ byte[] arg = new byte[1] { 1 };
+ var pk = new TestDerived(arg);
+
+ Assert.Throws<NotImplementedException>(() => pk.ToXmlString());
+ }
+ }
+}
diff --git a/src/System.Security.Cryptography.Algorithms/tests/HmacSha1Tests.cs b/src/System.Security.Cryptography.Algorithms/tests/HmacSha1Tests.cs
index 6618cf9e18..f7da1b0361 100644
--- a/src/System.Security.Cryptography.Algorithms/tests/HmacSha1Tests.cs
+++ b/src/System.Security.Cryptography.Algorithms/tests/HmacSha1Tests.cs
@@ -39,6 +39,30 @@ namespace System.Security.Cryptography.Hashing.Algorithms.Tests
protected override int BlockSize { get { return 64; } }
[Fact]
+ public void HmacSha1_Byte_Constructors()
+ {
+ byte[] key = (byte[])s_testKeys2202[1].Clone();
+ string digest = "b617318655057264e28bc0b6fb378c8ef146be00";
+
+ using (HMACSHA1 h1 = new HMACSHA1(key))
+ {
+ VerifyHmac_KeyAlreadySet(h1, 1, digest);
+#if netstandard17
+ using (HMACSHA1 h2 = new HMACSHA1(key, true))
+ {
+ VerifyHmac_KeyAlreadySet(h2, 1, digest);
+ Assert.Equal(h1.Key, h2.Key);
+ }
+ using (HMACSHA1 h2 = new HMACSHA1(key, false))
+ {
+ VerifyHmac_KeyAlreadySet(h1, 1, digest);
+ Assert.Equal(h1.Key, h2.Key);
+ }
+#endif
+ }
+ }
+
+ [Fact]
public void HmacSha1_Rfc2202_1()
{
VerifyHmac(1, "b617318655057264e28bc0b6fb378c8ef146be00");
diff --git a/src/System.Security.Cryptography.Algorithms/tests/HmacTests.cs b/src/System.Security.Cryptography.Algorithms/tests/HmacTests.cs
index 7e11279558..508926e79d 100644
--- a/src/System.Security.Cryptography.Algorithms/tests/HmacTests.cs
+++ b/src/System.Security.Cryptography.Algorithms/tests/HmacTests.cs
@@ -64,6 +64,18 @@ namespace System.Security.Cryptography.Hashing.Algorithms.Tests
Assert.Equal(digestBytes, computedDigest);
}
+ protected void VerifyHmac_KeyAlreadySet(
+ HMAC hmac,
+ int testCaseId,
+ string digest)
+ {
+ byte[] digestBytes = ByteUtils.HexToByteArray(digest);
+ byte[] computedDigest;
+
+ computedDigest = hmac.ComputeHash(_testData[testCaseId]);
+ Assert.Equal(digestBytes, computedDigest);
+ }
+
protected void VerifyHmacRfc2104_2()
{
// Ensure that keys shorter than the threshold don't get altered.
diff --git a/src/System.Security.Cryptography.Algorithms/tests/System.Security.Cryptography.Algorithms.Tests.csproj b/src/System.Security.Cryptography.Algorithms/tests/System.Security.Cryptography.Algorithms.Tests.csproj
index fb810bb6d1..68953f3947 100644
--- a/src/System.Security.Cryptography.Algorithms/tests/System.Security.Cryptography.Algorithms.Tests.csproj
+++ b/src/System.Security.Cryptography.Algorithms/tests/System.Security.Cryptography.Algorithms.Tests.csproj
@@ -135,6 +135,7 @@
<ItemGroup Condition="'$(TargetGroup)'==''">
<Compile Include="AsymmetricSignatureFormatterTests.cs" />
<Compile Include="DSASignatureFormatterTests.cs" />
+ <Compile Include="ECDiffieHellmanPublicKeyTests.cs" />
<Compile Include="RSAKeyExchangeFormatterTests.cs" />
<Compile Include="RSASignatureFormatterTests.cs" />
<Compile Include="DefaultDSAProvider.cs" />
diff --git a/src/System.Security.Cryptography.Encoding/ref/System.Security.Cryptography.Encoding.cs b/src/System.Security.Cryptography.Encoding/ref/System.Security.Cryptography.Encoding.cs
index 71e4f64ad5..7fd0bd30cf 100644
--- a/src/System.Security.Cryptography.Encoding/ref/System.Security.Cryptography.Encoding.cs
+++ b/src/System.Security.Cryptography.Encoding/ref/System.Security.Cryptography.Encoding.cs
@@ -25,9 +25,9 @@ namespace System.Security.Cryptography
public AsnEncodedDataCollection() { }
public AsnEncodedDataCollection(System.Security.Cryptography.AsnEncodedData asnEncodedData) { }
public int Count { get { return default(int); } }
+ public bool IsSynchronized { get { return default(bool); } }
public System.Security.Cryptography.AsnEncodedData this[int index] { get { return default(System.Security.Cryptography.AsnEncodedData); } }
- bool System.Collections.ICollection.IsSynchronized { get { return default(bool); } }
- object System.Collections.ICollection.SyncRoot { get { return default(object); } }
+ public object SyncRoot { get { return default(object); } }
public int Add(System.Security.Cryptography.AsnEncodedData asnEncodedData) { return default(int); }
public void CopyTo(System.Security.Cryptography.AsnEncodedData[] array, int index) { }
public System.Security.Cryptography.AsnEncodedDataEnumerator GetEnumerator() { return default(System.Security.Cryptography.AsnEncodedDataEnumerator); }
@@ -65,6 +65,7 @@ namespace System.Security.Cryptography
}
public sealed partial class Oid
{
+ public Oid() { }
public Oid(System.Security.Cryptography.Oid oid) { }
public Oid(string oid) { }
public Oid(string value, string friendlyName) { }
@@ -77,10 +78,10 @@ namespace System.Security.Cryptography
{
public OidCollection() { }
public int Count { get { return default(int); } }
+ public bool IsSynchronized { get { return default(bool); } }
public System.Security.Cryptography.Oid this[int index] { get { return default(System.Security.Cryptography.Oid); } }
public System.Security.Cryptography.Oid this[string oid] { get { return default(System.Security.Cryptography.Oid); } }
- bool System.Collections.ICollection.IsSynchronized { get { return default(bool); } }
- object System.Collections.ICollection.SyncRoot { get { return default(object); } }
+ public object SyncRoot { get { return default(object); } }
public int Add(System.Security.Cryptography.Oid oid) { return default(int); }
public void CopyTo(System.Security.Cryptography.Oid[] array, int index) { }
public System.Security.Cryptography.OidEnumerator GetEnumerator() { return default(System.Security.Cryptography.OidEnumerator); }
diff --git a/src/System.Security.Cryptography.Encoding/src/System/Security/Cryptography/AsnEncodedDataCollection.cs b/src/System.Security.Cryptography.Encoding/src/System/Security/Cryptography/AsnEncodedDataCollection.cs
index 4c1c1e692a..b7bbc36907 100644
--- a/src/System.Security.Cryptography.Encoding/src/System/Security/Cryptography/AsnEncodedDataCollection.cs
+++ b/src/System.Security.Cryptography.Encoding/src/System/Security/Cryptography/AsnEncodedDataCollection.cs
@@ -96,7 +96,7 @@ namespace System.Security.Cryptography
_list.CopyTo(array, index);
}
- bool ICollection.IsSynchronized
+ public bool IsSynchronized
{
get
{
@@ -104,7 +104,7 @@ namespace System.Security.Cryptography
}
}
- object ICollection.SyncRoot
+ public object SyncRoot
{
get
{
diff --git a/src/System.Security.Cryptography.Encoding/src/System/Security/Cryptography/Oid.cs b/src/System.Security.Cryptography.Encoding/src/System/Security/Cryptography/Oid.cs
index 65459be9f9..f97b2c9750 100644
--- a/src/System.Security.Cryptography.Encoding/src/System/Security/Cryptography/Oid.cs
+++ b/src/System.Security.Cryptography.Encoding/src/System/Security/Cryptography/Oid.cs
@@ -11,6 +11,8 @@ namespace System.Security.Cryptography
{
public sealed class Oid
{
+ public Oid() { }
+
public Oid(String oid)
{
// If we were passed the friendly name, retrieve the value String.
diff --git a/src/System.Security.Cryptography.Encoding/src/System/Security/Cryptography/OidCollection.cs b/src/System.Security.Cryptography.Encoding/src/System/Security/Cryptography/OidCollection.cs
index ea8042a41d..781a1947bc 100644
--- a/src/System.Security.Cryptography.Encoding/src/System/Security/Cryptography/OidCollection.cs
+++ b/src/System.Security.Cryptography.Encoding/src/System/Security/Cryptography/OidCollection.cs
@@ -81,9 +81,9 @@ namespace System.Security.Cryptography
_list.CopyTo(array, index);
}
- bool ICollection.IsSynchronized => false;
+ public bool IsSynchronized => false;
- object ICollection.SyncRoot => this;
+ public object SyncRoot => this;
private readonly List<Oid> _list;
}
diff --git a/src/System.Security.Cryptography.Encoding/tests/Oid.cs b/src/System.Security.Cryptography.Encoding/tests/Oid.cs
index d5211e5645..a0b85ce295 100644
--- a/src/System.Security.Cryptography.Encoding/tests/Oid.cs
+++ b/src/System.Security.Cryptography.Encoding/tests/Oid.cs
@@ -15,6 +15,12 @@ namespace System.Security.Cryptography.Encoding.Tests
Oid oid = new Oid("");
Assert.Equal("", oid.Value);
Assert.Null(oid.FriendlyName);
+
+#if netstandard17
+ oid = new Oid();
+ Assert.Null(oid.Value);
+ Assert.Null(oid.FriendlyName);
+#endif
}
[Theory]
diff --git a/src/System.Security.Cryptography.Encoding/tests/System.Security.Cryptography.Encoding.Tests.csproj b/src/System.Security.Cryptography.Encoding/tests/System.Security.Cryptography.Encoding.Tests.csproj
index 1e7a798d60..e741bb825b 100644
--- a/src/System.Security.Cryptography.Encoding/tests/System.Security.Cryptography.Encoding.Tests.csproj
+++ b/src/System.Security.Cryptography.Encoding/tests/System.Security.Cryptography.Encoding.Tests.csproj
@@ -12,6 +12,7 @@
<AssemblyName>System.Security.Cryptography.Encoding.Tests</AssemblyName>
<RootNamespace>System.Security.Cryptography.Encoding.Tests</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+ <DefineConstants Condition="'$(TargetGroup)'==''">$(DefineConstants);netstandard17</DefineConstants>
<NugetTargetMoniker Condition="'$(TargetGroup)' == ''">.NETStandard,Version=v1.7</NugetTargetMoniker>
</PropertyGroup>
<ItemGroup>