/// <summary>
 /// Get an authentication package by name.
 /// </summary>
 /// <param name="package">The name of the package.</param>
 /// <returns>The authentication package.</returns>
 public static AuthenticationPackage FromName(string package)
 {
     SecurityNativeMethods.QuerySecurityPackageInfo(package, out IntPtr package_info).CheckResult();
     try
     {
         return(new AuthenticationPackage((SecPkgInfo)Marshal.PtrToStructure(package_info, typeof(SecPkgInfo))));
     }
     finally
     {
         SecurityNativeMethods.FreeContextBuffer(package_info);
     }
 }
        /// <summary>
        /// Get authentication packages.
        /// </summary>
        /// <returns>The list of authentication packages.</returns>
        public static IEnumerable <AuthenticationPackage> Get()
        {
            List <AuthenticationPackage> packages = new List <AuthenticationPackage>();

            if (SecurityNativeMethods.EnumerateSecurityPackages(out int count,
                                                                out IntPtr ppPackageInfo) == SecStatusCode.Success)
            {
                try
                {
                    int size = Marshal.SizeOf(typeof(SecPkgInfo));
                    for (int i = 0; i < count; ++i)
                    {
                        SecPkgInfo pkg = (SecPkgInfo)Marshal.PtrToStructure(ppPackageInfo + i * size, typeof(SecPkgInfo));
                        packages.Add(new AuthenticationPackage(pkg));
                    }
                }
                finally
                {
                    SecurityNativeMethods.FreeContextBuffer(ppPackageInfo);
                }
            }
            return(packages.AsReadOnly());
        }