~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/maccore/src/Security/Certificate.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// 
2
2
// Certificate.cs: Implements the managed SecCertificate wrapper.
3
3
//
4
 
// Authors: Miguel de Icaza
5
 
//     
 
4
// Authors: 
 
5
//      Miguel de Icaza
 
6
//  Sebastien Pouliot  <sebastien@xamarin.com>
 
7
//
6
8
// Copyright 2010 Novell, Inc
 
9
// Copyright 2012 Xamarin Inc.
7
10
//
8
11
// Permission is hereby granted, free of charge, to any person obtaining
9
12
// a copy of this software and associated documentation files (the
26
29
//
27
30
using System;
28
31
using System.Runtime.InteropServices;
 
32
using System.Security.Cryptography.X509Certificates;
29
33
using MonoMac.ObjCRuntime;
30
34
using MonoMac.CoreFoundation;
31
35
using MonoMac.Foundation;
44
48
                [Preserve (Conditional = true)]
45
49
                internal SecCertificate (IntPtr handle, bool owns)
46
50
                {
 
51
                        if (handle == IntPtr.Zero)
 
52
                                throw new Exception ("Invalid handle");
 
53
 
47
54
                        this.handle = handle;
48
55
                        if (!owns)
49
56
                                CFObject.CFRetain (handle);
60
67
                        if (data == null)
61
68
                                throw new ArgumentNullException ("data");
62
69
 
 
70
                        Initialize (data);
 
71
                }
 
72
 
 
73
                public SecCertificate (byte[] data)
 
74
                {
 
75
                        if (data == null)
 
76
                                throw new ArgumentNullException ("data");
 
77
 
 
78
                        using (NSData cert = NSData.FromArray (data)) {
 
79
                                Initialize (cert);
 
80
                        }
 
81
                }
 
82
 
 
83
                public SecCertificate (X509Certificate certificate)
 
84
                {
 
85
                        if (certificate == null)
 
86
                                throw new ArgumentNullException ("certificate");
 
87
 
 
88
                        using (NSData cert = NSData.FromArray (certificate.GetRawCertData ())) {
 
89
                                Initialize (cert);
 
90
                        }
 
91
                }
 
92
 
 
93
                public SecCertificate (X509Certificate2 certificate)
 
94
                {
 
95
                        if (certificate == null)
 
96
                                throw new ArgumentNullException ("certificate");
 
97
 
 
98
                        using (NSData cert = NSData.FromArray (certificate.RawData)) {
 
99
                                Initialize (cert);
 
100
                        }
 
101
                }
 
102
 
 
103
                void Initialize (NSData data)
 
104
                {
63
105
                        handle = SecCertificateCreateWithData (IntPtr.Zero, data.Handle);
64
106
                        if (handle == IntPtr.Zero)
65
107
                                throw new ArgumentException ("Not a valid DER-encoded X.509 certificate");
185
227
                internal IntPtr handle;
186
228
                
187
229
                // invoked by marshallers
188
 
                internal SecKey (IntPtr handle)
 
230
                public SecKey (IntPtr handle)
189
231
                        : this (handle, false)
190
232
                {
191
233
                }
192
234
                
193
235
                [Preserve (Conditional = true)]
194
 
                internal SecKey (IntPtr handle, bool owns)
 
236
                public SecKey (IntPtr handle, bool owns)
195
237
                {
196
238
                        this.handle = handle;
197
239
                        if (!owns)