rasn_cap/
lib.rs

1#![doc = include_str!("../README.md")]
2#![no_std]
3
4use rasn::prelude::*;
5
6pub type ValueName = String;
7pub type Value = String;
8pub type DateTime = rasn::types::GeneralizedTime;
9pub type AnyUri = StringWithNoCrlFht;
10
11/// An alert message.
12#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
13#[rasn(automatic_tags)]
14pub struct Alert {
15    /// Unambiguous identification of the message from all messages from this
16    /// sender, in a format defined by the sender and identified in the "sender"
17    /// field below.
18    pub identifier: IdentifierString,
19
20    /// The globally unambiguous identification of the sender. This
21    /// specification does not define the root of a global identification tree
22    /// (there is no international agreement on such a root), so it relies on
23    /// human-readable text to define globally and unambiguously the sender. An
24    /// internet domain name or use of "iri:/ITU-T/..." is possible, but the
25    /// choice needs to be clearly stated in human-readable form.
26    pub sender: String,
27    pub sent: DateTime,
28    pub status: AlertStatus,
29    pub msg_type: AlertMessageType,
30
31    /// Not standardized human-readable identification of the source of
32    /// the alert.
33    pub source: Option<String>,
34    pub scope: AlertScope,
35
36    /// Not standardized human-readable restrictions on the distribution of the
37    /// alert message.
38    pub restriction: Option<String>,
39    /// A space separated list of addresses for private messages.
40    pub addresses: Option<String>,
41    /// Sequence codes for special handling.
42    pub code_list: SequenceOf<String>,
43    /// Not standardized human-readable clarifying text for the alert.
44    pub note: Option<String>,
45    /// Space-separated references to earlier messages.
46    pub references: Option<String>,
47    /// Space-separated references to related incidents.
48    pub incidents: Option<String>,
49    pub info_list: SequenceOf<AlertInformation>,
50}
51
52#[derive(AsnType, Clone, Copy, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
53#[rasn(enumerated)]
54pub enum AlertStatus {
55    Actual,
56    Draft,
57    Exercise,
58    System,
59    Test,
60}
61
62#[derive(AsnType, Clone, Copy, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
63#[rasn(enumerated)]
64pub enum AlertMessageType {
65    Ack,
66    Alert,
67    Cancel,
68    Error,
69    Update,
70}
71
72#[derive(AsnType, Clone, Copy, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
73#[rasn(enumerated)]
74pub enum AlertScope {
75    Private,
76    Public,
77    Restricted,
78}
79
80fn default_alert_language() -> Language {
81    Language("en-US".try_into().unwrap())
82}
83
84#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
85#[rasn(automatic_tags)]
86pub struct AlertEventCode {
87    pub value_name: ValueName,
88    pub value: Value,
89}
90
91#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
92#[rasn(automatic_tags)]
93pub struct AlertParameter {
94    value_name: ValueName,
95    value: Value,
96}
97
98#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
99#[rasn(automatic_tags)]
100pub struct AlertInformation {
101    /// The language used in this value.
102    #[rasn(default = "default_alert_language")]
103    language: Language,
104    #[rasn(size("1.."))]
105    category_list: SequenceOf<InformationCategory>,
106
107    /// Not standardized human-readable text describing the type of the event.
108    event: String,
109    #[rasn(size("0.."))]
110    response_type_list: SequenceOf<InformationResponseType>,
111    urgency: HowUrgent,
112    severity: HowSevere,
113    certainty: HowCertain,
114
115    /// Not standardized human-readable text describing the intended audience
116    /// for the message.
117    audience: Option<String>,
118
119    #[rasn(size("0.."))]
120    event_code_list: SequenceOf<AlertEventCode>,
121    effective: Option<DateTime>,
122    onset: Option<DateTime>,
123    expires: Option<DateTime>,
124
125    /// Not standardized human-readable name of the authority issuing
126    /// the message.
127    sender_name: Option<String>,
128
129    /// Not standardized human-readable short statement (headline) of the alert.
130    #[rasn(size("1..160"), extensible)]
131    headline: Option<String>,
132
133    /// Not standardized human-readable extended description of the event.
134    description: Option<String>,
135    /// Not standardized human-readable recommended action.
136    instruction: Option<String>,
137    web: Option<AnyUri>,
138    /// Not standardized human-readable contact details for follow-up.
139    contact: Option<String>,
140    #[rasn(size("0.."))]
141    parameter_list: SequenceOf<AlertParameter>,
142    #[rasn(size("0.."))]
143    resource_list: SequenceOf<ResourceFile>,
144    #[rasn(size("0.."))]
145    area_list: SequenceOf<Area>,
146}
147
148/// The category of the subject event of the alert message.
149#[derive(AsnType, Copy, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
150#[rasn(enumerated)]
151pub enum InformationCategory {
152    /// Chemical, Biological, Radiological, Nuclear or High-Yield Explosive
153    /// threat or attack
154    Cbrne,
155    /// Pollution and other environmental
156    Env,
157    /// Fire suppression and rescue
158    Fire,
159    /// Geophysical
160    Geo,
161    /// Medical and public health
162    Health,
163    /// Utility, telecommunication, other non-transport infrastructure
164    Infra,
165    /// Meteorological
166    Met,
167    /// Other events
168    Other,
169    /// Rescue and recovery
170    Rescue,
171    /// General emergency and public safety
172    Safety,
173    /// Law enforcement, military, homeland and local/private security
174    Security,
175    /// Public and private transportation
176    Transport,
177}
178
179#[derive(AsnType, Copy, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
180#[rasn(enumerated)]
181pub enum InformationResponseType {
182    Assess,
183    Evacuate,
184    Execute,
185    Monitor,
186    None,
187    Prepare,
188    Shelter,
189}
190
191#[derive(AsnType, Copy, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
192#[rasn(enumerated)]
193pub enum HowUrgent {
194    Expected,
195    Future,
196    Immediate,
197    Past,
198    Unknown,
199}
200
201#[derive(AsnType, Copy, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
202#[rasn(enumerated)]
203pub enum HowSevere {
204    Extreme,
205    Minor,
206    Moderate,
207    Severe,
208    Unknown,
209}
210
211#[derive(AsnType, Copy, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
212#[rasn(enumerated)]
213pub enum HowCertain {
214    Likely,
215    Observed,
216    Possible,
217    Unknown,
218    Unlikely,
219}
220
221#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
222#[rasn(automatic_tags)]
223pub struct ResourceFile {
224    resource_desc: String,
225    mime_type: Option<String>,
226    size: Option<Integer>,
227    uri: Option<AnyUri>,
228    deref_uri: Option<String>,
229    digest: Option<String>,
230}
231
232#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
233#[rasn(automatic_tags)]
234pub struct Area {
235    area_desc: String,
236    polygon_list: SequenceOf<String>,
237    circle_list: SequenceOf<String>,
238    #[rasn(size("0.."))]
239    geocode_list: SequenceOf<Geocode>,
240    altitude: Option<String>,
241    ceiling: Option<String>,
242}
243
244#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
245#[rasn(automatic_tags)]
246pub struct Geocode {
247    value_name: ValueName,
248    value: Value,
249}
250
251#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
252#[rasn(from(
253    "\u{0009}",
254    "\u{000A}",
255    "\u{000D}",
256    "\u{0020}..\u{D7FF}",
257    "\u{E000}..\u{FFFD}",
258    "\u{10000}..\u{10FFFD}"
259))]
260#[rasn(delegate)]
261pub struct String(Utf8String);
262
263#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
264#[rasn(size(1))]
265#[rasn(delegate)]
266pub struct StringChar(String);
267
268#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
269#[rasn(from("\u{0020}", "\u{002C}"))]
270#[rasn(delegate)]
271pub struct SpaceAndComma(Utf8String);
272
273#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
274#[rasn(delegate)]
275pub struct IdentifierString(StringChar);
276
277#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
278#[rasn(from("a..z", "A..Z", "-", "0..9"))]
279#[rasn(delegate)]
280pub struct Language(VisibleString);
281
282#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
283#[rasn(from("\u{20}..\u{D7FF}", "\u{E000}..\u{FFFD}", "\u{10000}..\u{100000}"))]
284#[rasn(delegate)]
285pub struct StringWithNoCrlFht(Utf8String);