7
7
using Org . BouncyCastle . Asn1 . X509 ;
8
8
using Org . BouncyCastle . Asn1 . X9 ;
9
9
using Org . BouncyCastle . Security ;
10
+ using Org . BouncyCastle . Utilities ;
10
11
11
12
namespace Org . BouncyCastle . X509
12
13
{
@@ -17,43 +18,15 @@ internal static bool AreEquivalentAlgorithms(AlgorithmIdentifier id1, AlgorithmI
17
18
if ( ! id1 . Algorithm . Equals ( id2 . Algorithm ) )
18
19
return false ;
19
20
20
- Asn1Encodable p1 = id1 . Parameters ;
21
- Asn1Encodable p2 = id2 . Parameters ;
21
+ // TODO Java has a property to control whether absent parameters can match NULL parameters
22
+ {
23
+ if ( IsAbsentOrEmptyParameters ( id1 . Parameters ) && IsAbsentOrEmptyParameters ( id2 . Parameters ) )
24
+ return true ;
25
+ }
22
26
23
- if ( p1 == p2 )
24
- return true ;
25
- if ( p1 == null )
26
- return p2 . ToAsn1Object ( ) is Asn1Null ;
27
- if ( p2 == null )
28
- return p1 . ToAsn1Object ( ) is Asn1Null ;
29
-
30
- return p1 . Equals ( p2 ) ;
27
+ return Objects . Equals ( id1 . Parameters , id2 . Parameters ) ;
31
28
}
32
29
33
- internal static string GetSignatureName ( AlgorithmIdentifier sigAlgID )
34
- {
35
- DerObjectIdentifier sigAlgOid = sigAlgID . Algorithm ;
36
- Asn1Encodable parameters = sigAlgID . Parameters ;
37
-
38
- if ( parameters != null && ! DerNull . Instance . Equals ( parameters ) )
39
- {
40
- if ( PkcsObjectIdentifiers . IdRsassaPss . Equals ( sigAlgOid ) )
41
- {
42
- RsassaPssParameters rsaParams = RsassaPssParameters . GetInstance ( parameters ) ;
43
-
44
- return GetDigestAlgName ( rsaParams . HashAlgorithm . Algorithm ) + "withRSAandMGF1" ;
45
- }
46
- if ( X9ObjectIdentifiers . ECDsaWithSha2 . Equals ( sigAlgOid ) )
47
- {
48
- Asn1Sequence ecDsaParams = Asn1Sequence . GetInstance ( parameters ) ;
49
-
50
- return GetDigestAlgName ( ( DerObjectIdentifier ) ecDsaParams [ 0 ] ) + "withECDSA" ;
51
- }
52
- }
53
-
54
- return SignerUtilities . GetEncodingName ( sigAlgOid ) ?? sigAlgOid . GetID ( ) ;
55
- }
56
-
57
30
/**
58
31
* Return the digest algorithm using one of the standard JCA string
59
32
* representations rather than the algorithm identifier (if possible).
@@ -103,7 +76,36 @@ private static string GetDigestAlgName(DerObjectIdentifier digestAlgOID)
103
76
else
104
77
{
105
78
return digestAlgOID . GetID ( ) ;
79
+ }
80
+ }
81
+
82
+ internal static string GetSignatureName ( AlgorithmIdentifier sigAlgID )
83
+ {
84
+ DerObjectIdentifier sigAlgOid = sigAlgID . Algorithm ;
85
+ Asn1Encodable parameters = sigAlgID . Parameters ;
86
+
87
+ if ( ! IsAbsentOrEmptyParameters ( parameters ) )
88
+ {
89
+ if ( PkcsObjectIdentifiers . IdRsassaPss . Equals ( sigAlgOid ) )
90
+ {
91
+ RsassaPssParameters rsaParams = RsassaPssParameters . GetInstance ( parameters ) ;
92
+
93
+ return GetDigestAlgName ( rsaParams . HashAlgorithm . Algorithm ) + "withRSAandMGF1" ;
94
+ }
95
+ if ( X9ObjectIdentifiers . ECDsaWithSha2 . Equals ( sigAlgOid ) )
96
+ {
97
+ Asn1Sequence ecDsaParams = Asn1Sequence . GetInstance ( parameters ) ;
98
+
99
+ return GetDigestAlgName ( ( DerObjectIdentifier ) ecDsaParams [ 0 ] ) + "withECDSA" ;
100
+ }
106
101
}
102
+
103
+ return SignerUtilities . GetEncodingName ( sigAlgOid ) ?? sigAlgOid . GetID ( ) ;
107
104
}
105
+
106
+ private static bool IsAbsentOrEmptyParameters ( Asn1Encodable parameters )
107
+ {
108
+ return parameters == null || DerNull . Instance . Equals ( parameters ) ;
109
+ }
108
110
}
109
111
}
0 commit comments