forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initialize HashSizeValue for digest algorithms.
The abstract types SHAx and MD5 did not set HashSizeValue, which would lead to derived types to have HashSize a value of 0. This initializes the field to match .NET Framework behavior.
- Loading branch information
Showing
7 changed files
with
109 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
src/libraries/System.Security.Cryptography.Algorithms/tests/HashDerivedTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// 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.Hashing.Algorithms.Tests | ||
{ | ||
public static class HashDerivedTests | ||
{ | ||
[Fact] | ||
public static void HashSize_SetForDerived_SHA1() | ||
{ | ||
using DerivedSHA1 sha = new DerivedSHA1(); | ||
Assert.Equal(160, sha.HashSize); | ||
} | ||
|
||
[Fact] | ||
public static void HashSize_SetForDerived_SHA256() | ||
{ | ||
using DerivedSHA256 sha = new DerivedSHA256(); | ||
Assert.Equal(256, sha.HashSize); | ||
} | ||
|
||
[Fact] | ||
public static void HashSize_SetForDerived_SHA384() | ||
{ | ||
using DerivedSHA384 sha = new DerivedSHA384(); | ||
Assert.Equal(384, sha.HashSize); | ||
} | ||
|
||
[Fact] | ||
public static void HashSize_SetForDerived_SHA512() | ||
{ | ||
using DerivedSHA512 sha = new DerivedSHA512(); | ||
Assert.Equal(512, sha.HashSize); | ||
} | ||
|
||
[Fact] | ||
public static void HashSize_SetForDerived_MD5() | ||
{ | ||
using DerivedMD5 sha = new DerivedMD5(); | ||
Assert.Equal(128, sha.HashSize); | ||
} | ||
|
||
private class DerivedSHA1 : SHA1 | ||
{ | ||
public override void Initialize() => throw null; | ||
protected override byte[] HashFinal() => throw null; | ||
protected override void HashCore(byte[] array, int ibStart, int cbSize) => throw null; | ||
} | ||
|
||
private class DerivedSHA256 : SHA256 | ||
{ | ||
public override void Initialize() => throw null; | ||
protected override byte[] HashFinal() => throw null; | ||
protected override void HashCore(byte[] array, int ibStart, int cbSize) => throw null; | ||
} | ||
|
||
private class DerivedSHA384 : SHA384 | ||
{ | ||
public override void Initialize() => throw null; | ||
protected override byte[] HashFinal() => throw null; | ||
protected override void HashCore(byte[] array, int ibStart, int cbSize) => throw null; | ||
} | ||
|
||
private class DerivedSHA512 : SHA512 | ||
{ | ||
public override void Initialize() => throw null; | ||
protected override byte[] HashFinal() => throw null; | ||
protected override void HashCore(byte[] array, int ibStart, int cbSize) => throw null; | ||
} | ||
|
||
private class DerivedMD5 : MD5 | ||
{ | ||
public override void Initialize() => throw null; | ||
protected override byte[] HashFinal() => throw null; | ||
protected override void HashCore(byte[] array, int ibStart, int cbSize) => throw null; | ||
} | ||
|
||
private class DerivedHMACMD5 : HMACMD5 | ||
{ | ||
public override void Initialize() => throw null; | ||
protected override byte[] HashFinal() => throw null; | ||
protected override void HashCore(byte[] array, int ibStart, int cbSize) => throw null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters