bssh 3.0.1

Parallel SSH command execution tool for cluster management
Documentation
// Copyright 2025 Lablup Inc. and Jeongkyu Shin
//
// 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.

//! SSH query options handler (-Q option)

use bssh::diagnosticln as eprintln;

pub fn is_supported_query(query: &str) -> bool {
    matches!(
        query.to_ascii_lowercase().as_str(),
        "cipher"
            | "cipher-auth"
            | "mac"
            | "kex"
            | "kexalgorithms"
            | "key"
            | "key-plain"
            | "key-cert"
            | "key-sig"
            | "protocol-version"
            | "help"
    )
}

/// Handle SSH query options (-Q)
pub fn handle_query(query: &str) {
    match query.to_ascii_lowercase().as_str() {
        "cipher" => {
            println!(
                "{}",
                bssh::ssh::tokio_client::supported_cipher_names().join("\n")
            );
        }
        "cipher-auth" => {
            println!("aes128-gcm@openssh.com\naes256-gcm@openssh.com");
            println!("chacha20-poly1305@openssh.com");
        }
        "mac" => {
            println!(
                "{}",
                bssh::ssh::tokio_client::supported_mac_names().join("\n")
            );
        }
        "kex" | "kexalgorithms" => {
            println!("curve25519-sha256\ncurve25519-sha256@libssh.org");
            println!("ecdh-sha2-nistp256\necdh-sha2-nistp384\necdh-sha2-nistp521");
        }
        "key" | "key-plain" | "key-cert" | "key-sig" => {
            println!("ssh-ed25519");
            println!("ecdsa-sha2-nistp256\necdsa-sha2-nistp384\necdsa-sha2-nistp521");
            println!("ssh-rsa");
        }
        "protocol-version" => {
            println!("2");
        }
        "help" => {
            println!("Available query options:");
            println!("  cipher            - Supported ciphers");
            println!("  cipher-auth       - Authenticated encryption ciphers");
            println!("  mac               - Supported MAC algorithms");
            println!("  kex               - Supported key exchange algorithms");
            println!("  key               - Supported key types");
            println!("  protocol-version  - SSH protocol version");
        }
        _ => {
            eprintln!("Unknown query option: {query}");
            eprintln!("Use 'bssh -Q help' to see available options");
            std::process::exit(1);
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn openssh_kex_algorithms_keyword_is_a_case_insensitive_query_alias() {
        for query in ["kex", "KexAlgorithms", "kexalgorithms"] {
            assert!(is_supported_query(query));
        }
    }
}