//----------------------------------------------------------------------- // // Copyright (c) Outercurve Foundation. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOpenAuth.Messaging.Bindings { using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text; using DotNetOpenAuth.Messaging; using Validation; /// /// A cryptographic key and metadata concerning it. /// public class CryptoKey { /// /// Backing field for the property. /// private readonly byte[] key; /// /// Backing field for the property. /// private readonly DateTime expiresUtc; /// /// Initializes a new instance of the class. /// /// The cryptographic key. /// The expires UTC. public CryptoKey(byte[] key, DateTime expiresUtc) { Requires.NotNull(key, "key"); Requires.That(expiresUtc.Kind == DateTimeKind.Utc, "expiresUtc", "Time must be expressed in UTC."); this.key = key; this.expiresUtc = expiresUtc; } /// /// Gets the key. /// [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "It's a buffer")] public byte[] Key { get { return this.key; } } /// /// Gets the expiration date of this key (UTC time). /// public DateTime ExpiresUtc { get { return this.expiresUtc; } } /// /// Determines whether the specified is equal to this instance. /// /// The to compare with this instance. /// /// true if the specified is equal to this instance; otherwise, false. /// /// /// The parameter is null. /// public override bool Equals(object obj) { var other = obj as CryptoKey; if (other == null) { return false; } return this.ExpiresUtc == other.ExpiresUtc && MessagingUtilities.AreEquivalent(this.Key, other.Key); } /// /// Returns a hash code for this instance. /// /// /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// public override int GetHashCode() { return this.ExpiresUtc.GetHashCode(); } } }