tightbeam-rs 0.6.2

A secure, high-performance messaging protocol library
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
#[cfg(not(feature = "std"))]
extern crate alloc;
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

use crate::spki::ObjectIdentifier;
use crate::Version;

#[cfg(feature = "derive")]
use crate::Errorizable;

/// A specialized Result type for TightBeam operations
pub type Result<T> = core::result::Result<T, TightBeamError>;

/// A specialized Result type for compression operations
#[cfg(feature = "compress")]
pub type CompressionResult<T> = core::result::Result<T, CompressionError>;

/// Error indicating a mismatch between received and expected values
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct ReceivedExpectedError<Received, Expected> {
	pub received: Received,
	pub expected: Expected,
}

impl<Received, Expected> From<(Received, Expected)> for ReceivedExpectedError<Received, Expected> {
	fn from((received, expected): (Received, Expected)) -> Self {
		Self { received, expected }
	}
}

impl<Received: core::fmt::Debug, Expected: core::fmt::Debug> core::fmt::Display
	for ReceivedExpectedError<Received, Expected>
{
	fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
		write!(f, "expected {:?}, got {:?}", self.expected, self.received)
	}
}

#[cfg(feature = "compress")]
#[cfg_attr(feature = "derive", derive(Errorizable))]
#[derive(Debug)]
pub enum CompressionError {
	#[cfg(feature = "zstd")]
	#[cfg_attr(feature = "derive", error("ZSTD compression/decompression error: {0}"))]
	#[cfg_attr(feature = "derive", from)]
	ZSTD(zeekstd::Error),

	#[cfg_attr(feature = "derive", error("I/O error during compression/decompression: {0}"))]
	#[cfg_attr(feature = "derive", from)]
	IO(std::io::Error),
}

#[cfg(all(feature = "compress", not(feature = "derive")))]
impl core::fmt::Display for CompressionError {
	fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
		match self {
			#[cfg(feature = "zstd")]
			CompressionError::ZSTD(e) => write!(f, "ZSTD compression/decompression error: {e}"),
			CompressionError::IO(e) => write!(f, "I/O error during compression/decompression: {e}"),
		}
	}
}

/// Trait for injected faults in testing
#[cfg(feature = "testing-fault")]
pub trait InjectedError: core::fmt::Debug + core::fmt::Display + Send + Sync {}

// Blanket implementation for any type meeting the requirements
#[cfg(feature = "testing-fault")]
impl<T> InjectedError for T where T: core::fmt::Debug + core::fmt::Display + Send + Sync {}

#[cfg_attr(feature = "derive", derive(Errorizable))]
#[derive(Debug)]
pub enum TightBeamError {
	/// Error from the matrix implementation
	#[cfg_attr(feature = "derive", error("Matrix error: {0}"))]
	#[cfg_attr(feature = "derive", from)]
	MatrixError(crate::matrix::MatrixError),

	#[cfg(feature = "router")]
	#[cfg_attr(feature = "derive", error("Route error: {0}"))]
	#[cfg_attr(feature = "derive", from)]
	RouterError(crate::router::RouterError),

	/// Error from the message builder
	#[cfg(feature = "builder")]
	#[cfg_attr(feature = "derive", error("Build error: {0}"))]
	#[cfg_attr(feature = "derive", from)]
	BuildError(crate::builder::error::BuildError),

	/// StandardError
	#[cfg(feature = "standards")]
	#[cfg_attr(feature = "derive", error("Standard error: {0}"))]
	#[cfg_attr(feature = "derive", from)]
	StandardError(crate::standards::error::StandardError),

	#[cfg(feature = "colony")]
	#[cfg_attr(feature = "derive", error("Drone error: {0}"))]
	#[cfg_attr(feature = "derive", from)]
	HiveError(crate::colony::hive::HiveError),

	#[cfg(feature = "colony")]
	#[cfg_attr(feature = "derive", error("Worker relay error: {0}"))]
	#[cfg_attr(feature = "derive", from)]
	WorkerRelay(crate::colony::worker::WorkerRelayError),

	#[cfg(feature = "std")]
	/// I/O error
	#[cfg_attr(feature = "derive", error("I/O error: {0}"))]
	#[cfg_attr(feature = "derive", from)]
	IoError(std::io::Error),

	#[cfg(feature = "std")]
	/// Lock poisoned
	#[cfg_attr(feature = "derive", error("Lock poisoned"))]
	LockPoisoned,

	/// Invalid or unsupported algorithm identifier
	#[cfg_attr(feature = "derive", error("Invalid or unsupported object identifier: {0}"))]
	InvalidOID(crate::der::oid::Error),

	/// Error during signature verification or generation
	#[cfg(feature = "signature")]
	#[cfg_attr(feature = "derive", error("Signature verification or generation error: {0}"))]
	#[cfg_attr(feature = "derive", from)]
	SignatureError(crate::crypto::sign::Error),

	/// Error from elliptic curve operations
	#[cfg(feature = "signature")]
	#[cfg_attr(feature = "derive", error("Elliptic curve error: {0}"))]
	#[cfg_attr(feature = "derive", from)]
	EllipticCurveError(crate::crypto::sign::elliptic_curve::Error),

	/// Error during serialization
	#[cfg_attr(feature = "derive", error("Serialization error: {0}"))]
	#[cfg_attr(feature = "derive", from)]
	SerializationError(crate::der::Error),

	/// Error during compression or decompression
	#[cfg(feature = "compress")]
	#[cfg_attr(feature = "derive", error("Compression error: {0}"))]
	#[cfg_attr(feature = "derive", from)]
	CompressionError(CompressionError),

	/// Error during handshake operations
	#[cfg(feature = "transport")]
	#[cfg_attr(feature = "derive", error("Handshake error: {0}"))]
	#[cfg_attr(feature = "derive", from)]
	HandshakeError(crate::transport::handshake::HandshakeError),

	#[cfg(feature = "transport")]
	#[cfg_attr(feature = "derive", error("Transport error: {0}"))]
	#[cfg_attr(feature = "derive", from)]
	TransportError(crate::transport::error::TransportError),

	/// Unsupported protocol version
	#[cfg_attr(
		feature = "derive",
		error("Unsupported protocol version: expected {expected:?}, got {received:?}")
	)]
	UnsupportedVersion(ReceivedExpectedError<Version, Version>),

	/// Error during testing operations
	#[cfg(feature = "testing")]
	#[cfg_attr(feature = "derive", error("Testing error: {0}"))]
	#[cfg_attr(feature = "derive", from)]
	TestingError(crate::testing::error::TestingError),

	/// Error during URN validation
	#[cfg_attr(feature = "derive", error("URN validation error: {0}"))]
	#[cfg_attr(feature = "derive", from)]
	UrnValidationError(crate::utils::urn::UrnValidationError),

	/// Error during encryption or decryption
	#[cfg(feature = "aead")]
	#[cfg_attr(feature = "derive", error("Encryption or decryption error: {0}"))]
	#[cfg_attr(feature = "derive", from)]
	EncryptionError(crate::crypto::aead::Error),

	/// Invalid key length for cryptographic operations
	#[cfg(feature = "aead")]
	#[cfg_attr(feature = "derive", error("Invalid key length: {0}"))]
	#[cfg_attr(feature = "derive", from)]
	InvalidKeyLength(crypto_common::InvalidLength),

	/// Error during ECIES operations
	#[cfg(feature = "ecies")]
	#[cfg_attr(feature = "derive", error("ECIES error: {0}"))]
	#[cfg_attr(feature = "derive", from)]
	EciesError(crate::crypto::ecies::EciesError),

	#[cfg(feature = "crypto")]
	#[cfg_attr(feature = "derive", error("Crypto policy error: {0}"))]
	#[cfg_attr(feature = "derive", from)]
	CryptoPolicyError(crate::crypto::policy::CryptoPolicyError),

	/// Error during certificate validation
	#[cfg(feature = "x509")]
	#[cfg_attr(feature = "derive", error("Certificate validation error: {0}"))]
	#[cfg_attr(feature = "derive", from)]
	CertificateValidationError(crate::crypto::x509::error::CertificateValidationError),

	#[cfg(feature = "kdf")]
	#[cfg_attr(feature = "derive", error("Key derivation error: {0}"))]
	#[cfg_attr(feature = "derive", from)]
	KeyDerivationError(crate::crypto::kdf::KdfError),

	/// Error from key provider operations
	#[cfg(feature = "crypto")]
	#[cfg_attr(feature = "derive", error("Key provider error: {0}"))]
	#[cfg_attr(feature = "derive", from)]
	KeyError(crate::crypto::key::KeyError),

	/// Error obtaining random bytes from the OS
	#[cfg(feature = "random")]
	#[cfg_attr(feature = "derive", error("OS random number generator error: {0}"))]
	#[cfg_attr(feature = "derive", from)]
	OsRngError(rand_core::Error),

	/// Error during SPKI operations
	#[cfg(feature = "x509")]
	#[cfg_attr(feature = "derive", error("SPKI error: {0}"))]
	#[cfg_attr(feature = "derive", from)]
	SpkiError(crate::spki::Error),

	/// Error during X.509 certificate building
	#[cfg(feature = "x509")]
	#[cfg_attr(feature = "derive", error("X.509 builder error: {0}"))]
	#[cfg_attr(feature = "derive", from)]
	X509BuilderError(x509_cert::builder::Error),

	/// Error receiving from channel with timeout
	#[cfg(feature = "std")]
	#[cfg_attr(feature = "derive", error("Channel receive timeout error"))]
	RecvTimeoutError,

	/// Error decoding signature from bytes
	#[cfg(feature = "signature")]
	#[cfg_attr(feature = "derive", error("Signature encoding error"))]
	SignatureEncodingError,

	/// Invalid metadata
	#[cfg_attr(feature = "derive", error("Invalid metadata"))]
	InvalidMetadata,

	/// Invalid message body
	#[cfg_attr(feature = "derive", error("Invalid message body"))]
	InvalidBody,

	/// Invalid overflow value
	#[cfg_attr(feature = "derive", error("Invalid overflow value"))]
	InvalidOverflowValue,

	/// Invalid order
	#[cfg_attr(feature = "derive", error("Invalid order"))]
	InvalidOrder,

	// Missing order
	#[cfg_attr(feature = "derive", error("Missing order"))]
	MissingOrder,

	/// Missing inflator
	#[cfg_attr(feature = "derive", error("Missing inflator"))]
	MissingInflator,

	/// Missing feature
	#[cfg_attr(feature = "derive", error("Missing feature: {0}"))]
	MissingFeature(&'static str),

	/// Missing priority
	#[cfg_attr(feature = "derive", error("Missing priority"))]
	MissingPriority,

	/// Missing response
	#[cfg_attr(feature = "derive", error("Missing response"))]
	MissingResponse,

	/// Signature is missing
	#[cfg(feature = "signature")]
	#[cfg_attr(feature = "derive", error("Missing signature"))]
	MissingSignature,

	/// Signature info is missing
	#[cfg(feature = "signature")]
	#[cfg_attr(feature = "derive", error("Missing signature info"))]
	MissingSignatureInfo,

	/// Missing Encryption Info
	#[cfg(feature = "aead")]
	#[cfg_attr(feature = "derive", error("Missing encryption info"))]
	MissingEncryptionInfo,

	/// Missing Integrity Info
	#[cfg(feature = "digest")]
	#[cfg_attr(feature = "derive", error("Missing integrity info"))]
	MissingDigestInfo,

	/// Missing Compression Info
	#[cfg_attr(feature = "derive", error("Missing compression info"))]
	MissingCompressedData,

	/// Invalid algorithm for the message profile
	#[cfg_attr(feature = "derive", error("Invalid algorithm for message profile"))]
	InvalidAlgorithm,

	/// Unexpected algorithm for the message profile
	#[cfg_attr(
		feature = "derive",
		error("Unexpected algorithm for message profile: expected {expected:?}, got {received:?}")
	)]
	UnexpectedAlgorithm(ReceivedExpectedError<ObjectIdentifier, ObjectIdentifier>),

	/// Missing or invalid configuration
	#[cfg_attr(feature = "derive", error("Missing configuration"))]
	MissingConfiguration,

	/// Operation not supported by this implementation
	#[cfg_attr(feature = "derive", error("Unsupported operation"))]
	UnsupportedOperation,

	/// Hive already established
	#[cfg(feature = "colony")]
	#[cfg_attr(feature = "derive", error("Hive already established"))]
	AlreadyEstablished,

	/// Task join error
	#[cfg(feature = "colony")]
	#[cfg_attr(feature = "derive", error("Task join failed"))]
	JoinError,

	/// Multiple errors collected together
	#[cfg_attr(feature = "derive", error("Multiple errors occurred: {0:?}"))]
	Sequence(Vec<TightBeamError>),

	/// Injected fault for testing (any error type)
	#[cfg(feature = "testing-fault")]
	#[cfg_attr(feature = "derive", error("Injected fault: {0}"))]
	InjectedFault(Box<dyn InjectedError>),
}

#[cfg(all(feature = "colony", not(feature = "derive")))]
impl From<crate::colony::WorkerRelayError> for TightBeamError {
	fn from(err: crate::colony::WorkerRelayError) -> Self {
		TightBeamError::WorkerRelay(err)
	}
}

#[cfg(not(feature = "derive"))]
impl core::fmt::Display for TightBeamError {
	fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
		match self {
			TightBeamError::SerializationError(err) => write!(f, "Serialization error: {err}"),
			#[cfg(feature = "router")]
			TightBeamError::RouterError(err) => write!(f, "Route error: {err}"),
			TightBeamError::InvalidMetadata => write!(f, "Invalid metadata"),
			TightBeamError::InvalidBody => write!(f, "Invalid message body"),
			TightBeamError::InvalidOID(err) => {
				write!(f, "Invalid or unsupported object identifier: {err}")
			}
			TightBeamError::InvalidOverflowValue => write!(f, "Invalid overflow value"),
			TightBeamError::InvalidOrder => write!(f, "Invalid order"),
			TightBeamError::MissingInflator => write!(f, "Missing inflator"),
			TightBeamError::MissingOrder => write!(f, "Missing order"),
			TightBeamError::MissingPriority => write!(f, "Missing priority"),
			TightBeamError::MissingResponse => write!(f, "Missing response"),
			TightBeamError::MissingFeature(feature) => write!(f, "Missing feature: {feature}"),
			TightBeamError::MissingConfiguration => write!(f, "Missing configuration"),
			TightBeamError::UnsupportedOperation => write!(f, "Unsupported operation"),
			#[cfg(feature = "transport")]
			TightBeamError::HandshakeError(err) => write!(f, "Handshake error: {err}"),
			#[cfg(feature = "colony")]
			TightBeamError::HiveError(err) => write!(f, "Drone error: {err}"),
			#[cfg(feature = "std")]
			TightBeamError::LockPoisoned => write!(f, "Lock poisoned"),
			#[cfg(feature = "standards")]
			TightBeamError::StandardError(err) => write!(f, "Standard error: {err}"),
			#[cfg(feature = "random")]
			TightBeamError::OsRngError(err) => write!(f, "OS random number generator error: {err}"),
			#[cfg(feature = "x509")]
			TightBeamError::SpkiError(err) => write!(f, "SPKI error: {err}"),
			#[cfg(feature = "x509")]
			TightBeamError::X509BuilderError(err) => write!(f, "X.509 builder error: {err}"),
			#[cfg(feature = "std")]
			TightBeamError::RecvTimeoutError => write!(f, "Channel receive timeout error"),
			#[cfg(feature = "aead")]
			TightBeamError::EncryptionError(err) => {
				write!(f, "Encryption or decryption error: {err}")
			}
			#[cfg(feature = "aead")]
			TightBeamError::InvalidKeyLength(_) => {
				write!(f, "Invalid key length")
			}
			#[cfg(feature = "ecies")]
			TightBeamError::EciesError(err) => write!(f, "ECIES error: {err}"),
			#[cfg(feature = "signature")]
			TightBeamError::SignatureError(err) => {
				write!(f, "Signature verification or generation error: {err}")
			}
			#[cfg(feature = "signature")]
			TightBeamError::EllipticCurveError(_) => write!(f, "Elliptic curve error"),
			#[cfg(feature = "signature")]
			TightBeamError::SignatureEncodingError => write!(f, "Signature encoding error"),
			TightBeamError::KeyError(err) => write!(f, "Key provider error: {err}"),
			#[cfg(feature = "digest")]
			TightBeamError::MissingDigestInfo => write!(f, "Missing integrity info"),
			#[cfg(feature = "aead")]
			TightBeamError::MissingEncryptionInfo => write!(f, "Missing encryption info"),
			#[cfg(feature = "signature")]
			TightBeamError::MissingSignatureInfo => write!(f, "Missing signature info"),
			#[cfg(feature = "signature")]
			TightBeamError::MissingSignature => write!(f, "Missing signature"),
			TightBeamError::MissingCompressedData => write!(f, "Missing compression info"),
			TightBeamError::InvalidAlgorithm => write!(f, "Invalid algorithm for message profile"),
			TightBeamError::UnexpectedAlgorithm(err) => {
				write!(
					f,
					"Unexpected algorithm for message profile: expected {:?}, got {:?}",
					err.expected, err.received
				)
			}
			#[cfg(feature = "compress")]
			TightBeamError::CompressionError(err) => match err {
				#[cfg(feature = "zstd")]
				CompressionError::ZSTD(e) => write!(f, "ZSTD compression/decompression error: {e}"),
				CompressionError::IO(e) => {
					write!(f, "I/O error during compression/decompression: {e}")
				}
			},
			TightBeamError::Sequence(errors) => {
				write!(f, "Multiple errors: ")?;
				for (i, error) in errors.iter().enumerate() {
					if i > 0 {
						write!(f, "; ")?;
					}
					write!(f, "{error}")?;
				}
				Ok(())
			}
			#[cfg(feature = "colony")]
			TightBeamError::AlreadyEstablished => write!(f, "Hive already established"),
			#[cfg(feature = "colony")]
			TightBeamError::JoinError => write!(f, "Task join failed"),
			TightBeamError::UnsupportedVersion(err) => {
				write!(
					f,
					"Unsupported protocol version: expected {:?}, got {:?}",
					err.expected, err.received
				)
			}
			#[cfg(feature = "testing")]
			TightBeamError::TestingError(err) => write!(f, "Testing error: {err}"),
			TightBeamError::UrnValidationError(err) => write!(f, "URN validation error: {err}"),
			#[cfg(feature = "testing-fault")]
			TightBeamError::InjectedFault(err) => write!(f, "Injected fault: {err}"),
		}
	}
}

#[cfg(feature = "std")]
crate::impl_from!(std::string::FromUtf8Error => TightBeamError::IoError via |err| std::io::Error::new(std::io::ErrorKind::InvalidData, err));
#[cfg(feature = "std")]
crate::impl_from!(std::net::AddrParseError => TightBeamError::IoError via |err| std::io::Error::new(std::io::ErrorKind::InvalidInput, err));

// ============================================================================
// Non-derive From implementations
// When `derive` feature is disabled, these provide the From impls that would
// otherwise be generated by the Errorizable derive macro's #[from] attribute.
// ============================================================================

#[cfg(not(feature = "derive"))]
crate::impl_from!(der::Error => TightBeamError::SerializationError);
#[cfg(not(feature = "derive"))]
crate::impl_from!(crate::matrix::MatrixError => TightBeamError::MatrixError);
#[cfg(not(feature = "derive"))]
crate::impl_from!(crate::utils::urn::UrnValidationError => TightBeamError::UrnValidationError);
#[cfg(all(feature = "crypto", not(feature = "derive")))]
crate::impl_from!(crate::crypto::policy::CryptoPolicyError => TightBeamError::CryptoPolicyError);
#[cfg(all(feature = "kdf", not(feature = "derive")))]
crate::impl_from!(crate::crypto::kdf::KdfError => TightBeamError::KeyDerivationError);
#[cfg(all(feature = "crypto", not(feature = "derive")))]
crate::impl_from!(crate::crypto::key::KeyError => TightBeamError::KeyError);

#[cfg(all(feature = "std", not(feature = "derive")))]
crate::impl_from!(std::io::Error => TightBeamError::IoError);

#[cfg(all(feature = "router", not(feature = "derive")))]
crate::impl_from!(crate::router::RouterError => TightBeamError::RouterError);

#[cfg(all(feature = "builder", not(feature = "derive")))]
crate::impl_from!(crate::builder::error::BuildError => TightBeamError::BuildError);

#[cfg(all(feature = "standards", not(feature = "derive")))]
crate::impl_from!(crate::standards::error::StandardError => TightBeamError::StandardError);

#[cfg(all(feature = "colony", not(feature = "derive")))]
crate::impl_from!(crate::colony::hive::HiveError => TightBeamError::HiveError);
#[cfg(all(feature = "colony", not(feature = "derive")))]
crate::impl_from!(crate::colony::worker::WorkerRelayError => TightBeamError::WorkerRelay);

#[cfg(all(feature = "transport", not(feature = "derive")))]
crate::impl_from!(crate::transport::handshake::HandshakeError => TightBeamError::HandshakeError);
#[cfg(all(feature = "transport", not(feature = "derive")))]
crate::impl_from!(crate::transport::error::TransportError => TightBeamError::TransportError);

#[cfg(all(feature = "random", not(feature = "derive")))]
crate::impl_from!(getrandom::Error => TightBeamError::OsRngError);

#[cfg(all(feature = "x509", not(feature = "derive")))]
crate::impl_from!(spki::Error => TightBeamError::SpkiError);
#[cfg(all(feature = "x509", not(feature = "derive")))]
crate::impl_from!(x509_cert::builder::Error => TightBeamError::X509BuilderError);

#[cfg(all(feature = "compress", not(feature = "derive")))]
crate::impl_from!(CompressionError => TightBeamError::CompressionError);
#[cfg(all(feature = "std", feature = "compress", not(feature = "derive")))]
crate::impl_from!(std::io::Error => CompressionError::IO);

#[cfg(all(feature = "aead", not(feature = "derive")))]
crate::impl_from!(aead::Error => TightBeamError::EncryptionError);
#[cfg(all(feature = "aead", not(feature = "derive")))]
crate::impl_from!(crypto_common::InvalidLength => TightBeamError::InvalidKeyLength);

#[cfg(all(feature = "ecies", not(feature = "derive")))]
crate::impl_from!(EciesError => TightBeamError::EciesError);

#[cfg(all(feature = "signature", not(feature = "derive")))]
crate::impl_from!(signature::Error => TightBeamError::SignatureError);
#[cfg(all(feature = "signature", not(feature = "derive")))]
crate::impl_from!(crate::crypto::sign::elliptic_curve::Error => TightBeamError::EllipticCurveError);

#[cfg(all(feature = "zstd", not(feature = "derive")))]
crate::impl_from!(zeekstd::Error => TightBeamError::CompressionError via CompressionError::ZSTD);
#[cfg(all(feature = "zstd", not(feature = "derive")))]
crate::impl_from!(zeekstd::Error => CompressionError::ZSTD);
#[cfg(all(feature = "testing", not(feature = "derive")))]
crate::impl_from!(crate::testing::error::TestingError => TightBeamError::TestingError);
#[cfg(all(feature = "std", not(feature = "derive")))]
crate::impl_from!(std::sync::mpsc::RecvTimeoutError => TightBeamError::RecvTimeoutError discard);

#[cfg(not(feature = "derive"))]
impl core::error::Error for TightBeamError {}
#[cfg(all(feature = "compress", not(feature = "derive")))]
impl core::error::Error for CompressionError {}

// Generic type to unit variant - requires manual impl due to generic T
#[cfg(feature = "std")]
impl<T> From<std::sync::PoisonError<T>> for TightBeamError {
	fn from(_: std::sync::PoisonError<T>) -> Self {
		TightBeamError::LockPoisoned
	}
}