12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
14
15
+ using System . Linq ;
15
16
using System . Security . Cryptography ;
16
17
using Xunit ;
17
- using Yubico . YubiKey . Piv ;
18
18
using Yubico . YubiKey . Piv . Converters ;
19
19
using Yubico . YubiKey . TestUtilities ;
20
20
21
21
namespace Yubico . YubiKey . Cryptography ;
22
22
23
- public class RsaPrivateKeyTests
23
+ public class RSAPrivateKeyTests
24
24
{
25
+ [ Fact ]
26
+ public void Dispose_DisposesResources ( )
27
+ {
28
+ // Arrange
29
+ using var rsa = RSA . Create ( 2048 ) ;
30
+ var parameters = rsa . ExportParameters ( true ) ;
31
+ var privateKey = RSAPrivateKey . CreateFromParameters ( parameters ) ;
32
+
33
+ // Act
34
+ privateKey . Dispose ( ) ;
35
+
36
+ // Assert all bytes are zero
37
+ Assert . True ( privateKey . Parameters . Modulus ? . All ( b => b == 0 ) ?? true ) ;
38
+ Assert . True ( privateKey . Parameters . Exponent ? . All ( b => b == 0 ) ?? true ) ;
39
+ Assert . True ( privateKey . Parameters . P ? . All ( b => b == 0 ) ?? true ) ;
40
+ Assert . True ( privateKey . Parameters . Q ? . All ( b => b == 0 ) ?? true ) ;
41
+ Assert . True ( privateKey . Parameters . DP ? . All ( b => b == 0 ) ?? true ) ;
42
+ Assert . True ( privateKey . Parameters . DQ ? . All ( b => b == 0 ) ?? true ) ;
43
+ Assert . True ( privateKey . Parameters . InverseQ ? . All ( b => b == 0 ) ?? true ) ;
44
+ }
45
+
46
+
25
47
[ Fact ]
26
48
public void CreateFromPivEncoding_WithValidParameters_CreatesInstance ( )
27
49
{
@@ -43,7 +65,7 @@ public void CreateFromPivEncoding_WithValidParameters_CreatesInstance()
43
65
Assert . Equal ( parameters . DQ , privateKeyParams . Parameters . DQ ) ;
44
66
Assert . Equal ( parameters . InverseQ , privateKeyParams . Parameters . InverseQ ) ;
45
67
}
46
-
68
+
47
69
[ Fact ]
48
70
public void CreateFromPkcs8_WithValidParameters_CreatesInstance ( )
49
71
{
@@ -65,14 +87,14 @@ public void CreateFromPkcs8_WithValidParameters_CreatesInstance()
65
87
Assert . Equal ( parameters . DQ , privateKeyParams . Parameters . DQ ) ;
66
88
Assert . Equal ( parameters . InverseQ , privateKeyParams . Parameters . InverseQ ) ;
67
89
}
68
-
90
+
69
91
[ Fact ]
70
92
public void CreateFromRsaParameters_WithValidParameters_CreatesInstance ( )
71
93
{
72
94
// Arrange
73
95
using var rsa = RSA . Create ( 2048 ) ;
74
96
var parameters = rsa . ExportParameters ( true ) ;
75
-
97
+
76
98
// Act
77
99
var privateKeyParams = RSAPrivateKey . CreateFromParameters ( parameters ) ;
78
100
@@ -84,10 +106,10 @@ public void CreateFromRsaParameters_WithValidParameters_CreatesInstance()
84
106
Assert . Equal ( parameters . DP , privateKeyParams . Parameters . DP ) ;
85
107
Assert . Equal ( parameters . DQ , privateKeyParams . Parameters . DQ ) ;
86
108
Assert . Equal ( parameters . InverseQ , privateKeyParams . Parameters . InverseQ ) ;
87
-
109
+
88
110
Assert . Equal ( rsa . ExportPkcs8PrivateKey ( ) , privateKeyParams . ExportPkcs8PrivateKey ( ) ) ;
89
111
}
90
-
112
+
91
113
[ Fact ]
92
114
public void CreateFromRsaParameters_WithCRTParameters_CreatesInstance ( )
93
115
{
@@ -102,7 +124,7 @@ public void CreateFromRsaParameters_WithCRTParameters_CreatesInstance()
102
124
DQ = parameters . DQ ,
103
125
InverseQ = parameters . InverseQ
104
126
} ;
105
-
127
+
106
128
// Act
107
129
var privateKeyParams = RSAPrivateKey . CreateFromParameters ( crtParameters ) ;
108
130
0 commit comments