winrm_rs/error.rs
1// Consolidated error types for the winrm-rs crate.
2//
3// All error enums live here to avoid circular dependencies between modules.
4
5/// Errors that can occur during WinRM operations.
6///
7/// Variants cover the full error surface: HTTP transport, authentication
8/// handshake, NTLM protocol, SOAP-level faults, and operation timeouts.
9#[derive(Debug, thiserror::Error)]
10pub enum WinrmError {
11 /// HTTP transport error from `reqwest` (connection refused, timeout, TLS, etc.).
12 #[error("WinRM HTTP error: {0}")]
13 Http(reqwest::Error),
14 /// Authentication was rejected by the server (bad credentials, unexpected
15 /// HTTP status during NTLM handshake, missing headers).
16 #[error("WinRM auth failed: {0}")]
17 AuthFailed(String),
18 /// NTLM protocol error (malformed challenge message, bad signature, etc.).
19 #[error("WinRM NTLM error: {0}")]
20 Ntlm(NtlmError),
21 /// SOAP-level fault or XML parsing error returned by the WinRM service.
22 #[error("WinRM SOAP error: {0}")]
23 Soap(SoapError),
24 /// The operation exceeded the configured timeout.
25 #[error("WinRM operation timed out after {0}s")]
26 Timeout(u64),
27 /// File transfer error (upload or download failure).
28 #[error("file transfer error: {0}")]
29 Transfer(String),
30 /// The operation was cancelled via a [`CancellationToken`](tokio_util::sync::CancellationToken).
31 #[error("operation cancelled")]
32 Cancelled,
33 /// CredSSP protocol error.
34 #[error("CredSSP error: {0}")]
35 CredSsp(CredSspError),
36}
37
38/// Errors from the CredSSP authentication protocol (MS-CSSP).
39#[derive(Debug, thiserror::Error)]
40pub enum CredSspError {
41 /// ASN.1 DER encoding or decoding error.
42 #[error("ASN.1 decode error: {0}")]
43 Asn1Decode(String),
44 /// Server public key verification failed (possible MiTM).
45 #[error("server public key mismatch")]
46 PublicKeyMismatch,
47 /// Server returned an NTSTATUS error code.
48 #[error("server error: {0:#010x}")]
49 ServerError(u32),
50}
51
52/// Errors from SOAP envelope parsing or WS-Management fault responses.
53#[derive(Debug, thiserror::Error)]
54pub enum SoapError {
55 /// A required XML element (e.g. `ShellId`, `CommandId`) was not found in
56 /// the response body.
57 #[error("missing element: {0}")]
58 MissingElement(String),
59 /// The response body could not be parsed (e.g. invalid base64 in a stream).
60 #[error("parse error: {0}")]
61 ParseError(String),
62 /// The WinRM service returned a SOAP fault with the given code and reason.
63 #[error("SOAP fault [{code}]: {reason}")]
64 Fault {
65 /// Fault code, typically a WS-Addressing or WS-Management URI.
66 code: String,
67 /// Human-readable fault reason from the server.
68 reason: String,
69 },
70}
71
72/// Errors from the NTLM authentication protocol layer.
73#[derive(Debug, thiserror::Error)]
74pub enum NtlmError {
75 /// The NTLM message is structurally invalid: too short, bad signature,
76 /// wrong message type, or corrupt base64.
77 #[error("NTLM error: {0}")]
78 InvalidMessage(String),
79}