Janis Danisevskis | 9d90b81 | 2020-11-25 21:02:11 -0800 | [diff] [blame] | 1 | // 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)] |
| 19 | pub 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), |
Joel Galenson | 0591458 | 2021-01-08 09:30:41 -0800 | [diff] [blame] | 59 | |
| 60 | /// This is returned if the C implementation of HKDFExtract returned false |
| 61 | /// or otherwise failed. |
| 62 | #[error("Failed to extract.")] |
| 63 | HKDFExtractFailed, |
| 64 | |
| 65 | /// This is returned if the C implementation of HKDFExpand returned false. |
| 66 | #[error("Failed to expand.")] |
| 67 | HKDFExpandFailed, |
| 68 | |
| 69 | /// This is returned if the C implementation of ECDHComputeKey returned -1. |
| 70 | #[error("Failed to compute ecdh key.")] |
| 71 | ECDHComputeKeyFailed, |
| 72 | |
| 73 | /// This is returned if the C implementation of ECKEYGenerateKey returned null. |
| 74 | #[error("Failed to generate key.")] |
| 75 | ECKEYGenerateKeyFailed, |
| 76 | |
| 77 | /// This is returned if the C implementation of ECKEYDeriveFromSecret returned null. |
| 78 | #[error("Failed to derive key.")] |
| 79 | ECKEYDeriveFailed, |
| 80 | |
| 81 | /// This is returned if the C implementation of ECPOINTPoint2Oct returned 0. |
| 82 | #[error("Failed to convert point to oct.")] |
| 83 | ECPoint2OctFailed, |
| 84 | |
| 85 | /// This is returned if the C implementation of ECPOINTOct2Point returned null. |
| 86 | #[error("Failed to convert oct to point.")] |
| 87 | ECOct2PointFailed, |
Shawn Willden | 8fde4c2 | 2021-02-14 13:58:22 -0700 | [diff] [blame] | 88 | |
| 89 | /// This is returned if the C implementation of extractSubjectFromCertificate failed. |
| 90 | #[error("Failed to extract certificate subject.")] |
| 91 | ExtractSubjectFailed, |
Janis Danisevskis | 9d90b81 | 2020-11-25 21:02:11 -0800 | [diff] [blame] | 92 | } |