tpm2_crypto/error.rs
1// SPDX-License-Identifier: MIT OR Apache-2.0
2// Copyright (c) 2025 Opinsys Oy
3// Copyright (c) 2024-2025 Jarkko Sakkinen
4
5use thiserror::Error;
6
7/// The top-level error type for cryptographic operations.
8#[derive(Debug, Error, PartialEq, Eq)]
9pub enum TpmCryptoError {
10 /// ECC curve is not supported in the context of use.
11 #[error("invalid ECC curve")]
12 InvalidEccCurve,
13
14 /// Invalid ECC public parameters.
15 #[error("invalid ECC parameters")]
16 InvalidEccParameters,
17
18 /// Hash algorithm is not supported in the context of use.
19 #[error("invalid hash algorithm")]
20 InvalidHash,
21
22 /// Invalid RSA key bits.
23 #[error("invalid RSA key bits: {0}")]
24 InvalidKeyBits(u16),
25
26 /// Invalid object type.
27 #[error("invalid object type")]
28 InvalidObjectType,
29
30 /// Invalid RSA public parameters.
31 #[error("invalid RSA parameters")]
32 InvalidRsaParameters,
33
34 /// A zero-length key was provided.
35 #[error("the provided key has zero length")]
36 KeyIsEmpty,
37
38 /// Marshaling a TPM protocol encoded object failed.
39 #[error("marshal: {0}")]
40 Marshal(tpm2_protocol::TpmProtocolError),
41
42 /// A cryptographic operation failed.
43 #[error("operation failed")]
44 OperationFailed,
45
46 /// Not enough memory available.
47 #[error("out of memory")]
48 OutOfMemory,
49
50 /// The provided HMAC does not match to the expected value.
51 #[error("permission denied")]
52 PermissionDenied,
53
54 /// Unmarshaling a TPM protocol encoded object failed.
55 #[error("unmarshal: {0}")]
56 Unmarshal(tpm2_protocol::TpmProtocolError),
57}