{"record":{"id":"40dd1d4d5f7fc8bd","repo":"tinyhumansai/openhuman","slug":"secret-key-file-has-wrong-length-expected-key-le","errorCode":null,"errorMessage":"Secret key file has wrong length: expected {KEY_LEN} bytes, got {}","messagePattern":"Secret key file has wrong length: expected (.+?) bytes, got (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/openhuman/security/keyring/encrypted_store.rs","lineNumber":658,"sourceCode":"\n/// XOR cipher with repeating key. Same function for encrypt and decrypt.\nfn xor_cipher(data: &[u8], key: &[u8]) -> Vec<u8> {\n    if key.is_empty() {\n        return data.to_vec();\n    }\n    data.iter()\n        .enumerate()\n        .map(|(i, &b)| b ^ key[i % key.len()])\n        .collect()\n}\n\nfn generate_random_key() -> Zeroizing<Vec<u8>> {\n    Zeroizing::new(crypto::generate_random_bytes(KEY_LEN))\n}\n\nfn decode_key_hex(hex_key: &str) -> Result<Zeroizing<Vec<u8>>> {\n    let key = Zeroizing::new(hex_decode(hex_key).context(\"Secret key file is corrupt\")?);\n    anyhow::ensure!(\n        key.len() == KEY_LEN,\n        \"Secret key file has wrong length: expected {KEY_LEN} bytes, got {}\",\n        key.len()\n    );\n    Ok(key)\n}\n\nfn hex_encode(data: &[u8]) -> String {\n    crypto::hex_encode(data)\n}\n\n/// Build the `/grant` argument for `icacls` using a normalized username.\n/// Returns `None` when the username is empty or whitespace-only.\nfn build_windows_icacls_grant_arg(username: &str) -> Option<String> {\n    let normalized = username.trim();\n    if normalized.is_empty() {\n        return None;\n    }","sourceCodeStart":640,"sourceCodeEnd":676,"githubUrl":"https://github.com/tinyhumansai/openhuman/blob/749120085864ce16e0f273c7b86fac7740b39c5b/src/openhuman/security/keyring/encrypted_store.rs#L640-L676","documentation":"The master key file decoded from hex but is not exactly KEY_LEN bytes (32). The size assertion in `decode_key_hex` fires after successful hex decode — so the file is well-formed hex but wrong length, pointing at a hand-edited, truncated, or foreign key file rather than decode corruption.","triggerScenarios":"Thrown at src/openhuman/security/keyring/encrypted_store.rs:658 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Restore the original 32-byte key file from backup","Regenerate the key (secrets encrypted with the old key become unrecoverable) and re-enter secrets","Prevent manual edits to the key file; it is binary key material in hex"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"749120085864ce16e0f273c7b86fac7740b39c5b","analyzedAt":"2026-08-17T21:21:45.363Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}