2005-04-26 Sebastien Pouliot <sebastien@ximian.com>
[mono.git] / mcs / class / Mono.Security / Mono.Security.X509 / PKCS12.cs
index 37f7106b3659f3934f2745e4f7c1b5ce82742238..0df82b90c314fd6cb2b52bd9b18437f99fed17f7 100755 (executable)
 // See bouncycastle.txt for license.
 //
 
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
 using System;
 using System.Collections;
 using System.IO;
@@ -248,7 +269,7 @@ namespace Mono.Security.X509 {
 
                static private int recommendedIterationCount = 2000;
 
-               private int _version;
+               //private int _version;
                private byte[] _password;
                private ArrayList _keyBags;
                private X509CertificateCollection _certs;
@@ -270,7 +291,12 @@ namespace Mono.Security.X509 {
                        _safeBags = new ArrayList ();
                }
 
-               public PKCS12 (byte[] data) : this (data, null) {}
+               public PKCS12 (byte[] data)
+                       : this ()
+               {
+                       Password = null;
+                       Decode (data);
+               }
 
                /*
                 * PFX ::= SEQUENCE {
@@ -295,10 +321,22 @@ namespace Mono.Security.X509 {
                 *      bagAttributes SET OF PKCS12Attribute OPTIONAL
                 * }
                 */
-               public PKCS12 (byte[] data, string password) : this ()
+               public PKCS12 (byte[] data, string password)
+                       : this ()
                {
                        Password = password;
-
+                       Decode (data);
+               }
+#if NET_2_0
+               public PKCS12 (byte[] data, byte[] password)
+                       : this ()
+               {
+                       _password = password;
+                       Decode (data);
+               }
+#endif
+               private void Decode (byte[] data)
+               {
                        ASN1 pfx = new ASN1 (data);
                        if (pfx.Tag != 0x30)
                                throw new ArgumentException ("invalid data");
@@ -306,7 +344,7 @@ namespace Mono.Security.X509 {
                        ASN1 version = pfx [0];
                        if (version.Tag != 0x02)
                                throw new ArgumentException ("invalid PFX version");
-                       _version = version.Value [0];
+                       //_version = version.Value [0];
 
                        PKCS7.ContentInfo authSafe = new PKCS7.ContentInfo (pfx [1]);
                        if (authSafe.ContentType != PKCS7.Oid.data)