* FileSystemInfo.cs: corrected COM visibility of UTC properties
[mono.git] / mcs / class / Mono.Security / Mono.Security.X509.Extensions / PrivateKeyUsagePeriodExtension.cs
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 //
9
10 using System;
11 using System.Text;
12
13 using Mono.Security;
14 using Mono.Security.X509;
15
16 namespace Mono.Security.X509.Extensions {
17
18         /*
19          * id-ce-privateKeyUsagePeriod OBJECT IDENTIFIER ::=  { id-ce 16 }
20          * 
21          * PrivateKeyUsagePeriod ::= SEQUENCE {
22          *    notBefore       [0]     GeneralizedTime OPTIONAL,
23          *    notAfter        [1]     GeneralizedTime OPTIONAL 
24          * }
25          */
26         public class PrivateKeyUsagePeriodExtension : X509Extension {
27
28                 private DateTime notBefore;
29                 private DateTime notAfter;
30
31                 public PrivateKeyUsagePeriodExtension () : base () 
32                 {
33                         extnOid = "2.5.29.16";
34                 }
35
36                 public PrivateKeyUsagePeriodExtension (ASN1 asn1) : base (asn1) {}
37
38                 public PrivateKeyUsagePeriodExtension (X509Extension extension) : base (extension) {}
39
40                 protected override void Decode () 
41                 {
42                         ASN1 sequence = new ASN1 (extnValue.Value);
43                         if (sequence.Tag != 0x30)
44                                 throw new ArgumentException ("Invalid PrivateKeyUsagePeriod extension");
45                         for (int i=0; i < sequence.Count; i++) {
46                                 switch (sequence [i].Tag) {
47                                         case 0x80:
48                                                 notBefore = ASN1Convert.ToDateTime (sequence [i]);
49                                                 break;
50                                         case 0x81:
51                                                 notAfter = ASN1Convert.ToDateTime (sequence [i]);
52                                                 break;
53                                         default:
54                                                 throw new ArgumentException ("Invalid PrivateKeyUsagePeriod extension");
55                                 }
56                         }
57                 }
58
59                 public override string Name {
60                         get { return "Private Key Usage Period"; }
61                 }
62
63                 public override string ToString () 
64                 {
65                         StringBuilder sb = new StringBuilder ();
66                         if (notBefore != DateTime.MinValue) {
67                                 sb.Append ("Not Before: ");
68                                 sb.Append (notBefore.ToString ());
69                                 sb.Append (Environment.NewLine);
70                         }
71                         if (notAfter != DateTime.MinValue) {
72                                 sb.Append ("Not After: ");
73                                 sb.Append (notAfter.ToString ());
74                                 sb.Append (Environment.NewLine);
75                         }
76                         return sb.ToString ();
77                 }
78         }
79 }