-
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Yuki Kishimoto <[email protected]>
- Loading branch information
Showing
28 changed files
with
248 additions
and
430 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) 2022-2023 Yuki Kishimoto | ||
// Copyright (c) 2023-2024 Rust Nostr Developers | ||
// Distributed under the MIT software license | ||
|
||
use alloc::string::{String, ToString}; | ||
use core::fmt; | ||
|
||
use crate::signer::SignerError; | ||
use crate::util::hex; | ||
|
||
/// Event error | ||
#[derive(Debug, PartialEq, Eq)] | ||
pub enum Error { | ||
/// Error serializing or deserializing JSON data | ||
Json(String), | ||
/// Signer error | ||
Signer(String), | ||
/// Hex decode error | ||
Hex(hex::Error), | ||
/// Unknown JSON event key | ||
UnknownKey(String), | ||
/// Invalid event ID | ||
InvalidId, | ||
/// Invalid signature | ||
InvalidSignature, | ||
} | ||
|
||
#[cfg(feature = "std")] | ||
impl std::error::Error for Error {} | ||
|
||
impl fmt::Display for Error { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
Self::Json(e) => write!(f, "{e}"), | ||
Self::Signer(e) => write!(f, "{e}"), | ||
Self::Hex(e) => write!(f, "{e}"), | ||
Self::UnknownKey(key) => write!(f, "Unknown key: {key}"), | ||
Self::InvalidId => write!(f, "Invalid event ID"), | ||
Self::InvalidSignature => write!(f, "Invalid signature"), | ||
} | ||
} | ||
} | ||
|
||
impl From<serde_json::Error> for Error { | ||
fn from(e: serde_json::Error) -> Self { | ||
Self::Json(e.to_string()) | ||
} | ||
} | ||
|
||
impl From<SignerError> for Error { | ||
fn from(e: SignerError) -> Self { | ||
Self::Signer(e.to_string()) | ||
} | ||
} | ||
|
||
impl From<hex::Error> for Error { | ||
fn from(e: hex::Error) -> Self { | ||
Self::Hex(e) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.