//----------------------------------------------------------------------- // // Copyright (c) Outercurve Foundation. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOpenAuth.OpenId { using System; using System.Collections.Generic; using System.Diagnostics.Contracts; using System.Linq; using DotNetOpenAuth.Messaging; using Validation; /// /// Wraps an existing Identifier and prevents it from performing discovery. /// [Pure] internal class NoDiscoveryIdentifier : Identifier { /// /// The wrapped identifier. /// private readonly Identifier wrappedIdentifier; /// /// Initializes a new instance of the class. /// /// The ordinary Identifier whose discovery is being masked. /// Whether this Identifier should claim to be SSL-secure, although no discovery will never generate service endpoints anyway. internal NoDiscoveryIdentifier(Identifier wrappedIdentifier, bool claimSsl) : base(wrappedIdentifier.OriginalString, claimSsl) { Requires.NotNull(wrappedIdentifier, "wrappedIdentifier"); this.wrappedIdentifier = wrappedIdentifier; } /// /// Returns a that represents the current . /// /// /// A that represents the current . /// public override string ToString() { return this.wrappedIdentifier.ToString(); } /// /// Tests equality between two s. /// /// The to compare with the current . /// /// true if the specified is equal to the current ; otherwise, false. /// /// /// The parameter is null. /// public override bool Equals(object obj) { return this.wrappedIdentifier.Equals(obj); } /// /// Gets the hash code for an for storage in a hashtable. /// /// /// A hash code for the current . /// public override int GetHashCode() { return this.wrappedIdentifier.GetHashCode(); } /// /// Returns an that has no URI fragment. /// Quietly returns the original if it is not /// a or no fragment exists. /// /// /// A new instance if there was a /// fragment to remove, otherwise this same instance.. /// internal override Identifier TrimFragment() { return new NoDiscoveryIdentifier(this.wrappedIdentifier.TrimFragment(), IsDiscoverySecureEndToEnd); } /// /// Converts a given identifier to its secure equivalent. /// UriIdentifiers originally created with an implied HTTP scheme change to HTTPS. /// Discovery is made to require SSL for the entire resolution process. /// /// The newly created secure identifier. /// If the conversion fails, retains /// this identifiers identity, but will never discover any endpoints. /// /// True if the secure conversion was successful. /// False if the Identifier was originally created with an explicit HTTP scheme. /// internal override bool TryRequireSsl(out Identifier secureIdentifier) { return this.wrappedIdentifier.TryRequireSsl(out secureIdentifier); } } }