2 // Pkcs9SigningTimeTest.cs - NUnit tests for Pkcs9SigningTime
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using NUnit
.Framework
;
35 using System
.Collections
;
36 using System
.Security
.Cryptography
;
37 using System
.Security
.Cryptography
.Pkcs
;
39 namespace MonoTests
.System
.Security
.Cryptography
.Pkcs
{
42 public class Pkcs9SigningTimeTest
{
44 static string signingTimeOid
= "1.2.840.113549.1.9.5";
45 static string signingTimeName
= "Signing Time";
46 static DateTime mono10release
= new DateTime (632241648000000000);
49 public void Constructor_Empty ()
51 Pkcs9SigningTime st
= new Pkcs9SigningTime ();
52 Assert
.AreEqual (signingTimeName
, st
.Oid
.FriendlyName
, "Oid.FriendlyName");
53 Assert
.AreEqual (signingTimeOid
, st
.Oid
.Value
, "Oid.Value");
54 Assert
.AreEqual (15, st
.RawData
.Length
, "RawData.Length");
58 public void Constructor_DateTime_Now ()
60 Pkcs9SigningTime st
= new Pkcs9SigningTime (DateTime
.UtcNow
);
61 Assert
.AreEqual (signingTimeName
, st
.Oid
.FriendlyName
, "Oid.FriendlyName");
62 Assert
.AreEqual (signingTimeOid
, st
.Oid
.Value
, "Oid.Value");
63 Assert
.AreEqual (15, st
.RawData
.Length
, "RawData.Length");
67 [ExpectedException (typeof (ArgumentOutOfRangeException
))]
68 public void Constructor_DateTime_MinValue ()
70 Pkcs9SigningTime st
= new Pkcs9SigningTime (DateTime
.MinValue
);
74 [ExpectedException (typeof (CryptographicException
))]
75 public void Constructor_DateTime_MaxValue ()
77 Pkcs9SigningTime st
= new Pkcs9SigningTime (DateTime
.MaxValue
);
81 public void Constructor_DateTime ()
83 Pkcs9SigningTime st
= new Pkcs9SigningTime (mono10release
);
84 Assert
.AreEqual (signingTimeName
, st
.Oid
.FriendlyName
, "Oid.FriendlyName");
85 Assert
.AreEqual (signingTimeOid
, st
.Oid
.Value
, "Oid.Value");
86 Assert
.AreEqual (15, st
.RawData
.Length
, "RawData.Length");
87 Assert
.AreEqual ("17-0D-30-34-30-36-33-30-30-34-30-30-30-30-5A", BitConverter
.ToString (st
.RawData
), "RawData");
88 Assert
.AreEqual (mono10release
, st
.SigningTime
, "st.SigningTime");
92 public void Constructor_Bytes ()
94 byte[] date
= new byte [15] { 0x17, 0x0D, 0x30, 0x34, 0x30, 0x36, 0x33, 0x30, 0x30, 0x34, 0x30, 0x30, 0x30, 0x30, 0x5A }
;
95 Pkcs9SigningTime st
= new Pkcs9SigningTime (date
);
96 Assert
.AreEqual (signingTimeName
, st
.Oid
.FriendlyName
, "Oid.FriendlyName");
97 Assert
.AreEqual (signingTimeOid
, st
.Oid
.Value
, "Oid.Value");
98 Assert
.AreEqual (15, st
.RawData
.Length
, "RawData.Length");
99 Assert
.AreEqual ("17-0D-30-34-30-36-33-30-30-34-30-30-30-30-5A", BitConverter
.ToString (st
.RawData
), "RawData");
100 Assert
.AreEqual (mono10release
, st
.SigningTime
, "st.SigningTime");
104 [ExpectedException (typeof (ArgumentNullException
))]
105 public void Constructor_Bytes_Null ()
107 Pkcs9SigningTime st
= new Pkcs9SigningTime (null);
111 public void CopyFrom ()
113 Pkcs9SigningTime st1
= new Pkcs9SigningTime (mono10release
);
114 Pkcs9SigningTime st2
= new Pkcs9SigningTime (DateTime
.UtcNow
);
116 Assert
.AreEqual (st2
.Oid
.FriendlyName
, st1
.Oid
.FriendlyName
, "Oid.FriendlyName");
117 Assert
.AreEqual (st2
.Oid
.Value
, st1
.Oid
.Value
, "Oid.Value");
118 Assert
.AreEqual (BitConverter
.ToString (st2
.RawData
), BitConverter
.ToString (st1
.RawData
), "RawData");
119 // BUG - SigningTime isn't updated
120 Assert
.AreEqual (st2
.SigningTime
, st1
.SigningTime
, "SigningTime");
124 [ExpectedException (typeof (ArgumentNullException
))]
125 public void CopyFrom_Null ()
127 new Pkcs9SigningTime (mono10release
).CopyFrom (null);
131 public void CopyFrom_Bad ()
133 Pkcs9SigningTime st
= new Pkcs9SigningTime (mono10release
);
134 Pkcs9DocumentName dn
= new Pkcs9DocumentName ("Mono");
136 Assert
.AreEqual (dn
.Oid
.FriendlyName
, st
.Oid
.FriendlyName
, "Oid.FriendlyName");
137 Assert
.AreEqual (dn
.Oid
.Value
, st
.Oid
.Value
, "Oid.Value");
138 Assert
.AreEqual (BitConverter
.ToString (dn
.RawData
), BitConverter
.ToString (st
.RawData
), "RawData");
140 Assert
.AreEqual (mono10release
, st
.SigningTime
, "SigningTime");