2004-02-07 Tim Coleman <tim@timcoleman.com>
[mono.git] / mcs / class / System.Security / System.Security.Cryptography.Xml / KeyInfoRetrievalMethod.cs
1 //
2 // KeyInfoRetrievalMethod.cs - KeyInfoRetrievalMethod implementation for XML Signature
3 //
4 // Author:
5 //      Sebastien Pouliot (spouliot@motus.com)
6 //      Tim Coleman (tim@timcoleman.com)
7 //
8 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
9 // Copyright (C) Tim Coleman, 2004
10 //
11
12 using System.Xml;
13
14 namespace System.Security.Cryptography.Xml {
15
16         public class KeyInfoRetrievalMethod : KeyInfoClause {
17
18                 private string URI;
19
20 #if NET_1_2
21                 string type;
22 #endif
23
24                 public KeyInfoRetrievalMethod () {}
25
26                 public KeyInfoRetrievalMethod (string strUri) 
27                 {
28                         URI = strUri;
29                 }
30
31 #if NET_1_2
32                 public KeyInfoRetrievalMethod (string strUri, string strType)
33                         : this (strUri)
34                 {
35                         Type = strType;
36                 }
37
38                 public string Type {
39                         get { return type; }
40                         set { type = value; }
41                 }
42 #endif
43
44                 public string Uri {
45                         get { return URI; }
46                         set { URI = value; }
47                 }
48
49
50                 public override XmlElement GetXml () 
51                 {
52                         XmlDocument document = new XmlDocument ();
53                         XmlElement xel = document.CreateElement (XmlSignature.ElementNames.RetrievalMethod, XmlSignature.NamespaceURI);
54                         if (URI != null)
55                                 xel.SetAttribute (XmlSignature.AttributeNames.URI, URI);
56 #if NET_1_2
57                         if (Type != null)
58                                 xel.SetAttribute (XmlSignature.AttributeNames.Type, Type);
59 #endif
60                         return xel;
61                 }
62
63                 public override void LoadXml (XmlElement value) 
64                 {
65                         if (value == null)
66                                 throw new ArgumentNullException ();
67
68                         if ((value.LocalName != XmlSignature.ElementNames.RetrievalMethod) || (value.NamespaceURI != XmlSignature.NamespaceURI)) {
69                                 URI = ""; // not null - so we return URI="" as attribute !!!
70                         } else {
71                                 URI = value.Attributes [XmlSignature.AttributeNames.URI].Value;
72 #if NET_1_2
73                                 if (value.HasAttribute (XmlSignature.AttributeNames.Type))
74                                         Type = value.Attributes [XmlSignature.AttributeNames.Type].Value;
75 #endif
76                         }
77                 }
78         }
79 }