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), 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 ECKEYMarshalPrivateKey returned 0. 78 #[error("Failed to marshal private key.")] 79 ECKEYMarshalPrivateKeyFailed, 80 81 /// This is returned if the C implementation of ECKEYParsePrivateKey returned null. 82 #[error("Failed to parse private key.")] 83 ECKEYParsePrivateKeyFailed, 84 85 /// This is returned if the C implementation of ECPOINTPoint2Oct returned 0. 86 #[error("Failed to convert point to oct.")] 87 ECPoint2OctFailed, 88 89 /// This is returned if the C implementation of ECPOINTOct2Point returned null. 90 #[error("Failed to convert oct to point.")] 91 ECOct2PointFailed, 92 93 /// This is returned if the C implementation of extractSubjectFromCertificate failed. 94 #[error("Failed to extract certificate subject.")] 95 ExtractSubjectFailed, 96 } 97