2
2
// Policy.cs: Implements the managed SecPolicy wrapper.
4
// Authors: Miguel de Icaza
6
// Sebastien Pouliot <sebastien@xamarin.com>
6
8
// Copyright 2010 Novell, Inc
9
// Copyright 2012 Xamarin Inc.
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
34
37
public class SecPolicy : INativeObject, IDisposable {
37
internal SecPolicy (IntPtr handle)
40
internal SecPolicy (IntPtr handle)
41
: this (handle, false)
39
if (handle == IntPtr.Zero)
40
throw new Exception ("Invalid parameters to context creation");
46
45
[Preserve (Conditional=true)]
47
46
internal SecPolicy (IntPtr handle, bool owns)
48
if (handle == IntPtr.Zero)
49
throw new Exception ("Invalid handle");
53
CFObject.CFRetain (handle);
56
[DllImport (Constants.SecurityLibrary)]
57
extern static IntPtr /* SecPolicyRef */ SecPolicyCreateSSL (bool server, IntPtr /* CFStringRef */ hostname);
59
static public SecPolicy CreateSslPolicy (bool server, string hostName)
62
NSString host = hostName == null ? null : new NSString (hostName);
63
IntPtr handle = host == null ? IntPtr.Zero : host.Handle;
64
SecPolicy policy = new SecPolicy (SecPolicyCreateSSL (server, handle), true);
68
CFString host = hostName == null ? null : new CFString (hostName);
69
IntPtr handle = host == null ? IntPtr.Zero : host.Handle;
70
SecPolicy policy = new SecPolicy (SecPolicyCreateSSL (server, handle), true);
77
[DllImport (Constants.SecurityLibrary)]
78
extern static IntPtr /* SecPolicyRef */ SecPolicyCreateBasicX509 ();
80
static public SecPolicy CreateBasicX509Policy ()
82
return new SecPolicy (SecPolicyCreateBasicX509 (), true);
67
97
get { return handle; }
70
[DllImport (Constants.CoreFoundationLibrary)]
71
extern static void CFRelease (IntPtr handle);
73
[DllImport (Constants.CoreFoundationLibrary)]
74
extern static void CFRetain (IntPtr handle);
76
100
protected virtual void Dispose (bool disposing)
78
102
if (handle != IntPtr.Zero){
103
CFObject.CFRelease (handle);
80
104
handle = IntPtr.Zero;