**** Merged from MCS ****
[mono-project.git] / mcs / class / Mono.Security / Mono.Security.X509.Extensions / PrivateKeyUsagePeriodExtension.cs
blobc57b88b0ae5a02b15f3f85cf933b62589b6c214b
1 //
2 // PrivateKeyUsagePeriodExtension.cs: Handles X.509 PrivateKeyUsagePeriod extensions.
3 //
4 // Author:
5 // Sebastien Pouliot <sebastien@ximian.com>
6 //
7 // (C) 2004 Novell (http://www.novell.com)
8 //
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.
31 using System;
32 using System.Globalization;
33 using System.Text;
35 using Mono.Security;
36 using Mono.Security.X509;
38 namespace Mono.Security.X509.Extensions {
41 * id-ce-privateKeyUsagePeriod OBJECT IDENTIFIER ::= { id-ce 16 }
43 * PrivateKeyUsagePeriod ::= SEQUENCE {
44 * notBefore [0] GeneralizedTime OPTIONAL,
45 * notAfter [1] GeneralizedTime OPTIONAL
46 * }
48 public class PrivateKeyUsagePeriodExtension : X509Extension {
50 private DateTime notBefore;
51 private DateTime notAfter;
53 public PrivateKeyUsagePeriodExtension () : base ()
55 extnOid = "2.5.29.16";
58 public PrivateKeyUsagePeriodExtension (ASN1 asn1) : base (asn1)
62 public PrivateKeyUsagePeriodExtension (X509Extension extension) : base (extension)
66 protected override void Decode ()
68 ASN1 sequence = new ASN1 (extnValue.Value);
69 if (sequence.Tag != 0x30)
70 throw new ArgumentException ("Invalid PrivateKeyUsagePeriod extension");
71 for (int i=0; i < sequence.Count; i++) {
72 switch (sequence [i].Tag) {
73 case 0x80:
74 notBefore = ASN1Convert.ToDateTime (sequence [i]);
75 break;
76 case 0x81:
77 notAfter = ASN1Convert.ToDateTime (sequence [i]);
78 break;
79 default:
80 throw new ArgumentException ("Invalid PrivateKeyUsagePeriod extension");
85 public override string Name {
86 get { return "Private Key Usage Period"; }
89 public override string ToString ()
91 StringBuilder sb = new StringBuilder ();
92 if (notBefore != DateTime.MinValue) {
93 sb.Append ("Not Before: ");
94 sb.Append (notBefore.ToString (CultureInfo.CurrentUICulture));
95 sb.Append (Environment.NewLine);
97 if (notAfter != DateTime.MinValue) {
98 sb.Append ("Not After: ");
99 sb.Append (notAfter.ToString (CultureInfo.CurrentUICulture));
100 sb.Append (Environment.NewLine);
102 return sb.ToString ();