{"record":{"id":"a1be64d4ac65b164","repo":"astrid-runtime/astrid","slug":"gateway-key-at-has-wrong-length-bytes-expe","errorCode":null,"errorMessage":"gateway key at {} has wrong length ({} bytes, expected 32) — remove the file to regenerate","messagePattern":"gateway key at (.+?) has wrong length \\((.+?) bytes, expected 32\\) — remove the file to regenerate","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-gateway/src/state.rs","lineNumber":82,"sourceCode":"    /// pattern: 0600 perms, atomic write-then-rename. Same path\n    /// layout convention (`keys/` under `$ASTRID_HOME`).\n    ///\n    /// # Errors\n    /// Returns an error if the keys directory can't be created,\n    /// the on-disk key is corrupt (wrong length), or the file\n    /// write fails.\n    pub fn load_or_generate() -> anyhow::Result<Self> {\n        use anyhow::Context as _;\n        let home = astrid_core::dirs::AstridHome::resolve()\n            .context(\"resolve $ASTRID_HOME for gateway signing key\")?;\n        let keys_dir = home.keys_dir();\n        let key_path = keys_dir.join(\"gateway.ed25519\");\n\n        if key_path.exists() {\n            let bytes = std::fs::read(&key_path)\n                .with_context(|| format!(\"read gateway key at {}\", key_path.display()))?;\n            if bytes.len() != 32 {\n                anyhow::bail!(\n                    \"gateway key at {} has wrong length ({} bytes, expected 32) — remove the file to regenerate\",\n                    key_path.display(),\n                    bytes.len()\n                );\n            }\n            let mut arr = [0u8; 32];\n            arr.copy_from_slice(&bytes);\n            let signer = SigningKey::from_bytes(&arr);\n            let verifier = signer.verifying_key();\n            return Ok(Self { signer, verifier });\n        }\n\n        // Generate fresh and persist atomically (write-then-rename\n        // with 0600 perms, matching the kernel's runtime key flow).\n        std::fs::create_dir_all(&keys_dir)\n            .with_context(|| format!(\"create keys dir {}\", keys_dir.display()))?;\n        let fresh = Self::fresh();\n","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-gateway/src/state.rs#L64-L100","documentation":"Corrupt-key guard in GatewaySigningKey::load_or_generate: the on-disk gateway signing key at keys/ under $ASTRID_HOME has the wrong byte length (expected 32), so it cannot be a valid key and startup refuses instead of using garbage material.","triggerScenarios":"Thrown at crates/astrid-gateway/src/state.rs:82 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Remove the corrupt key file so the next startup regenerates a fresh 32-byte key","Note that removing it invalidates previously issued tokens — plan re-authentication","Check for disk corruption or partial writes that truncated the file"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"affd8760f44190dbdfbec23403f4c4b642c33112","analyzedAt":"2026-09-09T21:28:12.402Z","contentChangedAt":"2026-09-09T21:28:12.402Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}