     - returns: a public key
     */
     func extractPublicKeyFromCert(cert: SecCertificate, policy: SecPolicy) -> SecKeyRef? {
-        var possibleTrust: Unmanaged<SecTrust>?
-        SecTrustCreateWithCertificates(cert,policy, &possibleTrust)
+        var possibleTrust: SecTrust?
+        SecTrustCreateWithCertificates(cert, policy, &possibleTrust)
         if let trust = possibleTrust {
-            let t = trust.takeRetainedValue()
             var result: SecTrustResultType = 0
-            SecTrustEvaluate(t,&result)
-            return SecTrustCopyPublicKey(t).takeRetainedValue()
+            SecTrustEvaluate(trust, &result)
+            return SecTrustCopyPublicKey(trust)
         }
         return nil
     }

        }
        var policy: SecPolicyRef
        if self.validatedDN {
            policy = SecPolicyCreateSSL(1, domain).takeRetainedValue()
        } else {
            policy = SecPolicyCreateBasicX509().takeRetainedValue()
        }
        SecTrustSetPolicies(trust,policy)
        if self.usePublicKeys {

            let serverCerts = certificateChainForTrust(trust)
            var collect = Array<SecCertificate>()
            for cert in certs {
                collect.append(SecCertificateCreateWithData(nil,cert)!)
            }
            SecTrustSetAnchorCertificates(trust,collect)
            var result: SecTrustResultType = 0
