blob: c6476f94d99e65803fb77bf3b48c7e54b96ac88d [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.
Janis Danisevskisa16ddf32021-10-20 09:40:02 -070016use crate::zvec;
Janis Danisevskis9d90b812020-11-25 21:02:11 -080017
18/// Crypto specific error codes.
19#[derive(Debug, thiserror::Error, Eq, PartialEq)]
20pub enum Error {
21 /// This is returned if the C/C++ implementation of AES_gcm_decrypt returned false.
22 #[error("Failed to decrypt.")]
23 DecryptionFailed,
24
25 /// This is returned if the C/C++ implementation of AES_gcm_encrypt returned false.
26 #[error("Failed to encrypt.")]
27 EncryptionFailed,
28
29 /// The initialization vector has the wrong length.
30 #[error("Invalid IV length.")]
31 InvalidIvLength,
32
33 /// The aead tag has the wrong length.
34 #[error("Invalid AEAD tag length.")]
35 InvalidAeadTagLength,
36
37 /// The key has the wrong length.
38 #[error("Invalid key length.")]
39 InvalidKeyLength,
40
41 /// Invalid data length.
42 #[error("Invalid data length.")]
43 InvalidDataLength,
44
45 /// Invalid salt length.
46 #[error("Invalid salt length.")]
47 InvalidSaltLength,
48
49 /// Random number generation failed.
50 #[error("Random number generation failed.")]
51 RandomNumberGenerationFailed,
52
53 /// ZVec construction failed.
54 #[error(transparent)]
55 LayoutError(#[from] std::alloc::LayoutErr),
56
57 /// Nix error.
58 #[error(transparent)]
59 NixError(#[from] nix::Error),
Joel Galenson05914582021-01-08 09:30:41 -080060
61 /// This is returned if the C implementation of HKDFExtract returned false
62 /// or otherwise failed.
63 #[error("Failed to extract.")]
64 HKDFExtractFailed,
65
66 /// This is returned if the C implementation of HKDFExpand returned false.
67 #[error("Failed to expand.")]
68 HKDFExpandFailed,
69
70 /// This is returned if the C implementation of ECDHComputeKey returned -1.
71 #[error("Failed to compute ecdh key.")]
72 ECDHComputeKeyFailed,
73
74 /// This is returned if the C implementation of ECKEYGenerateKey returned null.
75 #[error("Failed to generate key.")]
76 ECKEYGenerateKeyFailed,
77
Paul Crowley7bb5edd2021-03-20 20:26:43 -070078 /// This is returned if the C implementation of ECKEYMarshalPrivateKey returned 0.
79 #[error("Failed to marshal private key.")]
80 ECKEYMarshalPrivateKeyFailed,
81
82 /// This is returned if the C implementation of ECKEYParsePrivateKey returned null.
83 #[error("Failed to parse private key.")]
84 ECKEYParsePrivateKeyFailed,
Joel Galenson05914582021-01-08 09:30:41 -080085
86 /// This is returned if the C implementation of ECPOINTPoint2Oct returned 0.
87 #[error("Failed to convert point to oct.")]
88 ECPoint2OctFailed,
89
90 /// This is returned if the C implementation of ECPOINTOct2Point returned null.
91 #[error("Failed to convert oct to point.")]
92 ECOct2PointFailed,
Shawn Willden8fde4c22021-02-14 13:58:22 -070093
94 /// This is returned if the C implementation of extractSubjectFromCertificate failed.
95 #[error("Failed to extract certificate subject.")]
96 ExtractSubjectFailed,
Janis Danisevskisa16ddf32021-10-20 09:40:02 -070097
98 /// Zvec error.
99 #[error(transparent)]
100 ZVec(#[from] zvec::Error),
Janis Danisevskis9d90b812020-11-25 21:02:11 -0800101}