From 473fbfd3e1809872b7784d22c9cbc3730585c657 Mon Sep 17 00:00:00 2001 From: Sebastien Pouliot Date: Wed, 15 May 2013 16:29:44 -0400 Subject: [PATCH] Do not require an exception to detect if SHA1 is used. --- .../System.Security.Cryptography/DSASignatureDeformatter.cs | 11 ++++------- .../System.Security.Cryptography/DSASignatureFormatter.cs | 11 ++++------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/mcs/class/corlib/System.Security.Cryptography/DSASignatureDeformatter.cs b/mcs/class/corlib/System.Security.Cryptography/DSASignatureDeformatter.cs index 6f926b7cfb7..e8ac18064d6 100644 --- a/mcs/class/corlib/System.Security.Cryptography/DSASignatureDeformatter.cs +++ b/mcs/class/corlib/System.Security.Cryptography/DSASignatureDeformatter.cs @@ -3,10 +3,11 @@ // // Authors: // Thomas Neidhart (tome@sbox.tugraz.at) -// Sebastien Pouliot (sebastien@ximian.com) +// Sebastien Pouliot // // Portions (C) 2002 Motus Technologies Inc. (http://www.motus.com) // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com) +// Copyright 2013 Xamarin Inc. (http://www.xamarin.com) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -52,14 +53,10 @@ namespace System.Security.Cryptography { if (strName == null) throw new ArgumentNullException ("strName"); - try { - // just to test, we don't need the object - SHA1.Create (strName); - } - catch (InvalidCastException) { + var instance = HashAlgorithm.Create (strName) as SHA1; + if (instance == null) throw new CryptographicUnexpectedOperationException ( Locale.GetText ("DSA requires SHA1")); - } } public override void SetKey (AsymmetricAlgorithm key) diff --git a/mcs/class/corlib/System.Security.Cryptography/DSASignatureFormatter.cs b/mcs/class/corlib/System.Security.Cryptography/DSASignatureFormatter.cs index 1eaa37e2d2c..002bc126a5f 100644 --- a/mcs/class/corlib/System.Security.Cryptography/DSASignatureFormatter.cs +++ b/mcs/class/corlib/System.Security.Cryptography/DSASignatureFormatter.cs @@ -3,10 +3,11 @@ // // Authors: // Thomas Neidhart (tome@sbox.tugraz.at) -// Sebastien Pouliot (sebastien@ximian.com) +// Sebastien Pouliot // // Portions (C) 2002 Motus Technologies Inc. (http://www.motus.com) // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com) +// Copyright 2013 Xamarin Inc. (http://www.xamarin.com) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -62,14 +63,10 @@ namespace System.Security.Cryptography { if (strName == null) throw new ArgumentNullException ("strName"); - try { - // just to test, we don't need the object - SHA1.Create (strName); - } - catch (InvalidCastException) { + var instance = HashAlgorithm.Create (strName) as SHA1; + if (instance == null) throw new CryptographicUnexpectedOperationException ( Locale.GetText ("DSA requires SHA1")); - } } public override void SetKey (AsymmetricAlgorithm key) -- 2.11.4.GIT