#region Native Methods
		[DllImport("gmime")]
		static extern int g_mime_certificate_list_length (IntPtr list);
		
		[DllImport("gmime")]
		static extern void g_mime_certificate_list_clear (IntPtr list);
		
		[DllImport("gmime")]
		static extern int g_mime_certificate_list_add (IntPtr list, IntPtr ia);
		
		[DllImport("gmime")]
		static extern void g_mime_certificate_list_insert (IntPtr list, int index, IntPtr ia);
		
		[DllImport("gmime")]
		static extern bool g_mime_certificate_list_remove (IntPtr list, IntPtr ia);
		
		[DllImport("gmime")]
		static extern bool g_mime_certificate_list_remove_at (IntPtr list, int index);
		
		[DllImport("gmime")]
		static extern bool g_mime_certificate_list_contains (IntPtr list, IntPtr ia);
		
		[DllImport("gmime")]
		static extern int g_mime_certificate_list_index_of (IntPtr list, IntPtr ia);
		
		[DllImport("gmime")]
		static extern IntPtr g_mime_certificate_list_get_certificate (IntPtr list, int index);
		
		[DllImport("gmime")]
		static extern void g_mime_certificate_list_set_certificate (IntPtr list, int index, IntPtr ia);
#endregion
		
		Exception CannotAdd (object value)
		{
			if (value == null)
				return new ArgumentNullException ("value");
			
			string message = String.Format ("Cannot add objects of type '{0}' to a CertificateCollection.",
							value.GetType ().ToString ());
			
			return new InvalidOperationException (message);
		}
		
		Exception CannotInsert (object value)
		{
			if (value == null)
				return new ArgumentNullException ("value");
			
			string message = String.Format ("Cannot insert objects of type '{0}' into a CertificateCollection.",
							value.GetType ().ToString ());
			
			return new InvalidOperationException (message);
		}
		
		Exception CannotRemove (object value)
		{
			if (value == null)
				return new ArgumentNullException ("value");
			
			string  message = String.Format ("Cannot remove objects of type '{0}' from a CertificateCollection.",
							 value.GetType ().ToString ());
			
			return new InvalidOperationException (message);
		}
		
		Exception CannotSet (object value)
		{
			if (value == null)
				return new ArgumentNullException ("value");
			
			string message = String.Format ("Cannot set objects of type '{0}' on an CertificateCollection.",
							value.GetType ().ToString ());
			
			return new InvalidOperationException (message);
		}
		
		public int Count {
			get { return g_mime_certificate_list_length (Handle); }
		}
		
		public bool IsFixedSize {
			get { return false; }
		}
		
		public bool IsReadOnly {
			get { return false; }
		}
		
		public bool IsSynchronized {
			get { return false; }
		}
		
		public object SyncRoot {
			get { return this; }
		}
		
		public int Add (Certificate cert)
		{
			if (cert == null)
				throw CannotAdd (cert);
			
			return g_mime_certificate_list_add (Handle, cert.Handle);
		}
		
		int IList.Add (object value)
		{
			Certificate cert = value as Certificate;
			
			if (cert == null)
				throw CannotAdd (value);
			
			return Add (cert);
		}
		
		public void Clear ()
		{
			g_mime_certificate_list_clear (Handle);
		}
		
		public bool Contains (Certificate cert)
		{
			if (cert == null)
				return false;
			
			return g_mime_certificate_list_contains (Handle, cert.Handle);
		}
		
		bool IList.Contains (object value)
		{
			return Contains (value as Certificate);
		}
		
		public void CopyTo (Array array, int index)
		{
			if (array == null)
				throw new ArgumentNullException ("array");
			
			if (index < 0)
				throw new ArgumentOutOfRangeException ("index");
			
			int n = Count;
			
			for (int i = 0; i < n; i++)
				array.SetValue (((IList) this)[i], index + i);
		}
		
		public IEnumerator GetEnumerator ()
		{
			return new CertificateCollectionIterator (this);
		}
		
		public int IndexOf (Certificate cert)
		{
			if (cert == null)
				return -1;
			
			return g_mime_certificate_list_index_of (Handle, cert.Handle);
		}
		
		int IList.IndexOf (object value)
		{
			return IndexOf (value as Certificate);
		}
		
		public void Insert (int index, Certificate cert)
		{
			if (cert == null)
				throw CannotInsert (cert);
			
			if (index < 0)
				throw new ArgumentOutOfRangeException ("index");
			
			g_mime_certificate_list_insert (Handle, index, cert.Handle);
		}
		
		void IList.Insert (int index, object value)
		{
			Certificate cert = value as Certificate;
			
			if (cert == null)
				throw CannotInsert (value);
			
			Insert (index, cert);
		}
		
		public void Remove (Certificate cert)
		{
			if (cert == null)
				throw CannotRemove (cert);
			
			g_mime_certificate_list_remove (Handle, cert.Handle);
		}
		
		void IList.Remove (object value)
		{
			Certificate cert = value as Certificate;
			
			if (cert == null)
				throw CannotRemove (value);
			
			Remove (cert);
		}
		
		public void RemoveAt (int index)
		{
			if (index < 0 || index >= Count)
				throw new ArgumentOutOfRangeException ("index");
			
			g_mime_certificate_list_remove_at (Handle, index);
		}
		
		public Certificate this[int index] {
			get {
				IntPtr raw = g_mime_certificate_list_get_certificate (Handle, index);
				
				if (raw == IntPtr.Zero)
					return null;
				
				return GLib.Object.GetObject (raw) as Certificate;
			}
			
			set {
				if (value == null)
					throw CannotSet (value);
				
				g_mime_certificate_list_set_certificate (Handle, index, value.Handle);
			}
		}
		
		object IList.this[int index] {
			get {
				return this[index];
			}
			
			set {
				this[index] = value as Certificate;
			}
		}
		
		internal class CertificateCollectionIterator : IEnumerator {
			CertificateCollection list;
			int index = -1;
			
			public CertificateCollectionIterator (CertificateCollection list)
			{
				this.list = list;
			}
			
			public object Current {
				get { return list[index]; }
			}
			
			public void Reset ()
			{
				index = -1;
			}
			
			public bool MoveNext ()
			{
				index++;
				
				return index < list.Count;
			}
		}
