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
// Copyright (c) 2022-2023 Yuki Kishimoto
// Copyright (c) 2023-2025 Rust Nostr Developers
// Distributed under the MIT software license
//! NIP56: Reporting
//!
//! <https://github.com/nostr-protocol/nips/blob/master/56.md>
use core::fmt;
use core::str::FromStr;
/// NIP56 error
#[derive(Debug, PartialEq, Eq)]
pub enum Error {
/// Unknown [`Report`]
UnknownReportType,
}
#[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::UnknownReportType => f.write_str("Unknown report type"),
}
}
}
/// Report
///
/// <https://github.com/nostr-protocol/nips/blob/master/56.md>
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Report {
/// Depictions of nudity, porn, etc
Nudity,
/// Virus, trojan horse, worm, robot, spyware, adware, back door, ransomware, rootkit, kidnapper, etc.
Malware,
/// Profanity, hateful speech, etc.
Profanity,
/// Something which may be illegal in some jurisdiction
Illegal,
/// Spam
Spam,
/// Someone pretending to be someone else
Impersonation,
/// Reports that don't fit in the above categories
Other,
}
impl fmt::Display for Report {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(self.as_str())
}
}
impl Report {
/// Get as `&str`
pub fn as_str(&self) -> &str {
match self {
Self::Nudity => "nudity",
Self::Malware => "malware",
Self::Profanity => "profanity",
Self::Illegal => "illegal",
Self::Spam => "spam",
Self::Impersonation => "impersonation",
Self::Other => "other",
}
}
}
impl FromStr for Report {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"nudity" => Ok(Self::Nudity),
"malware" => Ok(Self::Malware),
"profanity" => Ok(Self::Profanity),
"illegal" => Ok(Self::Illegal),
"spam" => Ok(Self::Spam),
"impersonation" => Ok(Self::Impersonation),
"other" => Ok(Self::Other),
_ => Err(Error::UnknownReportType),
}
}
}