keepassxc-client 0.1.0

KeePassXC browser native-messaging protocol client (associate, get-logins, set-login, ...)
Documentation
// SPDX-License-Identifier: MIT OR Apache-2.0
// Copyright (c) 2026 gaffa fix <gaffa@mafix.cc>

use thiserror::Error;

#[derive(Debug, Error)]
pub enum KxcError {
    #[error("io error: {0}")]
    Io(#[from] std::io::Error),

    #[error("json error: {0}")]
    Json(#[from] serde_json::Error),

    #[error("base64 decode error: {0}")]
    Base64(#[from] base64::DecodeError),

    #[error("crypto failure (encrypt/decrypt)")]
    Crypto,

    #[error("no KeePassXC browser socket found (is KeePassXC running with Browser Integration enabled?) — tried: {0}")]
    SocketNotFound(String),

    #[error("peer public key not set (run change-public-keys first)")]
    NoPeerKey,

    #[error("nonce verification failed: response nonce != incremented request nonce")]
    NonceMismatch,

    #[error("KeePassXC returned error {code:?}: {message}")]
    KeePassXc { code: Option<i64>, message: String },

    #[error("association was rejected or is invalid")]
    NotAssociated,

    #[error("database is locked")]
    DatabaseLocked,

    #[error("unexpected response for action {action}: {detail}")]
    UnexpectedResponse { action: String, detail: String },

    #[error("connection closed by KeePassXC")]
    ConnectionClosed,
}

pub type Result<T> = std::result::Result<T, KxcError>;