Add MIT license to System.Security.DLL
[mono.git] / mcs / class / System.Security / System.Security.Cryptography.Pkcs / Pkcs7Signer.cs
1 //
2 // Pkcs7Signer.cs - System.Security.Cryptography.Pkcs.Pkcs7Signer
3 //
4 // Author:
5 //      Sebastien Pouliot (spouliot@motus.com)
6 //
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 //
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 #if NET_2_0
32
33 using System;
34 using System.Security.Cryptography.X509Certificates;
35
36 namespace System.Security.Cryptography.Pkcs {
37
38         public sealed class Pkcs7Signer {
39
40                 private SubjectIdentifierType _signer;
41                 private X509CertificateEx _certificate;
42                 private Oid _digest;
43                 private X509IncludeOption _options;
44                 private Pkcs9AttributeCollection _auth;
45                 private Pkcs9AttributeCollection _unauth;
46
47                 // constructors
48
49                 public Pkcs7Signer () 
50                 {
51                         _signer = SubjectIdentifierType.IssuerAndSerialNumber;
52                         _digest = new Oid ("1.3.14.3.2.26");
53                         _options = X509IncludeOption.ExcludeRoot;
54                         _auth = new Pkcs9AttributeCollection ();
55                         _unauth = new Pkcs9AttributeCollection ();
56                 }
57
58                 public Pkcs7Signer (SubjectIdentifierType signerIdentifierType) : this ()
59                 {
60                         if (signerIdentifierType == SubjectIdentifierType.Unknown)
61                                 _signer = SubjectIdentifierType.IssuerAndSerialNumber;
62                         else
63                                 _signer = signerIdentifierType;
64                 }
65
66                 public Pkcs7Signer (SubjectIdentifierType signerIdentifierType, X509CertificateEx certificate) 
67                         : this (signerIdentifierType)
68                 {
69 // FIXME: compatibility with fx 1.2.3400.0
70 //                      if (certificate == null)
71 //                              throw new ArgumentNullException ("certificate");
72                         _certificate = certificate;
73                 }
74
75                 public Pkcs7Signer (X509CertificateEx certificate) : this ()
76                 {
77 // FIXME: compatibility with fx 1.2.3400.0
78 //                      if (certificate == null)
79 //                              throw new ArgumentNullException ("certificate");
80                         _certificate = certificate;
81                 }
82
83                 // properties
84
85                 public Pkcs9AttributeCollection AuthenticatedAttributes {
86                         get { return _auth; }
87                 }
88
89                 public X509CertificateEx Certificate {
90                         get { return _certificate; }
91                         set { _certificate = value; }
92                 }
93
94                 public Oid DigestAlgorithm {
95                         get { return _digest; }
96                         set { _digest = value; }
97                 } 
98
99                 public X509IncludeOption IncludeOption {
100                         get { return _options; }
101                         set { _options = value; }
102                 } 
103
104                 public SubjectIdentifierType SignerIdentifierType {
105                         get { return _signer; }
106                         set { 
107                                 if (value == SubjectIdentifierType.Unknown)
108                                         throw new ArgumentException ("value");
109
110                                 _signer = value;
111                         }
112                 }
113
114                 public Pkcs9AttributeCollection UnauthenticatedAttributes {
115                         get { return _unauth; }
116                 }
117         }
118 }
119
120 #endif