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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
//-----------------------------------------------------------------------
// <copyright file="DataBag.cs" company="Outercurve Foundation">
// Copyright (c) Outercurve Foundation. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.Messaging {
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Validation;
/// <summary>
/// A collection of message parts that will be serialized into a single string,
/// to be set into a larger message.
/// </summary>
public abstract class DataBag : IMessage {
/// <summary>
/// The default version for DataBags.
/// </summary>
private static readonly Version DefaultVersion = new Version(1, 0);
/// <summary>
/// The backing field for the <see cref="IMessage.Version"/> property.
/// </summary>
private Version version;
/// <summary>
/// A dictionary to contain extra message data.
/// </summary>
private Dictionary<string, string> extraData = new Dictionary<string, string>();
/// <summary>
/// Initializes a new instance of the <see cref="DataBag"/> class.
/// </summary>
protected DataBag()
: this(DefaultVersion) {
}
/// <summary>
/// Initializes a new instance of the <see cref="DataBag"/> class.
/// </summary>
/// <param name="version">The DataBag version.</param>
protected DataBag(Version version) {
Requires.NotNull(version, "version");
this.version = version;
}
#region IMessage Properties
/// <summary>
/// Gets the version of the protocol or extension this message is prepared to implement.
/// </summary>
/// <remarks>
/// Implementations of this interface should ensure that this property never returns null.
/// </remarks>
Version IMessage.Version {
get { return this.version; }
}
/// <summary>
/// Gets the extra, non-standard Protocol parameters included in the message.
/// </summary>
/// <value></value>
/// <remarks>
/// Implementations of this interface should ensure that this property never returns null.
/// </remarks>
public IDictionary<string, string> ExtraData {
get { return this.extraData; }
}
#endregion
/// <summary>
/// Gets or sets the nonce.
/// </summary>
/// <value>The nonce.</value>
[MessagePart]
internal byte[] Nonce { get; set; }
/// <summary>
/// Gets or sets the UTC creation date of this token.
/// </summary>
/// <value>The UTC creation date.</value>
[MessagePart("ts", IsRequired = true, Encoder = typeof(TimestampEncoder))]
internal DateTime UtcCreationDate { get; set; }
/// <summary>
/// Gets or sets the signature.
/// </summary>
/// <value>The signature.</value>
internal byte[] Signature { get; set; }
/// <summary>
/// Gets or sets the message that delivered this DataBag instance to this host.
/// </summary>
protected internal IProtocolMessage ContainingMessage { get; set; }
/// <summary>
/// Gets the type of this instance.
/// </summary>
/// <value>The type of the bag.</value>
/// <remarks>
/// This ensures that one token cannot be misused as another kind of token.
/// </remarks>
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Accessed by reflection")]
[MessagePart("t", IsRequired = true, AllowEmpty = false)]
protected virtual Type BagType {
get { return this.GetType(); }
}
#region IMessage Methods
/// <summary>
/// Checks the message state for conformity to the protocol specification
/// and throws an exception if the message is invalid.
/// </summary>
/// <remarks>
/// <para>Some messages have required fields, or combinations of fields that must relate to each other
/// in specialized ways. After deserializing a message, this method checks the state of the
/// message to see if it conforms to the protocol.</para>
/// <para>Note that this property should <i>not</i> check signatures or perform any state checks
/// outside this scope of this particular message.</para>
/// </remarks>
/// <exception cref="ProtocolException">Thrown if the message is invalid.</exception>
void IMessage.EnsureValidMessage() {
this.EnsureValidMessage();
}
#endregion
/// <summary>
/// Checks the message state for conformity to the protocol specification
/// and throws an exception if the message is invalid.
/// </summary>
/// <remarks>
/// <para>Some messages have required fields, or combinations of fields that must relate to each other
/// in specialized ways. After deserializing a message, this method checks the state of the
/// message to see if it conforms to the protocol.</para>
/// <para>Note that this property should <i>not</i> check signatures or perform any state checks
/// outside this scope of this particular message.</para>
/// </remarks>
/// <exception cref="ProtocolException">Thrown if the message is invalid.</exception>
protected virtual void EnsureValidMessage() {
}
}
}
|