{"record":{"id":"c3d0944be8aca93f","repo":"tonhowtf/omniget","slug":"chave-hex","errorCode":null,"errorMessage":"chave hex: {}","messagePattern":"chave hex: (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/ctf/xor.rs","lineNumber":156,"sourceCode":"}\n\n#[derive(Debug, Clone, Serialize)]\npub struct XorResult {\n    pub candidates: Vec<XorCandidate>,\n    pub key_sizes: Vec<(usize, f64)>,\n}\n\npub fn run(opts: &XorOptions) -> anyhow::Result<XorResult> {\n    let data = if opts.input_hex {\n        hex::decode(opts.input.trim().replace([' ', '\\n', ':'], \"\"))\n            .map_err(|e| anyhow::anyhow!(\"hex inválido: {}\", e))?\n    } else {\n        opts.input.as_bytes().to_vec()\n    };\n    Ok(match opts.mode.as_str() {\n        \"apply\" => {\n            let key = if opts.key_hex {\n                hex::decode(opts.key.trim()).map_err(|e| anyhow::anyhow!(\"chave hex: {}\", e))?\n            } else {\n                opts.key.as_bytes().to_vec()\n            };\n            let out = xor(&data, &key);\n            XorResult {\n                candidates: vec![XorCandidate {\n                    key: opts.key.clone(),\n                    key_hex: hex::encode(&key),\n                    text: String::from_utf8_lossy(&out).to_string(),\n                    score: 0.0,\n                }],\n                key_sizes: vec![],\n            }\n        }\n        \"repeating\" => XorResult {\n            key_sizes: guess_key_sizes(&data, opts.max_key_size, 5),\n            candidates: break_repeating(&data, opts.max_key_size)\n                .into_iter()","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/ctf/xor.rs#L138-L174","documentation":"In ctf/xor 'apply' mode with opts.key_hex set to true, the key is decoded from hexadecimal. If opts.key is not valid hex (odd length or non-hex characters) hex::decode fails and the tool raises 'chave hex: <hex error>'.","triggerScenarios":"Calling run with mode = \"apply\", key_hex = true, and a key string that is not pure hex of even length — e.g. an ASCII passphrase passed while key_hex is enabled.","commonSituations":"Using a text key like \"secretkey\" with key_hex left true from a previous run; odd-length key from manual entry; hidden whitespace or '0x' prefix in the key field.","solutions":["Provide the key as valid even-length hex (e.g. \"deadbeef\"), or","Set key_hex = false to interpret opts.key as raw ASCII bytes","Strip '0x' prefixes and stray whitespace from the key before calling run"],"exampleFix":"// before\nlet opts = XorOptions { mode: \"apply\".into(), key_hex: true, key: \"secret\".into(), .. };\n// after\nlet opts = XorOptions { mode: \"apply\".into(), key_hex: true, key: \"736563726574\".into(), .. };","handlingStrategy":"validation","validationCode":"if opts.key_hex {\n    let k = opts.key.trim();\n    if k.len() % 2 != 0 || !k.chars().all(|c| c.is_ascii_hexdigit()) {\n        anyhow::bail!(\"key must be even-length hex, or set key_hex=false for ASCII\");\n    }\n}","typeGuard":"fn valid_hex_key(opts: &XorOptions) -> bool {\n    !opts.key_hex || (opts.key.trim().len() % 2 == 0\n        && opts.key.trim().chars().all(|c| c.is_ascii_hexdigit()))\n}","tryCatchPattern":null,"preventionTips":["Keep key_hex in sync with the key format you are actually providing","For text keys, always use key_hex = false (raw bytes)","Convert ASCII keys to hex explicitly in the caller when hex mode is required"],"tags":["hex","xor","ctf","rust","key"],"backgroundTag":"invalid-argument-format","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}