Beispiel #1
0
    public static void HashEachInput(string[] inputs, bool text, HashFunction hashFunction)
    {
        if (inputs == null)
        {
            DisplayMessage.Error(!text ? "Please specify a file/directory to hash." : "Please specify text to hash.");
            return;
        }
        foreach (string input in inputs)
        {
            try
            {
                switch (text)
                {
                case false when Directory.Exists(input):
                {
                    string[] filePaths  = Directory.GetFiles(input, searchPattern: "*", SearchOption.AllDirectories);
                    int      arrayIndex = Array.IndexOf(inputs, input);
                    if (arrayIndex > 0)
                    {
                        Console.WriteLine();
                    }
                    DisplayMessage.Message(input, "Hashing each file in the directory...");
                    HashEachInput(filePaths, text: false, hashFunction);
                    if (arrayIndex != inputs.Length - 1)
                    {
                        Console.WriteLine();
                    }
                    continue;
                }

                case false when !File.Exists(input):
                    DisplayMessage.NamedError(input, "This file/directory path doesn't exist.");
                    continue;
                }
                using Stream stream = !text ? new FileStream(input, FileMode.Open, FileAccess.Read, FileShare.Read, HashingAlgorithms.BufferSize, FileOptions.SequentialScan) : new MemoryStream(Encoding.UTF8.GetBytes(input));
                byte[] hash = HashingAlgorithms.GetHash(stream, hashFunction);
                DisplayMessage.Message(input, BitConverter.ToString(hash).Replace("-", "").ToLower());
            }
            catch (Exception ex) when(ex is IOException or UnauthorizedAccessException or ArgumentException or SecurityException or NotSupportedException)
            {
                DisplayMessage.NamedError(input, ex.GetType().ToString());
            }
        }
    }
Beispiel #2
0
 private void OnExecute()
 {
     Console.WriteLine();
     if (SHAKE256)
     {
         CommandLine.HashEachInput(Inputs, Text, HashFunction.SHAKE256);
     }
     else if (SHAKE128)
     {
         CommandLine.HashEachInput(Inputs, Text, HashFunction.SHAKE128);
     }
     else if (SHA3_512)
     {
         CommandLine.HashEachInput(Inputs, Text, HashFunction.SHA3_512);
     }
     else if (SHA3_384)
     {
         CommandLine.HashEachInput(Inputs, Text, HashFunction.SHA3_384);
     }
     else if (SHA3_256)
     {
         CommandLine.HashEachInput(Inputs, Text, HashFunction.SHA3_256);
     }
     else if (BLAKE3)
     {
         CommandLine.HashEachInput(Inputs, Text, HashFunction.BLAKE3);
     }
     else if (BLAKE2b512)
     {
         CommandLine.HashEachInput(Inputs, Text, HashFunction.BLAKE2b512);
     }
     else if (BLAKE2b256)
     {
         CommandLine.HashEachInput(Inputs, Text, HashFunction.BLAKE2b256);
     }
     else if (SHA512)
     {
         CommandLine.HashEachInput(Inputs, Text, HashFunction.SHA512);
     }
     else if (SHA384)
     {
         CommandLine.HashEachInput(Inputs, Text, HashFunction.SHA384);
     }
     else if (SHA256)
     {
         CommandLine.HashEachInput(Inputs, Text, HashFunction.SHA256);
     }
     else if (SHA1)
     {
         CommandLine.HashEachInput(Inputs, Text, HashFunction.SHA1);
     }
     else if (MD5)
     {
         CommandLine.HashEachInput(Inputs, Text, HashFunction.MD5);
     }
     else if (About)
     {
         CommandLine.DisplayAbout();
     }
     else
     {
         DisplayMessage.Error("Unknown command. Please specify -h|--help for a list of options and examples.");
     }
 }
Beispiel #3
0
        private void Init()
        {
            QueryParser parser = new QueryParser(query);

            root = parser.GetRoot();

            try
            {
                if (root != null)
                {
                    _messenger.Message("Valid Query");
                    parser.PrintNode(root, 0);
                    _messenger.Message("====================");

                    if (root.ChildNodes[0].Term.ToString() == "createDatabaseStmt")
                    {
                        CreateDatabase();
                    }
                    else if (root.ChildNodes[0].Term.ToString() == "dropDatabaseStmt")
                    {
                        DropDatabase();
                    }
                    else if (root.ChildNodes[0].Term.ToString() == "useDatabaseStmt")
                    {
                        ChangeDatabase();
                    }
                    else if (root.ChildNodes[0].Term.ToString() == "showTablesStmt")
                    {
                        ShowTables();
                    }
                    else if (root.ChildNodes[0].Term.ToString() == "showDatabasesStmt")
                    {
                        ShowDatabases();
                    }
                    else if (root.ChildNodes[0].Term.ToString() == "describeTableStmt")
                    {
                        DescribeTable();
                    }
                    else if (root.ChildNodes[0].Term.ToString() == "createTableStmt")
                    {
                        CreateTable();
                    }
                    else if (root.ChildNodes[0].Term.ToString() == "dropTableStmt")
                    {
                        DropTable();
                    }
                    else if (root.ChildNodes[0].Term.ToString() == "insertStmt")
                    {
                        InsertRecordIntoTable();
                    }
                    else if (root.ChildNodes[0].Term.ToString() == "updateStmt")
                    {
                        UpdateRecordOfTable();
                    }
                    else if (root.ChildNodes[0].Term.ToString() == "deleteStmt")
                    {
                        DeleteRecordsFromTable();
                    }
                    else if (root.ChildNodes[0].Term.ToString() == "selectStmt")
                    {
                        SelectRecordsFromTable();
                    }
                    else if (root.ChildNodes[0].Term.ToString() == "selectJoinStmt")
                    {
                        SelectRecordsFromMultipleTable();
                    }
                    else if (root.ChildNodes[0].Term.ToString() == "createIndexStmt")
                    {
                        CreateIndexOnColumn();
                    }
                    else if (root.ChildNodes[0].Term.ToString() == "dropIndexStmt")
                    {
                        DropIndexOnColumn();
                    }
                    else if (root.ChildNodes[0].Term.ToString() == "addPrimaryKeyStmt")
                    {
                        CreatePrimaryKey();
                    }
                    else if (root.ChildNodes[0].Term.ToString() == "dropPrimaryKeyStmt")
                    {
                        DropPrimaryKey();
                    }
                    else
                    {
                        _messenger.Error("Some error in alloting query");
                    }
                }
                else                 //invalid query
                {
                    _messenger.Error("Invalid Query");
                }
            }
            catch (Exception e)
            {
                _messenger.Error(e.Message);
            }
        }