/// <summary> /// Looks up the value to be used for the openid.session_type parameter. /// </summary> /// <param name="protocol">The protocol version that is to be used.</param> /// <param name="hashSizeInBits">The hash size (in bits) that the DH session must have.</param> /// <returns>The value to be used for the openid.session_type parameter, or null if no match was found.</returns> internal static string GetNameForSize(Protocol protocol, int hashSizeInBits) { Requires.NotNull(protocol, "protocol"); DHSha match = diffieHellmanSessionTypes.FirstOrDefault(dhsha => dhsha.Algorithm.HashSize == hashSizeInBits); return(match != null?match.GetName(protocol) : null); }
/// <summary> /// Looks up the value to be used for the openid.session_type parameter. /// </summary> /// <param name="protocol">The protocol version that is to be used.</param> /// <param name="hashSizeInBits">The hash size (in bits) that the DH session must have.</param> /// <returns>The value to be used for the openid.session_type parameter, or null if no match was found.</returns> internal static string GetNameForSize(Protocol protocol, int hashSizeInBits) { Contract.Requires <ArgumentNullException>(protocol != null); DHSha match = diffieHellmanSessionTypes.FirstOrDefault(dhsha => dhsha.Algorithm.HashSize == hashSizeInBits); return(match != null?match.GetName(protocol) : null); }
/// <summary> /// Finds the hashing algorithm to use given an openid.session_type value. /// </summary> /// <param name="protocol">The protocol version of the message that named the session_type to be used.</param> /// <param name="sessionType">The value of the openid.session_type parameter.</param> /// <returns>The hashing algorithm to use.</returns> /// <exception cref="ProtocolException">Thrown if no match could be found for the given <paramref name="sessionType"/>.</exception> public static HashAlgorithm Lookup(Protocol protocol, string sessionType) { Requires.NotNull(protocol, "protocol"); 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)); ErrorUtilities.VerifyProtocol(match != null, OpenIdStrings.NoSessionTypeFound, sessionType, protocol.Version); return(match.Algorithm); }