summaryrefslogtreecommitdiffstats
path: root/src/DotNetOAuth/Messages/SignedMessageBase.cs
blob: 7361adf24b4b8c365c8cfdade96aeec3805808e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//-----------------------------------------------------------------------
// <copyright file="SignedMessageBase.cs" company="Andrew Arnott">
//     Copyright (c) Andrew Arnott. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace DotNetOAuth.Messages {
	using System;
	using DotNetOAuth.ChannelElements;
	using DotNetOAuth.Messaging;
	using DotNetOAuth.Messaging.Bindings;

	/// <summary>
	/// A base class for all signed OAuth messages.
	/// </summary>
	internal class SignedMessageBase : MessageBase, ITamperResistantOAuthMessage, IExpiringProtocolMessage, IReplayProtectedProtocolMessage {
		/// <summary>
		/// Initializes a new instance of the <see cref="SignedMessageBase"/> class.
		/// </summary>
		/// <param name="transport">A value indicating whether this message requires a direct or indirect transport.</param>
		internal SignedMessageBase(MessageTransport transport)
			: base(MessageProtection.All, transport) {
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="SignedMessageBase"/> class.
		/// </summary>
		/// <param name="transport">A value indicating whether this message requires a direct or indirect transport.</param>
		/// <param name="recipient">The URI that a directed message will be delivered to.</param>
		internal SignedMessageBase(MessageTransport transport, Uri recipient)
			: base(MessageProtection.All, transport, recipient) {
		}

		#region ITamperResistantOAuthMessage Members

		/// <summary>
		/// Gets or sets the message signature.
		/// </summary>
		[MessagePart("oauth_signature")]
		string ITamperResistantProtocolMessage.Signature { get; set; }

		/// <summary>
		/// Gets or sets the signature method used to sign the request.
		/// </summary>
		[MessagePart("oauth_signature_method")]
		string ITamperResistantOAuthMessage.SignatureMethod { get; set; }

		#endregion

		#region IExpiringProtocolMessage Members

		/// <summary>
		/// Gets or sets the OAuth timestamp of the message.
		/// </summary>
		[MessagePart("oauth_timestamp")]
		DateTime IExpiringProtocolMessage.UtcCreationDate { get; set; }

		#endregion

		#region IReplayProtectedProtocolMessage Members

		/// <summary>
		/// Gets or sets the message nonce used for replay detection.
		/// </summary>
		[MessagePart("oauth_nonce")]
		string IReplayProtectedProtocolMessage.Nonce { get; set; }

		#endregion

		/// <summary>
		/// Gets or sets the version of the protocol this message was created with.
		/// </summary>
		[MessagePart(Name = "oauth_version", IsRequired = false)]
		private string Version {
			get {
				return ((IProtocolMessage)this).ProtocolVersion.ToString();
			}

			set {
				if (value != this.Version) {
					throw new ArgumentOutOfRangeException("value");
				}
			}
		}
	}
}