Esempio n. 1
0
        static INativeObject [] QueryAsReference(CFDictionary query, out SecStatusCode result)
        {
            if (query == null)
            {
                result = SecStatusCode.Param;
                return(null);
            }

            IntPtr ptr;

            result = SecItem.SecItemCopyMatching(query.Handle, out ptr);
            if (result == SecStatusCode.Success && ptr != IntPtr.Zero)
            {
                var array = CFArray.ArrayFromHandle <INativeObject> (ptr, p => {
                    IntPtr cfType = CFType.GetTypeID(p);
                    if (cfType == SecCertificate.GetTypeID())
                    {
                        return(new SecCertificate(p, true));
                    }
                    if (cfType == SecKey.GetTypeID())
                    {
                        return(new SecKey(p, true));
                    }
                    if (cfType == SecIdentity.GetTypeID())
                    {
                        return(new SecIdentity(p, true));
                    }
                    throw new Exception(String.Format("Unexpected type: 0x{0:x}", cfType));
                });
                return(array);
            }
            return(null);
        }
Esempio n. 2
0
        public static INativeObject[] QueryAsReference(SecRecord query, int max, out SecStatusCode result)
        {
            if (query == null)
            {
                result = SecStatusCode.Param;
                return(null);
            }

            using (var copy = query.queryDict.MutableCopy()) {
                copy.SetValue(CFBoolean.True.Handle, SecItem.ReturnRef);
                SetLimit(copy, max);

                IntPtr ptr;
                result = SecItem.SecItemCopyMatching(copy.Handle, out ptr);
                if ((result == SecStatusCode.Success) && (ptr != IntPtr.Zero))
                {
                    var array = CFArray.ArrayFromHandle <INativeObject> (ptr, p => {
                        IntPtr cfType = CFType.GetTypeID(p);
                        if (cfType == SecCertificate.GetTypeID())
                        {
                            return(new SecCertificate(p, true));
                        }
                        else if (cfType == SecKey.GetTypeID())
                        {
                            return(new SecKey(p, true));
                        }
                        else if (cfType == SecIdentity.GetTypeID())
                        {
                            return(new SecIdentity(p, true));
                        }
                        else
                        {
                            throw new Exception(String.Format("Unexpected type: 0x{0:x}", cfType));
                        }
                    });
                    return(array);
                }
                return(null);
            }
        }