Debian Codegraph @

README.md

raw
1 ICANN RDAP Common
2 =================
3
4 This is a common component library for the Registration Data Access Protocol (RDAP) written and sponsored
5 by the Internet Corporation for Assigned Names and Numbers [(ICANN)](https://www.icann.org).
6 RDAP is standard of the [IETF](https://ietf.org/), and extensions
7 to RDAP are a current work activity of the IETF's [REGEXT working group](https://datatracker.ietf.org/wg/regext/documents/).
8 Read about [ICANN's role in RDAP](https://www.icann.org/rdap).
9 See [general information on RDAP](https://rdap.rcode3.com/).
10
11
12 Installation
13 ------------
14
15 Add the library to your Cargo.toml: `cargo add icann-rdap-common`.
16
17 This library can be compiled for WASM targets.
18
19 Usage
20 -----
21
22 Parse RDAP JSON:
23
24 ```rust
25 use icann_rdap_common::prelude::*;
26
27 let json = r#"
28 {
29 "objectClassName": "ip network",
30 "links": [
31 {
32 "value": "http://localhost:3000/rdap/ip/10.0.0.0/16",
33 "rel": "self",
34 "href": "http://localhost:3000/rdap/ip/10.0.0.0/16",
35 "type": "application/rdap+json"
36 }
37 ],
38 "events": [
39 {
40 "eventAction": "registration",
41 "eventDate": "2023-06-16T22:56:49.594173356+00:00"
42 },
43 {
44 "eventAction": "last changed",
45 "eventDate": "2023-06-16T22:56:49.594189140+00:00"
46 }
47 ],
48 "startAddress": "10.0.0.0",
49 "endAddress": "10.0.255.255",
50 "ipVersion": "v4"
51 }
52 "#;
53
54 let rdap: RdapResponse = serde_json::from_str(json).unwrap();
55 assert!(matches!(rdap, RdapResponse::Network(_)));
56 ```
57
58 Create some RDAP objects:
59
60 ```rust
61 use icann_rdap_common::prelude::*;
62
63 // create a simple entity to be used inside other objects with builder().
64 let holder = Entity::builder().handle("foo-BAR").build();
65
66 // create an RDAP domain response object with response_obj()
67 let domain = Domain::response_obj()
68 .ldh_name("example.com")
69 .extension(ExtensionId::IcannRdapResponseProfile1.as_ref())
70 .extension(ExtensionId::IcannRdapTechnicalImplementationGuide1.as_ref())
71 .notice(Notice::builder()
72 .title("Inaccuracy report")
73 .description_entry("Things may be wrong. But it isn't our fault.")
74 .description_entry("Read the policy for more information.")
75 .build()
76 )
77 .entity(holder.clone())
78 .build();
79
80 // create an IP network to be used as a response with response_obj()
81 let net = Network::response_obj()
82 .cidr("10.0.0.0/16")
83 .entity(holder.clone())
84 .extension(ExtensionId::NroRdapProfile0.as_ref())
85 .notice(Notice::builder().title("test").build())
86 .build()
87 .unwrap();
88
89 // create a nameserver for a response
90 let ns = Nameserver::response_obj()
91 .ldh_name("ns1.example.com")
92 .entity(holder.clone())
93 .extension(ExtensionId::IcannRdapResponseProfile1.as_ref())
94 .extension(ExtensionId::IcannRdapTechnicalImplementationGuide1.as_ref())
95 .notice(Notice::builder().title("Inaccuracy report").build())
96 .build()
97 .unwrap();
98
99 // create an autnum for a response
100 let autnum = Autnum::response_obj()
101 .autnum_range(700..700)
102 .entity(holder)
103 .extension(ExtensionId::NroRdapProfile0.as_ref())
104 .notice(Notice::builder().title("test").build())
105 .build();
106 ```
107
108 RDAP uses jCard, the JSON version of vCard, to model "contact information"
109 (e.g. postal addresses, phone numbers, etc...). Because jCard is difficult
110 to use and there might be other contact models standardized by the IETF,
111 this library includes the [`contact::Contact`] struct. This struct can be
112 converted to and from jCard/vCard with the [`contact::Contact::from_vcard`]
113 and [`contact::Contact::to_vcard`] functions.
114
115 [`contact::Contact`] structs can be built using the builder.
116
117 ```rust
118 use icann_rdap_common::contact::Contact;
119
120 let contact = Contact::builder()
121 .kind("individual")
122 .full_name("Bob Smurd")
123 .build();
124 ```
125
126 Once built, a Contact struct can be converted to an array of [serde_json::Value]'s,
127 which can be used with serde to serialize to JSON.
128
129 ```rust
130 use icann_rdap_common::contact::Contact;
131 use serde::Serialize;
132 use serde_json::Value;
133
134 let contact = Contact::builder()
135 .kind("individual")
136 .full_name("Bob Smurd")
137 .build();
138
139 let v = contact.to_vcard();
140 let json = serde_json::to_string(&v);
141 ```
142
143 To deserialize, use the `from_vcard` function.
144
145 ```rust
146 use icann_rdap_common::contact::Contact;
147 use serde::Deserialize;
148 use serde_json::Value;
149
150 let json = r#"
151 [
152 "vcard",
153 [
154 ["version", {}, "text", "4.0"],
155 ["fn", {}, "text", "Joe User"],
156 ["kind", {}, "text", "individual"],
157 ["org", {
158 "type":"work"
159 }, "text", "Example"],
160 ["title", {}, "text", "Research Scientist"],
161 ["role", {}, "text", "Project Lead"],
162 ["adr",
163 { "type":"work" },
164 "text",
165 [
166 "",
167 "Suite 1234",
168 "4321 Rue Somewhere",
169 "Quebec",
170 "QC",
171 "G1V 2M2",
172 "Canada"
173 ]
174 ],
175 ["tel",
176 { "type":["work", "voice"], "pref":"1" },
177 "uri", "tel:+1-555-555-1234;ext=102"
178 ],
179 ["email",
180 { "type":"work" },
181 "text", "[email protected]"
182 ]
183 ]
184 ]"#;
185
186 let data: Vec<Value> = serde_json::from_str(json).unwrap();
187 let contact = Contact::from_vcard(&data);
188 ```
189
190 ## Using `strum`
191
192 This project uses the [strum](https://crates.io/crates/strum) crate to provide many compile-time
193 utilities for enums. To avoid conflicts with the macros used by strum, this project uses strums
194 "derive" feature. Code depending on this project are recommended to do the same.
195
196 License
197 -------
198
199 Licensed under either of
200 * Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
201 * MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT) at your option.
202
203 Contribution
204 ------------
205
206 Unless you explicitly state otherwise, any contribution, as defined in the Apache-2.0 license,
207 intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license,
208 shall be dual licensed pursuant to the Apache License, Version 2.0 or the MIT License referenced
209 as above, at ICANN’s option, without any additional terms or conditions.