Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/vendor/ed25519-dalek/src/errors.rs # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / vendor / ed25519-dalek / src / errors.rs` 119 lines ยท 4039 bytes Raw Blame History 1 // -*- mode: rust; -*- 2 // 3 // This file is part of `ed25519`-dalek. 4 // Copyright (c) 2017-2019 isis lovecruft 5 // See LICENSE for licensing information. 6 // 7 // Authors: 8 // - isis agora lovecruft 9 10 //! Errors which may occur when parsing keys and/or signatures to or from wire formats. 11 12 // rustc seems to think the typenames in match statements (e.g. in 13 // Display) should be snake cased, for some reason. 14 #![allow(non_snake_case)] 15 16 use core::fmt; 17 use core::fmt::Display; 18 19 #[cfg(feature = "std")] 20 use std::error::Error; 21 22 /// Internal errors. Most application-level developers will likely not 23 /// need to pay any attention to these. 24 #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] 25 pub(crate) enum InternalError { 26 PointDecompression, 27 ScalarFormat, 28 /// An error in the length of bytes handed to a constructor. 29 /// 30 /// To use this, pass a string specifying the `name` of the type which is 31 /// returning the error, and the `length` in bytes which its constructor 32 /// expects. 33 BytesLength { 34 name: &'static str, 35 length: usize, 36 }, 37 /// The verification equation wasn't satisfied 38 Verify, 39 /// Two arrays did not match in size, making the called signature 40 /// verification method impossible. 41 #[cfg(feature = "batch")] 42 ArrayLength { 43 name_a: &'static str, 44 length_a: usize, 45 name_b: &'static str, 46 length_b: usize, 47 name_c: &'static str, 48 length_c: usize, 49 }, 50 /// An ed25519ph signature can only take up to 255 octets of context. 51 #[cfg(feature = "digest")] 52 PrehashedContextLength, 53 /// A mismatched (public, secret) key pair. 54 MismatchedKeypair, 55 } 56 57 impl Display for InternalError { 58 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 59 match *self { 60 InternalError::PointDecompression => write!(f, "Cannot decompress Edwards point"), 61 InternalError::ScalarFormat => write!(f, "Cannot use scalar with high-bit set"), 62 InternalError::BytesLength { name: n, length: l } => { 63 write!(f, "{} must be {} bytes in length", n, l) 64 } 65 InternalError::Verify => write!(f, "Verification equation was not satisfied"), 66 #[cfg(feature = "batch")] 67 InternalError::ArrayLength { 68 name_a: na, 69 length_a: la, 70 name_b: nb, 71 length_b: lb, 72 name_c: nc, 73 length_c: lc, 74 } => write!( 75 f, 76 "Arrays must be the same length: {} has length {}, 77 {} has length {}, {} has length {}.", 78 na, la, nb, lb, nc, lc 79 ), 80 #[cfg(feature = "digest")] 81 InternalError::PrehashedContextLength => write!( 82 f, 83 "An ed25519ph signature can only take up to 255 octets of context" 84 ), 85 InternalError::MismatchedKeypair => write!(f, "Mismatched Keypair detected"), 86 } 87 } 88 } 89 90 #[cfg(feature = "std")] 91 impl Error for InternalError {} 92 93 /// Errors which may occur while processing signatures and keypairs. 94 /// 95 /// This error may arise due to: 96 /// 97 /// * Being given bytes with a length different to what was expected. 98 /// 99 /// * A problem decompressing `r`, a curve point, in the `Signature`, or the 100 /// curve point for a `PublicKey`. 101 /// 102 /// * A problem with the format of `s`, a scalar, in the `Signature`. This 103 /// is only raised if the high-bit of the scalar was set. (Scalars must 104 /// only be constructed from 255-bit integers.) 105 /// 106 /// * Failure of a signature to satisfy the verification equation. 107 pub type SignatureError = `ed25519`::signature::Error; 108 109 impl From for SignatureError { 110 #[cfg(not(feature = "std"))] 111 fn from(_err: InternalError) -> SignatureError { 112 SignatureError::new() 113 } 114 115 #[cfg(feature = "std")] 116 fn from(err: InternalError) -> SignatureError { 117 SignatureError::from_source(err) 118 } 119 }