diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2012-04-28 19:56:30 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2012-04-28 20:01:00 -0700 |
commit | ea4325d172d8a2bc925ed362f1c35560b8c1f13e (patch) | |
tree | a04960f4cddd7f2223df83b03e89300c5051434c /src/DotNetOpenAuth.Core/Messaging | |
parent | 01d8c73f818d30b20f86630d35d230b5168215d1 (diff) | |
download | DotNetOpenAuth-origin/jwt.zip DotNetOpenAuth-origin/jwt.tar.gz DotNetOpenAuth-origin/jwt.tar.bz2 |
Work toward support JWT access tokens.origin/jwt
Diffstat (limited to 'src/DotNetOpenAuth.Core/Messaging')
-rw-r--r-- | src/DotNetOpenAuth.Core/Messaging/DataBagFormatterBase.cs | 46 |
1 files changed, 39 insertions, 7 deletions
diff --git a/src/DotNetOpenAuth.Core/Messaging/DataBagFormatterBase.cs b/src/DotNetOpenAuth.Core/Messaging/DataBagFormatterBase.cs index c9ceb81..8b92d64 100644 --- a/src/DotNetOpenAuth.Core/Messaging/DataBagFormatterBase.cs +++ b/src/DotNetOpenAuth.Core/Messaging/DataBagFormatterBase.cs @@ -139,20 +139,40 @@ namespace DotNetOpenAuth.Messaging { this.compressed = compressed; } + protected bool Encrypted { + get { return this.encrypted; } + } + + protected bool Compressed { + get { return this.compressed; } + } + + protected RSACryptoServiceProvider SigningKey { + get { return this.asymmetricSigning; } + } + + protected RSACryptoServiceProvider EncryptingKey { + get { return this.asymmetricEncrypting; } + } + + protected ICryptoKeyStore CryptoKeyStore { + get { return this.cryptoKeyStore; } + } + + protected string CryptoKeyBucket { + get { return this.cryptoKeyBucket; } + } + /// <summary> /// Serializes the specified message, including compression, encryption, signing, and nonce handling where applicable. /// </summary> /// <param name="message">The message to serialize. Must not be null.</param> /// <returns>A non-null, non-empty value.</returns> [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "No apparent problem. False positive?")] - public string Serialize(T message) { + public virtual string Serialize(T message) { Requires.NotNull(message, "message"); - message.UtcCreationDate = DateTime.UtcNow; - - if (this.decodeOnceOnly != null) { - message.Nonce = MessagingUtilities.GetNonCryptoRandomData(NonceLength); - } + this.BeforeSerialize(message); byte[] encoded = this.SerializeCore(message); @@ -189,6 +209,14 @@ namespace DotNetOpenAuth.Messaging { } } + protected virtual void BeforeSerialize(T message) { + message.UtcCreationDate = DateTime.UtcNow; + + if (this.decodeOnceOnly != null) { + message.Nonce = MessagingUtilities.GetNonCryptoRandomData(NonceLength); + } + } + /// <summary> /// Deserializes a <see cref="DataBag"/>, including decompression, decryption, signature and nonce validation where applicable. /// </summary> @@ -197,7 +225,7 @@ namespace DotNetOpenAuth.Messaging { /// <param name="value">The serialized form of the <see cref="DataBag"/> to deserialize. Must not be null or empty.</param> /// <param name="messagePartName">The name of the parameter whose value is to be deserialized. Used for error message generation.</param> [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "No apparent problem. False positive?")] - public void Deserialize(T message, IProtocolMessage containingMessage, string value, string messagePartName) { + public virtual void Deserialize(T message, IProtocolMessage containingMessage, string value, string messagePartName) { Requires.NotNull(message, "message"); Requires.NotNull(containingMessage, "containingMessage"); Requires.NotNullOrEmpty(value, "value"); @@ -236,6 +264,10 @@ namespace DotNetOpenAuth.Messaging { this.DeserializeCore(message, data); message.Signature = signature; // TODO: we don't really need this any more, do we? + this.AfterDeserialize(message, containingMessage); + } + + protected virtual void AfterDeserialize(T message, IProtocolMessage containingMessage) { if (this.maximumAge.HasValue) { // Has message verification code expired? DateTime expirationDate = message.UtcCreationDate + this.maximumAge.Value; |