2 // MonoBtlsX509NameList.cs
5 // Martin Baulig <martin.baulig@xamarin.com>
7 // Copyright (c) 2016 Xamarin Inc. (http://www.xamarin.com)
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30 using System.Runtime.InteropServices;
31 using System.Runtime.CompilerServices;
35 class MonoBtlsX509NameList : MonoBtlsObject
37 internal class BoringX509NameListHandle : MonoBtlsHandle
41 internal BoringX509NameListHandle (IntPtr handle, bool ownsHandle)
42 : base (handle, ownsHandle)
44 this.dontFree = !ownsHandle;
47 protected override bool ReleaseHandle ()
50 mono_btls_x509_name_list_free (handle);
55 [DllImport (BTLS_DYLIB)]
56 extern static IntPtr mono_btls_x509_name_list_new ();
58 [DllImport (BTLS_DYLIB)]
59 extern static int mono_btls_x509_name_list_get_count (IntPtr handle);
61 [DllImport (BTLS_DYLIB)]
62 extern static int mono_btls_x509_name_list_add (IntPtr handle, IntPtr name);
64 [DllImport (BTLS_DYLIB)]
65 extern static IntPtr mono_btls_x509_name_list_get_item (IntPtr handle, int index);
67 [DllImport (BTLS_DYLIB)]
68 extern static void mono_btls_x509_name_list_free (IntPtr handle);
70 new internal BoringX509NameListHandle Handle {
71 get { return (BoringX509NameListHandle)base.Handle; }
74 internal MonoBtlsX509NameList (BoringX509NameListHandle handle)
79 internal MonoBtlsX509NameList ()
80 : this (Create_internal ())
84 static BoringX509NameListHandle Create_internal ()
86 var handle = mono_btls_x509_name_list_new ();
87 if (handle == IntPtr.Zero)
88 throw new MonoBtlsException ();
89 return new BoringX509NameListHandle (handle, true);
92 public int GetCount ()
95 return mono_btls_x509_name_list_get_count (
96 Handle.DangerousGetHandle ());
99 public MonoBtlsX509Name GetItem (int index)
102 if (index < 0 || index >= GetCount ())
103 throw new ArgumentOutOfRangeException ();
104 var ptr = mono_btls_x509_name_list_get_item (
105 Handle.DangerousGetHandle (), index);
106 if (ptr == IntPtr.Zero)
108 return new MonoBtlsX509Name (
109 new MonoBtlsX509Name.BoringX509NameHandle (ptr, true));
112 public void Add (MonoBtlsX509Name name)
115 mono_btls_x509_name_list_add (
116 Handle.DangerousGetHandle (),
117 name.Handle.DangerousGetHandle ());