{"record":{"id":"bdb637f5bc460781","repo":"shadowsocks/shadowsocks-rust","slug":"method","errorCode":null,"errorMessage":"method","messagePattern":"method","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/service/genkey.rs","lineNumber":30,"sourceCode":"    app = app.arg(\n        Arg::new(\"ENCRYPT_METHOD\")\n            .short('m')\n            .long(\"encrypt-method\")\n            .num_args(1)\n            .action(ArgAction::Set)\n            .required(true)\n            .value_parser(PossibleValuesParser::new(available_ciphers()))\n            .help(\"Server's encryption method\"),\n    );\n\n    app\n}\n\n/// Program entrance `main`\npub fn main(matches: &ArgMatches) -> ExitCode {\n    let method = matches\n        .get_one::<String>(\"ENCRYPT_METHOD\")\n        .map(|x| x.parse::<CipherKind>().expect(\"method\"))\n        .expect(\"`method` is required\");\n\n    let key_len = method.key_len();\n    if key_len > 0 {\n        let mut key = vec![0u8; key_len];\n        rand::fill(key.as_mut_slice());\n\n        let encoded_key = base64::engine::general_purpose::STANDARD.encode(&key);\n        println!(\"{encoded_key}\");\n    }\n\n    ExitCode::SUCCESS\n}\n","sourceCodeStart":12,"sourceCodeEnd":44,"githubUrl":"https://github.com/shadowsocks/shadowsocks-rust/blob/8eb0f0a65b1d976ab6bed5787327ef86529b0435/src/service/genkey.rs#L12-L44","documentation":"The genkey subcommand parses the ENCRYPT_METHOD CLI argument into a CipherKind with FromStr; an unrecognized method name makes .parse fail and the .expect(\"method\") panics. This is a CLI-input validation guard: only cipher names implemented by the linked shadowsocks-crypto crate are accepted.","triggerScenarios":"Running `sslocal genkey <method>` (or ssserver genkey) with a method string that is not a valid CipherKind, e.g. a typo like `aes-256-gcm-12`, an old/removed cipher name, or a cipher requiring a disabled crypto feature.","commonSituations":"Typo in cipher name; copying a method name from a different tool (e.g. OpenSSL names); cipher compiled out because a crypto feature flag is off; lowercase/case mistakes.","solutions":["Use a supported cipher name exactly, e.g. aes-256-gcm, aes-128-gcm, chacha20-ietf-poly1305, 2022-blake3-aes-256-gcm.","Check the crate's cipher feature flags; recompile with the feature that enables the wanted cipher.","Pre-validate the method string against CipherKind::from_str before invoking to print a friendly error instead of panicking."],"exampleFix":"// before\nlet method: CipherKind = \"aes-256-cbc\".parse().expect(\"method\");\n\n// after\nlet method: CipherKind = match \"aes-256-cbc\".parse() {\n    Ok(m) => m,\n    Err(_) => { eprintln!(\"unsupported encrypt-method\\\"aes-256-cbc\\\"\"); return ExitCode::FAILURE; }\n};","handlingStrategy":"validation","validationCode":"fn validate_cipher_method(s: &str) -> Result<shadowsocks::config::CipherKind, String> {\n    s.parse::<shadowsocks::config::CipherKind>()\n        .map_err(|_| format!(\"unknown encrypt-method: {} (try aes-256-gcm, chacha20-ietf-poly1305)\", s))\n}","typeGuard":null,"tryCatchPattern":"let kind = s.parse::<CipherKind>().unwrap_or_else(|_| {\n    eprintln!(\"invalid encrypt-method: {}\", s);\n    std::process::exit(2);\n});","preventionTips":["Copy cipher names from the official supported-ciphers list rather than typing them.","Remember legacy stream ciphers (rc4-md5, aes-*-cfb) are removed; migrate to AEAD.","Verify the binary was built with the crypto feature enabling your chosen cipher."],"tags":["cli","rust","argument-parsing","panic"],"backgroundTag":"invalid-enum-value","analyzedSha":"8eb0f0a65b1d976ab6bed5787327ef86529b0435","analyzedAt":"2026-09-09T12:20:43.168Z","contentChangedAt":"2026-09-09T12:20:43.168Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}