1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//! Errors, phrased so that a caller can fix the problem from the message
//! alone.
use core::fmt;
use crate::encoding;
/// Errors produced by the ECQV operations.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
/// The request public key R_U is not a valid P-256 point.
///
/// The request did not come from a P-256 key pair, or was corrupted in
/// transit. Check that the requester used the same curve.
MalformedRequest,
/// The reconstruction value P_U is not on the P-256 curve.
///
/// The certificate is corrupt, or was issued for a different curve.
InvalidReconstructionPoint,
/// The derived private key does not match the reconstructed public key.
///
/// The certificate was not issued by the CA public key you supplied, or
/// the certificate or reconstruction value was altered.
SelfCheckFailed,
/// A signature did not verify with the reconstructed key.
///
/// Either the certificate was forged (reconstruction succeeded but the
/// key is wrong), or the message or signature was altered.
SignatureVerification,
/// A scalar value was outside the valid range.
///
/// A secret or reconstruction value was zero or >= the group order.
InvalidScalar,
/// The certificate bytes could not be parsed.
///
/// The certificate is truncated, or the field lengths are inconsistent.
MalformedCertificate,
/// The certificate's reconstruction point is not a valid P-256 point.
///
/// The certificate is corrupt, or was issued for a different curve.
InvalidCertificatePoint,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::MalformedRequest => f.write_str(
"the request public key R_U is not a valid P-256 point; check that the requester used the same curve",
),
Error::InvalidReconstructionPoint => f.write_str(
"the reconstruction value P_U is not on the P-256 curve; the certificate is corrupt or was issued for a different curve",
),
Error::SelfCheckFailed => f.write_str(
"the derived private key does not match the reconstructed public key; the certificate was not issued by this CA or was altered",
),
Error::SignatureVerification => f.write_str(
"the signature did not verify with the reconstructed key; the certificate is forged or the message was altered",
),
Error::InvalidScalar => f.write_str(
"a secret or reconstruction value was zero or >= the group order",
),
Error::MalformedCertificate => f.write_str(
"the certificate bytes could not be parsed; it is truncated or the field lengths are inconsistent",
),
Error::InvalidCertificatePoint => f.write_str(
"the certificate's reconstruction point is not a valid P-256 point; the certificate is corrupt or was issued for a different curve",
),
}
}
}
impl core::error::Error for Error {}
impl From<encoding::DecodeError> for Error {
fn from(e: encoding::DecodeError) -> Self {
match e {
encoding::DecodeError::Truncated => Error::MalformedCertificate,
encoding::DecodeError::InvalidPoint => Error::InvalidCertificatePoint,
}
}
}