<commit_before>using System;
using System.IO;
using System.Linq;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;

namespace SuperSocket
{
    public class CertificateOptions
    {
        public X509Certificate Certificate { get; set; }


        /// <summary>
        /// Gets the certificate file path (pfx).
        /// </summary>
        public string FilePath { get; set; }

        /// <summary>
        /// Gets the password.
        /// </summary>
        public string Password { get; set; }

        /// <summary>
        /// Gets the the store where certificate locates.
        /// </summary>
        /// <value>
        /// The name of the store.
        /// </value>
        public string StoreName { get; set; }

        /// <summary>
        /// Gets the thumbprint.
        /// </summary>
        public string Thumbprint { get; set; }


        /// <summary>
        /// Gets the store location of the certificate.
        /// </summary>
        /// <value>
        /// The store location.
        /// </value>
        public StoreLocation StoreLocation { get; set; }


        /// <summary>
        /// Gets a value indicating whether [client certificate required].
        /// </summary>
        /// <value>
        /// <c>true</c> if [client certificate required]; otherwise, <c>false</c>.
        /// </value>
        public bool ClientCertificateRequired { get; set; }

        /// <summary>
        /// Gets a value that will be used to instantiate the X509Certificate2 object in the CertificateManager
        /// </summary>
        public X509KeyStorageFlags KeyStorageFlags { get; set; }


        public RemoteCertificateValidationCallback RemoteCertificateValidationCallback { get; set; }

        public void EnsureCertificate()
        {
            // The certificate is there already
            if (Certificate != null)
                return;            

            // load certificate from pfx file
            if (!string.IsNullOrEmpty(FilePath))
            {
                string filePath = FilePath;

                if (!Path.IsPathRooted(filePath))
                {
                    filePath = Path.Combine(AppContext.BaseDirectory, filePath);
                }

                Certificate = new X509Certificate2(filePath, Password, KeyStorageFlags);
            }
            else if (!string.IsNullOrEmpty(Thumbprint)) // load certificate from certificate store
            {
                var storeName = StoreName;
                if (string.IsNullOrEmpty(storeName))
                    storeName = "Root";

                var store = new X509Store((StoreName)Enum.Parse(typeof(StoreName), storeName), StoreLocation);

                store.Open(OpenFlags.ReadOnly);

                Certificate = store.Certificates.OfType<X509Certificate2>()
                    .FirstOrDefault(c => c.Thumbprint.Equals(Thumbprint, StringComparison.OrdinalIgnoreCase));

                store.Close();
            }
            else<commit_msg>set the default store location and default store name<commit_after>using System;
using System.IO;
using System.Linq;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;

namespace SuperSocket
{
    public class CertificateOptions
    {
        public X509Certificate Certificate { get; set; }


        /// <summary>
        /// Gets the certificate file path (pfx).
        /// </summary>
        public string FilePath { get; set; }

        /// <summary>
        /// Gets the password.
        /// </summary>
        public string Password { get; set; }

        /// <summary>
        /// Gets the the store where certificate locates.
        /// </summary>
        /// <value>
        /// The name of the store.
        /// </value>
        public string StoreName { get; set; } = "My";//The X.509 certificate store for personal certificates.

        /// <summary>
        /// Gets the thumbprint.
        /// </summary>
        public string Thumbprint { get; set; }


        /// <summary>
        /// Gets the store location of the certificate.
        /// </summary>
        /// <value>
        /// The store location.
        /// </value>
        public StoreLocation StoreLocation { get; set; } = StoreLocation.CurrentUser;//The X.509 certificate store used by the current user.


        /// <summary>
        /// Gets a value indicating whether [client certificate required].
        /// </summary>
        /// <value>
        /// <c>true</c> if [client certificate required]; otherwise, <c>false</c>.
        /// </value>
        public bool ClientCertificateRequired { get; set; }

        /// <summary>
        /// Gets a value that will be used to instantiate the X509Certificate2 object in the CertificateManager
        /// </summary>
        public X509KeyStorageFlags KeyStorageFlags { get; set; }


        public RemoteCertificateValidationCallback RemoteCertificateValidationCallback { get; set; }

        public void EnsureCertificate()
        {
            // The certificate is there already
            if (Certificate != null)
                return;            

            // load certificate from pfx file
            if (!string.IsNullOrEmpty(FilePath))
            {
                string filePath = FilePath;

                if (!Path.IsPathRooted(filePath))
                {
                    filePath = Path.Combine(AppContext.BaseDirectory, filePath);
                }

                Certificate = new X509Certificate2(filePath, Password, KeyStorageFlags);
            }
            else if (!string.IsNullOrEmpty(Thumbprint)) // load certificate from certificate store
            {
                var store = new X509Store((StoreName)Enum.Parse(typeof(StoreName), StoreName), StoreLocation);

                store.Open(OpenFlags.ReadOnly);

                Certificate = store.Certificates.OfType<X509Certificate2>()
                    .FirstOrDefault(c => c.Thumbprint.Equals(Thumbprint, StringComparison.OrdinalIgnoreCase));

                store.Close();
            }
            else
{'fraction_non_alphanumeric': 0.10737153176818257, 'fraction_numerical': 0.008865539320308652, 'mean_word_length': 1.670758439281017, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7313600', 'n_tokens_mistral': 1541, 'n_tokens_neox': 1434, 'n_words': 426}