internal static unsafe SecurityCredentials CreateFromNative(NativeTypes.FABRIC_SECURITY_CREDENTIALS *nativeCredentials)
        {
            SecurityCredentials managedCredentials = null;

            switch (nativeCredentials->Kind)
            {
            case NativeTypes.FABRIC_SECURITY_CREDENTIAL_KIND.FABRIC_SECURITY_CREDENTIAL_KIND_CLAIMS:
                managedCredentials = ClaimsCredentials.CreateFromNative((NativeTypes.FABRIC_CLAIMS_CREDENTIALS *)nativeCredentials->Value);
                break;

            case NativeTypes.FABRIC_SECURITY_CREDENTIAL_KIND.FABRIC_SECURITY_CREDENTIAL_KIND_WINDOWS:
                managedCredentials = WindowsCredentials.CreateFromNative((NativeTypes.FABRIC_WINDOWS_CREDENTIALS *)nativeCredentials->Value);
                break;

            case NativeTypes.FABRIC_SECURITY_CREDENTIAL_KIND.FABRIC_SECURITY_CREDENTIAL_KIND_X509:
                managedCredentials = X509Credentials.CreateFromNative((NativeTypes.FABRIC_X509_CREDENTIALS *)nativeCredentials->Value);
                break;

            case NativeTypes.FABRIC_SECURITY_CREDENTIAL_KIND.FABRIC_SECURITY_CREDENTIAL_KIND_NONE:
                managedCredentials = NoneSecurityCredentials.CreateFromNative();
                break;

            default:
                AppTrace.TraceSource.WriteError("SecurityCredentials.FromNative", "Unknown credential type: {0}", nativeCredentials->Kind);
                ReleaseAssert.Failfast("Unknown credential type: {0}", nativeCredentials->Kind);
                break;
            }

            return(managedCredentials);
        }
        internal static unsafe ClaimsCredentials CreateFromNative(NativeTypes.FABRIC_CLAIMS_CREDENTIALS *nativeCredentials)
        {
            ClaimsCredentials managedCredentials = new ClaimsCredentials();

            managedCredentials.LocalClaims = NativeTypes.FromNativeString(nativeCredentials->LocalClaims);

            managedCredentials.ProtectionLevel = CreateFromNative(nativeCredentials->ProtectionLevel);

            var serverCommonNames = new ItemList <string>();

            for (int i = 0; i < nativeCredentials->ServerCommonNameCount; i++)
            {
                IntPtr location = nativeCredentials->ServerCommonNames + (i * IntPtr.Size);
                IntPtr value    = *((IntPtr *)location);
                serverCommonNames.Add(NativeTypes.FromNativeString(value));
            }
            managedCredentials.ServerCommonNames = serverCommonNames;

            var issuerThumbprints = new ItemList <string>();

            for (int i = 0; i < nativeCredentials->IssuerThumbprintCount; i++)
            {
                IntPtr location = nativeCredentials->IssuerThumbprints + (i * IntPtr.Size);
                IntPtr value    = *((IntPtr *)location);
                issuerThumbprints.Add(NativeTypes.FromNativeString(value));
            }
            managedCredentials.IssuerThumbprints = issuerThumbprints;

            if (nativeCredentials->Reserved != IntPtr.Zero)
            {
                var ex1 = (NativeTypes.FABRIC_CLAIMS_CREDENTIALS_EX1 *)nativeCredentials->Reserved;

                var serverThumbprints = new ItemList <string>();
                for (int i = 0; i < ex1->ServerThumbprintCount; i++)
                {
                    IntPtr location = ex1->ServerThumbprints + (i * IntPtr.Size);
                    IntPtr value    = *((IntPtr *)location);
                    serverThumbprints.Add(NativeTypes.FromNativeString(value));
                }
                managedCredentials.ServerThumbprints = serverThumbprints;
            }

            return(managedCredentials);
        }
 public NativeClaimsCredentialConverter(ClaimsCredentials securityCredentials)
 {
     this.claimsCredentials = securityCredentials;
 }