<commit_before>﻿// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Management.Automation;

namespace StaticAnalysis.SignatureVerifier
{
    /// <summary>
    /// Data about the cmdlet signature
    /// </summary>
    [Serializable]
    public class CmdletSignatureMetadata
    {
        private IList<OutputMetadata> _outputTypes = new List<OutputMetadata>();
        private IList<ParameterMetadata> _parameters = new List<ParameterMetadata>();

        #region ShouldContinueVerbs
        private static readonly List<string> ShouldContinueVerbs = new List<string>
        {
             VerbsCommon.Clear,
             VerbsCommon.Copy,
             VerbsData.Edit,
             VerbsData.Export,
             VerbsData.Import,
             VerbsData.Initialize,
             VerbsCommon.Move,
             VerbsCommon.Redo,
             VerbsCommon.Remove,
             VerbsCommon.Rename,
             VerbsDiagnostic.Repair,
             VerbsCommon.Reset,
             VerbsCommon.Resize,
             VerbsLifecycle.Restart,
             VerbsData.Restore,
             VerbsCommon.Set,
             VerbsLifecycle.Stop,
             VerbsLifecycle.Suspend,
             VerbsLifecycle.Uninstall,
             VerbsData.Update,
             VerbsCommunications.Write
      };
        #endregion

        #region ShouldProcessVerbs
        private static readonly List<string> ShouldProcessVerbs = new List<string>
        {
            VerbsCommon.Close,
            VerbsData.Compress,
            VerbsLifecycle.Disable,
            VerbsCommunications.Disconnect,
            VerbsData.Dismount,
            VerbsCommon.Exit,
            VerbsCommon.Hide,
            VerbsCommon.Lock,
            VerbsData.Merge,
            VerbsData.Mount,
            VerbsData.Limit,
            VerbsCommon.New,
            VerbsCommon.Optimize,
            VerbsData.Publish,
            VerbsDiagnostic.Resolve,
            VerbsData.Save,
            VerbsData.Sync,
            VerbsCommon.Switch,
            VerbsCommon.Undo,
            VerbsCommon.Unlock,
            VerbsSecurity.Unprotect,
            VerbsData.Unpublish,
            VerbsLifecycle.Unregister,
            VerbsCommon.Add,
            VerbsLifecycle.Approve,
            VerbsData.Backup,
            VerbsData.Checkpoint,
            VerbsLifecycle.Complete,
            VerbsCommunications.Connect,
            VerbsData.Convert,
            VerbsData.ConvertFrom,
            VerbsData.ConvertTo,
            VerbsLifecycle.Deny,
            VerbsLifecycle.Enable,
            VerbsData.Group,
            VerbsCommon.Enter,
            VerbsData.Expand,
            VerbsCommon.Format,
            VerbsLifecycle.Install,
            VerbsLifecycle.Invoke,
            VerbsCommon.Open,
            VerbsCommon.Push,
            VerbsCommon.Pop,
            VerbsCommunications.Read,
            VerbsCommunications.Receive,
            VerbsLifecycle.Register,
            VerbsLifecycle.Request,
            VerbsLifecycle.Resume,
            VerbsCommunications.Send,
            VerbsCommon.Split,
            VerbsLifecycle.Start,
            VerbsLifecycle.Submit,
            VerbsSecurity.Block,
            VerbsSecurity.Grant,
            VerbsSecurity.Protect,
            VerbsSecurity.Revoke,
            VerbsSecurity.Unblock
        };
        #endregion

        #region ApprovedVerbs
        private List<string> ApprovedVerbs;

        private List<string> GetApprovedVerbs()
        {
            if (ApprovedVerbs == null)
            {
                ApprovedVerbs = new List<string>();

                PowerShell powershell = PowerShell.Create();
                powershell.AddCommand("Get-Verb");

                var cmdletResult = powershell.Invoke();

                foreach (PSObject result in cmdletResult)
                {
                    ApprovedVerbs.Add(result.Members["Verb"].Value.ToString());
                }
            }

            return ApprovedVerbs;
        }
        #endregion

        /// <summary>
        /// The name of the assembly containing cmdlet
        /// </summary>
        public string AssemblyName { get; set; }
<commit_msg>Fix issue with ApprovedVerbs list that was slowing down SignatureVerifier (#3357)<commit_after>﻿// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Management.Automation;

namespace StaticAnalysis.SignatureVerifier
{
    /// <summary>
    /// Data about the cmdlet signature
    /// </summary>
    [Serializable]
    public class CmdletSignatureMetadata
    {
        private IList<OutputMetadata> _outputTypes = new List<OutputMetadata>();
        private IList<ParameterMetadata> _parameters = new List<ParameterMetadata>();

        #region ShouldContinueVerbs
        private static readonly List<string> ShouldContinueVerbs = new List<string>
        {
             VerbsCommon.Clear,
             VerbsCommon.Copy,
             VerbsData.Edit,
             VerbsData.Export,
             VerbsData.Import,
             VerbsData.Initialize,
             VerbsCommon.Move,
             VerbsCommon.Redo,
             VerbsCommon.Remove,
             VerbsCommon.Rename,
             VerbsDiagnostic.Repair,
             VerbsCommon.Reset,
             VerbsCommon.Resize,
             VerbsLifecycle.Restart,
             VerbsData.Restore,
             VerbsCommon.Set,
             VerbsLifecycle.Stop,
             VerbsLifecycle.Suspend,
             VerbsLifecycle.Uninstall,
             VerbsData.Update,
             VerbsCommunications.Write
      };
        #endregion

        #region ShouldProcessVerbs
        private static readonly List<string> ShouldProcessVerbs = new List<string>
        {
            VerbsCommon.Close,
            VerbsData.Compress,
            VerbsLifecycle.Disable,
            VerbsCommunications.Disconnect,
            VerbsData.Dismount,
            VerbsCommon.Exit,
            VerbsCommon.Hide,
            VerbsCommon.Lock,
            VerbsData.Merge,
            VerbsData.Mount,
            VerbsData.Limit,
            VerbsCommon.New,
            VerbsCommon.Optimize,
            VerbsData.Publish,
            VerbsDiagnostic.Resolve,
            VerbsData.Save,
            VerbsData.Sync,
            VerbsCommon.Switch,
            VerbsCommon.Undo,
            VerbsCommon.Unlock,
            VerbsSecurity.Unprotect,
            VerbsData.Unpublish,
            VerbsLifecycle.Unregister,
            VerbsCommon.Add,
            VerbsLifecycle.Approve,
            VerbsData.Backup,
            VerbsData.Checkpoint,
            VerbsLifecycle.Complete,
            VerbsCommunications.Connect,
            VerbsData.Convert,
            VerbsData.ConvertFrom,
            VerbsData.ConvertTo,
            VerbsLifecycle.Deny,
            VerbsLifecycle.Enable,
            VerbsData.Group,
            VerbsCommon.Enter,
            VerbsData.Expand,
            VerbsCommon.Format,
            VerbsLifecycle.Install,
            VerbsLifecycle.Invoke,
            VerbsCommon.Open,
            VerbsCommon.Push,
            VerbsCommon.Pop,
            VerbsCommunications.Read,
            VerbsCommunications.Receive,
            VerbsLifecycle.Register,
            VerbsLifecycle.Request,
            VerbsLifecycle.Resume,
            VerbsCommunications.Send,
            VerbsCommon.Split,
            VerbsLifecycle.Start,
            VerbsLifecycle.Submit,
            VerbsSecurity.Block,
            VerbsSecurity.Grant,
            VerbsSecurity.Protect,
            VerbsSecurity.Revoke,
            VerbsSecurity.Unblock
        };
        #endregion

        #region ApprovedVerbs
        private static List<string> ApprovedVerbs;

        private static List<string> GetApprovedVerbs()
        {
            if (ApprovedVerbs == null)
            {
                ApprovedVerbs = new List<string>();

                PowerShell powershell = PowerShell.Create();
                powershell.AddCommand("Get-Verb");

                var cmdletResult = powershell.Invoke();

                foreach (PSObject result in cmdletResult)
                {
                    ApprovedVerbs.Add(result.Members["Verb"].Value.ToString());
                }
            }

            return ApprovedVerbs;
        }
        #endregion

        /// <summary>
        /// The name of the assembly containing cmdlet
        /// </summary>
        public string AssemblyName { get; set; }

{'fraction_non_alphanumeric': 0.10260782347041124, 'fraction_numerical': 0.0012036108324974925, 'mean_word_length': 1.5429737311910228, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6720452', 'n_tokens_mistral': 2474, 'n_tokens_neox': 2419, 'n_words': 518}