blob: 2eb97b976d5b122f2235cc172929ccc7809cb3f2 [file] [log] [blame]
Janis Danisevskis9d90b812020-11-25 21:02:11 -08001// Copyright 2020, The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! This module implements Error for the keystore2_crypto library.
16
17/// Crypto specific error codes.
18#[derive(Debug, thiserror::Error, Eq, PartialEq)]
19pub enum Error {
20 /// This is returned if the C/C++ implementation of AES_gcm_decrypt returned false.
21 #[error("Failed to decrypt.")]
22 DecryptionFailed,
23
24 /// This is returned if the C/C++ implementation of AES_gcm_encrypt returned false.
25 #[error("Failed to encrypt.")]
26 EncryptionFailed,
27
28 /// The initialization vector has the wrong length.
29 #[error("Invalid IV length.")]
30 InvalidIvLength,
31
32 /// The aead tag has the wrong length.
33 #[error("Invalid AEAD tag length.")]
34 InvalidAeadTagLength,
35
36 /// The key has the wrong length.
37 #[error("Invalid key length.")]
38 InvalidKeyLength,
39
40 /// Invalid data length.
41 #[error("Invalid data length.")]
42 InvalidDataLength,
43
44 /// Invalid salt length.
45 #[error("Invalid salt length.")]
46 InvalidSaltLength,
47
48 /// Random number generation failed.
49 #[error("Random number generation failed.")]
50 RandomNumberGenerationFailed,
51
52 /// ZVec construction failed.
53 #[error(transparent)]
54 LayoutError(#[from] std::alloc::LayoutErr),
55
56 /// Nix error.
57 #[error(transparent)]
58 NixError(#[from] nix::Error),
59}