-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bring the AlgorithmIdentifier.Parameters property back
Add AlgorithmIdentifier.Parameters, but always set it to the empty array. There aren't any really understood scenarios for why someone would want to read the algorithm parameters. Combined with .NET Framework only assigning a non-empty value some of the time, never assigning the correct value, and not having a consistent incorrect value, the empty array seemed the best thing for now. Commit migrated from dotnet/corefx@64bab98
- Loading branch information
1 parent
6225cfe
commit ce99945
Showing
4 changed files
with
117 additions
and
0 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
113 changes: 113 additions & 0 deletions
113
src/libraries/System.Security.Cryptography.Pkcs/tests/AlgorithmIdentifierTest.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,113 @@ | ||
// 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 Test.Cryptography; | ||
using Xunit; | ||
|
||
namespace System.Security.Cryptography.Pkcs.Tests | ||
{ | ||
public static class AlgorithmIdentifierTest | ||
{ | ||
[Fact] | ||
public static void ParameterlessConstructor() | ||
{ | ||
AlgorithmIdentifier ai = new AlgorithmIdentifier(); | ||
Assert.Equal(0, ai.KeyLength); | ||
Assert.Equal(Oids.TripleDesCbc, ai.Oid.Value); | ||
Assert.NotNull(ai.Parameters); | ||
Assert.Equal(0, ai.Parameters.Length); | ||
} | ||
|
||
[Fact] | ||
public static void ConstructorTakesOid() | ||
{ | ||
Oid o = new Oid(Oids.Rsa); | ||
AlgorithmIdentifier ai = new AlgorithmIdentifier(o); | ||
Assert.Equal(0, ai.KeyLength); | ||
Assert.Equal(Oids.Rsa, ai.Oid.Value); | ||
Assert.NotNull(ai.Parameters); | ||
Assert.Equal(0, ai.Parameters.Length); | ||
} | ||
|
||
[Fact] | ||
public static void ConstructorTakesNullOid() | ||
{ | ||
AlgorithmIdentifier ai = new AlgorithmIdentifier(null); | ||
Assert.Null(ai.Oid); | ||
Assert.Equal(0, ai.KeyLength); | ||
Assert.NotNull(ai.Parameters); | ||
Assert.Equal(0, ai.Parameters.Length); | ||
} | ||
|
||
[Fact] | ||
public static void ConstructorTakesOidAndKeyLength() | ||
{ | ||
Oid o = new Oid(Oids.Rsa); | ||
AlgorithmIdentifier ai = new AlgorithmIdentifier(o, 128); | ||
Assert.Equal(128, ai.KeyLength); | ||
Assert.Equal(Oids.Rsa, ai.Oid.Value); | ||
Assert.NotNull(ai.Parameters); | ||
Assert.Equal(0, ai.Parameters.Length); | ||
} | ||
|
||
[Fact] | ||
public static void ConstructorTakesNullOidAndKeyLength() | ||
{ | ||
AlgorithmIdentifier ai = new AlgorithmIdentifier(null, 128); | ||
Assert.Null(ai.Oid); | ||
Assert.Equal(128, ai.KeyLength); | ||
Assert.NotNull(ai.Parameters); | ||
Assert.Equal(0, ai.Parameters.Length); | ||
} | ||
|
||
[Fact] | ||
public static void ConstructorTakesOidAndNegativeKeyLength() | ||
{ | ||
Oid o = new Oid(Oids.Rsa); | ||
AlgorithmIdentifier ai = new AlgorithmIdentifier(o, -1); | ||
Assert.Equal(-1, ai.KeyLength); | ||
Assert.Equal(Oids.Rsa, ai.Oid.Value); | ||
Assert.NotNull(ai.Parameters); | ||
Assert.Equal(0, ai.Parameters.Length); | ||
} | ||
|
||
[Fact] | ||
public static void KeyLength() | ||
{ | ||
AlgorithmIdentifier ai = new AlgorithmIdentifier | ||
{ | ||
KeyLength = int.MaxValue | ||
}; | ||
Assert.Equal(int.MaxValue, ai.KeyLength); | ||
ai.KeyLength = 0; | ||
Assert.Equal(0, ai.KeyLength); | ||
ai.KeyLength = int.MinValue; | ||
Assert.Equal(int.MinValue, ai.KeyLength); | ||
} | ||
|
||
[Fact] | ||
public static void Oid() | ||
{ | ||
AlgorithmIdentifier ai = new AlgorithmIdentifier | ||
{ | ||
Oid = new Oid(Oids.Rsa) | ||
}; | ||
Assert.Equal(Oids.Rsa, ai.Oid.Value); | ||
ai.Oid = null; | ||
Assert.Null(ai.Oid); | ||
} | ||
|
||
[Fact] | ||
public static void Parameters() | ||
{ | ||
AlgorithmIdentifier ai = new AlgorithmIdentifier | ||
{ | ||
Parameters = new byte[2] { 0x05, 0x00 } // ASN.1 NULL | ||
}; | ||
Assert.Equal("0500", ai.Parameters.ByteArrayToHex()); | ||
ai.Parameters = null; | ||
Assert.Null(ai.Parameters); | ||
} | ||
} | ||
} |
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