diff options
-rw-r--r-- | crypto/src/asn1/x509/X509Name.cs | 8 | ||||
-rw-r--r-- | crypto/src/operators/utilities/DefaultDigestAlgorithmFinder.cs | 12 | ||||
-rw-r--r-- | crypto/src/pkcs/Pkcs10CertificationRequestDelaySigned.cs | 18 |
3 files changed, 13 insertions, 25 deletions
diff --git a/crypto/src/asn1/x509/X509Name.cs b/crypto/src/asn1/x509/X509Name.cs index 8fd564090..6135ad2fa 100644 --- a/crypto/src/asn1/x509/X509Name.cs +++ b/crypto/src/asn1/x509/X509Name.cs @@ -532,11 +532,11 @@ namespace Org.BouncyCastle.Asn1.X509 if (name.StartsWith("OID.", StringComparison.OrdinalIgnoreCase)) return new DerObjectIdentifier(name.Substring("OID.".Length)); - if (name[0] >= '0' && name[0] <= '9') - return new DerObjectIdentifier(name); - - if (lookup.TryGetValue(name, out var oid)) + if (DerObjectIdentifier.TryFromID(name, out var oid) || + lookup.TryGetValue(name, out oid)) + { return oid; + } throw new ArgumentException("Unknown object id - " + name + " - passed to distinguished name"); } diff --git a/crypto/src/operators/utilities/DefaultDigestAlgorithmFinder.cs b/crypto/src/operators/utilities/DefaultDigestAlgorithmFinder.cs index 025b94622..4e71c8a94 100644 --- a/crypto/src/operators/utilities/DefaultDigestAlgorithmFinder.cs +++ b/crypto/src/operators/utilities/DefaultDigestAlgorithmFinder.cs @@ -308,16 +308,10 @@ namespace Org.BouncyCastle.Operators.Utilities public virtual AlgorithmIdentifier Find(string digestName) { - if (DigestNameToOids.TryGetValue(digestName, out var digestOid)) - return Find(digestOid); - - try + if (DigestNameToOids.TryGetValue(digestName, out var digestOid) || + DerObjectIdentifier.TryFromID(digestName, out digestOid)) { - return Find(new DerObjectIdentifier(digestName)); - } - catch (Exception) - { - // ignore - tried it but it didn't work... + return Find(digestOid); } return null; diff --git a/crypto/src/pkcs/Pkcs10CertificationRequestDelaySigned.cs b/crypto/src/pkcs/Pkcs10CertificationRequestDelaySigned.cs index e3a710f37..f95cf826c 100644 --- a/crypto/src/pkcs/Pkcs10CertificationRequestDelaySigned.cs +++ b/crypto/src/pkcs/Pkcs10CertificationRequestDelaySigned.cs @@ -95,18 +95,12 @@ namespace Org.BouncyCastle.Pkcs if (publicKey.IsPrivate) throw new ArgumentException("expected public key", "publicKey"); - DerObjectIdentifier sigOid = CollectionUtilities.GetValueOrNull(m_algorithms, signatureAlgorithm); - if (sigOid == null) - { - try - { - sigOid = new DerObjectIdentifier(signatureAlgorithm); - } - catch (Exception e) - { - throw new ArgumentException("Unknown signature type requested", e); - } - } + if (!m_algorithms.TryGetValue(signatureAlgorithm, out var sigOid) && + !DerObjectIdentifier.TryFromID(signatureAlgorithm, out sigOid)) + { + throw new ArgumentException("Unknown signature type requested"); + } + if (m_noParams.Contains(sigOid)) { this.sigAlgId = new AlgorithmIdentifier(sigOid); |