diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2012-03-10 07:49:13 -0800 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2012-03-10 07:49:13 -0800 |
commit | 6e68095c020f88f6c61b3a76f1fa885ead1e7f15 (patch) | |
tree | 83bfc6d5ff5cddf7144cc85de5b4df755753b724 /src/DotNetOpenAuth.OpenId/OpenId/DiffieHellmanUtilities.cs | |
parent | 945b058634609684e72d6ea233d4643dd2f17a32 (diff) | |
parent | 351ecb6678ec3cbd469bfa8076dfdc7aad83e987 (diff) | |
download | DotNetOpenAuth-6e68095c020f88f6c61b3a76f1fa885ead1e7f15.zip DotNetOpenAuth-6e68095c020f88f6c61b3a76f1fa885ead1e7f15.tar.gz DotNetOpenAuth-6e68095c020f88f6c61b3a76f1fa885ead1e7f15.tar.bz2 |
Merge branch 'stylecopUpgrade'
Diffstat (limited to 'src/DotNetOpenAuth.OpenId/OpenId/DiffieHellmanUtilities.cs')
-rw-r--r-- | src/DotNetOpenAuth.OpenId/OpenId/DiffieHellmanUtilities.cs | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/src/DotNetOpenAuth.OpenId/OpenId/DiffieHellmanUtilities.cs b/src/DotNetOpenAuth.OpenId/OpenId/DiffieHellmanUtilities.cs index 5c18275..e15bd6e 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/DiffieHellmanUtilities.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/DiffieHellmanUtilities.cs @@ -22,12 +22,7 @@ namespace DotNetOpenAuth.OpenId { /// <summary> /// An array of known Diffie Hellman sessions, sorted by decreasing hash size. /// </summary> - private static DHSha[] diffieHellmanSessionTypes = new List<DHSha> { - new DHSha(SHA512.Create(), protocol => protocol.Args.SessionType.DH_SHA512), - new DHSha(SHA384.Create(), protocol => protocol.Args.SessionType.DH_SHA384), - new DHSha(SHA256.Create(), protocol => protocol.Args.SessionType.DH_SHA256), - new DHSha(SHA1.Create(), protocol => protocol.Args.SessionType.DH_SHA1), - } .ToArray(); + private static DHSha[] diffieHellmanSessionTypes = CreateSessionTypes(); /// <summary> /// Finds the hashing algorithm to use given an openid.session_type value. @@ -41,7 +36,7 @@ namespace DotNetOpenAuth.OpenId { Requires.NotNull(sessionType, "sessionType"); // We COULD use just First instead of FirstOrDefault, but we want to throw ProtocolException instead of InvalidOperationException. - DHSha match = diffieHellmanSessionTypes.FirstOrDefault(dhsha => String.Equals(dhsha.GetName(protocol), sessionType, StringComparison.Ordinal)); + DHSha match = diffieHellmanSessionTypes.FirstOrDefault(dhsha => string.Equals(dhsha.GetName(protocol), sessionType, StringComparison.Ordinal)); ErrorUtilities.VerifyProtocol(match != null, OpenIdStrings.NoSessionTypeFound, sessionType, protocol.Version); return match.Algorithm; } @@ -119,6 +114,23 @@ namespace DotNetOpenAuth.OpenId { } /// <summary> + /// Returns the value used to initialize the static field storing DH session types. + /// </summary> + /// <returns>A non-null, non-empty array.</returns> + /// <remarks>> + /// This is a method rather than being inlined to the field initializer to try to avoid + /// the CLR bug that crops up sometimes if we initialize arrays using object initializer syntax. + /// </remarks> + private static DHSha[] CreateSessionTypes() { + return new[] { + new DHSha(SHA512.Create(), protocol => protocol.Args.SessionType.DH_SHA512), + new DHSha(SHA384.Create(), protocol => protocol.Args.SessionType.DH_SHA384), + new DHSha(SHA256.Create(), protocol => protocol.Args.SessionType.DH_SHA256), + new DHSha(SHA1.Create(), protocol => protocol.Args.SessionType.DH_SHA1), + }; + } + + /// <summary> /// Provides access to a Diffie-Hellman session algorithm and its name. /// </summary> private class DHSha { |