Debian Codegraph @

src/serialize/txt/rdata_parsers/svcb.rs

raw symbols SCIP
1 // Copyright 2015-2023 Benjamin Fry <[email protected]>
2 //
3 // Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
4 // https://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5 // https://opensource.org/licenses/MIT>, at your option. This file may not be
6 // copied, modified, or distributed except according to those terms.
7
8 //! SVCB records in presentation format
9
10 use alloc::{
11 string::{String, ToString},
12 vec::Vec,
13 };
14 use core::str::FromStr;
15
16 use crate::{
17 rr::{
18 Name,
19 rdata::{A, AAAA, svcb::*},
20 },
21 serialize::txt::{
22 Lexer, Token,
23 errors::{ParseError, ParseResult},
24 },
25 };
26
27 /// [RFC 9460 SVCB and HTTPS Resource Records, Nov 2023](https://datatracker.ietf.org/doc/html/rfc9460#section-2.1)
28 ///
29 /// ```text
30 /// 2.1. Zone file presentation format
31 ///
32 /// The presentation format <RDATA> of the record ([RFC1035]) has the form:
33 ///
34 /// SvcPriority TargetName SvcParams
35 ///
36 /// The SVCB record is defined specifically within the Internet ("IN")
37 /// Class ([RFC1035]).
38 ///
39 /// SvcPriority is a number in the range 0-65535, TargetName is a
40 /// <domain-name> ([RFC1035], Section 5.1), and the SvcParams are
41 /// a whitespace-separated list, with each SvcParam consisting of a
42 /// SvcParamKey=SvcParamValue pair or a standalone SvcParamKey.
43 /// SvcParamKeys are registered by IANA (Section 14.3).
44 ///
45 /// Each SvcParamKey SHALL appear at most once in the SvcParams. In
46 /// presentation format, SvcParamKeys are lowercase alphanumeric
47 /// strings. Key names should contain 1-63 characters from the ranges
48 /// "a"-"z", "0"-"9", and "-". In ABNF [RFC5234],
49 ///
50 /// alpha-lc = %x61-7A ; a-z
51 /// SvcParamKey = 1*63(alpha-lc / DIGIT / "-")
52 /// SvcParam = SvcParamKey ["=" SvcParamValue]
53 /// SvcParamValue = char-string ; See Appendix A.
54 /// value = *OCTET ; Value before key-specific parsing
55 ///
56 /// The SvcParamValue is parsed using the character-string decoding
57 /// algorithm (Appendix A), producing a value. The value is then
58 /// validated and converted into wire-format in a manner specific to each
59 /// key.
60 ///
61 /// When the optional "=" and SvcParamValue are omitted, the value is
62 /// interpreted as empty.
63 ///
64 /// Arbitrary keys can be represented using the unknown-key presentation
65 /// format "keyNNNNN" where NNNNN is the numeric value of the key type
66 /// without leading zeros. A SvcParam in this form SHALL be parsed as
67 /// specified above, and the decoded value SHALL be used as its wire-format
68 /// encoding.
69 ///
70 /// For some SvcParamKeys, the value corresponds to a list or set of
71 /// items. Presentation formats for such keys SHOULD use a comma-
72 /// separated list (Appendix A.1).
73 ///
74 /// SvcParams in presentation format MAY appear in any order, but keys
75 /// MUST NOT be repeated.
76 /// ```
77 pub(crate) fn parse<'i, I: Iterator<Item = &'i str>>(mut tokens: I) -> ParseResult<SVCB> {
78 // SvcPriority
79 let svc_priority: u16 = tokens
80 .next()
81 .ok_or_else(|| ParseError::MissingToken("SvcPriority".to_string()))
82 .and_then(|s| s.parse().map_err(Into::into))?;
83
84 // svcb target
85 let target_name: Name = tokens
86 .next()
87 .ok_or_else(|| ParseError::MissingToken("Target".to_string()))
88 .and_then(|s| Name::from_str(s).map_err(ParseError::from))?;
89
90 // Loop over all of the service parameters
91 let mut svc_params = Vec::new();
92 for token in tokens {
93 // first need to split the key and (optional) value
94 let mut key_value = token.splitn(2, '=');
95 let key = key_value
96 .next()
97 .ok_or_else(|| ParseError::MissingToken("SVCB SvcbParams missing".to_string()))?;
98
99 // get the value, and remove any quotes
100 let mut value = key_value.next();
101 if let Some(value) = value.as_mut() {
102 if value.starts_with('"') && value.ends_with('"') {
103 *value = &value[1..value.len() - 1];
104 }
105 }
106 svc_params.push(into_svc_param(key, value)?);
107 }
108
109 Ok(SVCB::new(svc_priority, target_name, svc_params))
110 }
111
112 // first take the param and convert to
113 fn into_svc_param(
114 key: &str,
115 value: Option<&str>,
116 ) -> Result<(SvcParamKey, SvcParamValue), ParseError> {
117 let key = SvcParamKey::from_str(key)?;
118 let value = parse_value(key, value)?;
119
120 Ok((key, value))
121 }
122
123 fn parse_value(key: SvcParamKey, value: Option<&str>) -> Result<SvcParamValue, ParseError> {
124 match key {
125 SvcParamKey::Mandatory => parse_mandatory(value),
126 SvcParamKey::Alpn => parse_alpn(value),
127 SvcParamKey::NoDefaultAlpn => parse_no_default_alpn(value),
128 SvcParamKey::Port => parse_port(value),
129 SvcParamKey::Ipv4Hint => parse_ipv4_hint(value),
130 SvcParamKey::Ipv6Hint => parse_ipv6_hint(value),
131 SvcParamKey::EchConfigList => parse_ech_config(value),
132 SvcParamKey::Key(_) => parse_unknown(value),
133 SvcParamKey::Key65535 | SvcParamKey::Unknown(_) => Err(ParseError::Message(
134 "Bad Key type or unsupported, see generic key option, e.g. key1234",
135 )),
136 }
137 }
138
139 fn parse_char_data(value: &str) -> Result<String, ParseError> {
140 let mut lex = Lexer::new(value);
141 let ch_data = lex
142 .next_token()?
143 .ok_or(ParseError::Message("expected character data"))?;
144
145 match ch_data {
146 Token::CharData(data) => Ok(data),
147 _ => Err(ParseError::Message("expected character data")),
148 }
149 }
150
151 /// [RFC 9460 SVCB and HTTPS Resource Records, Nov 2023](https://datatracker.ietf.org/doc/html/rfc9460#section-8)
152 ///
153 /// ```text
154 /// The presentation value SHALL be a comma-separated list
155 /// (Appendix A.1) of one or more valid SvcParamKeys, either by their
156 /// registered name or in the unknown-key format (Section 2.1). Keys MAY
157 /// appear in any order, but MUST NOT appear more than once. For self-
158 /// consistency (Section 2.4.3), listed keys MUST also appear in the
159 /// SvcParams.
160 ///
161 /// To enable simpler parsing, this SvcParamValue MUST NOT contain escape
162 /// sequences.
163 ///
164 /// For example, the following is a valid list of SvcParams:
165 ///
166 /// ipv6hint=... key65333=ex1 key65444=ex2 mandatory=key65444,ipv6hint
167 /// ```
168 ///
169 /// Currently this does not validate that the mandatory section matches the other keys
170 fn parse_mandatory(value: Option<&str>) -> Result<SvcParamValue, ParseError> {
171 let value = value.ok_or(ParseError::Message("expected at least one Mandatory field"))?;
172
173 let mandatories = parse_list::<SvcParamKey>(value)?;
174 Ok(SvcParamValue::Mandatory(Mandatory(mandatories)))
175 }
176
177 /// [RFC 9460 SVCB and HTTPS Resource Records, Nov 2023](https://datatracker.ietf.org/doc/html/rfc9460#section-7.1.1)
178 ///
179 /// ```text
180 /// ALPNs are identified by their registered "Identification Sequence"
181 /// (alpn-id), which is a sequence of 1-255 octets.
182 ///
183 /// alpn-id = 1*255OCTET
184 ///
185 /// For "alpn", the presentation value SHALL be a comma-separated list
186 /// (Appendix A.1) of one or more alpn-ids.
187 /// ```
188 ///
189 /// This does not currently check to see if the ALPN code is legitimate
190 fn parse_alpn(value: Option<&str>) -> Result<SvcParamValue, ParseError> {
191 let value = value.ok_or(ParseError::Message("expected at least one ALPN code"))?;
192
193 let alpns = parse_list::<String>(value).expect("infallible");
194 Ok(SvcParamValue::Alpn(Alpn(alpns)))
195 }
196
197 /// [RFC 9460 SVCB and HTTPS Resource Records, Nov 2023](https://datatracker.ietf.org/doc/html/rfc9460#section-7.1.1)
198 ///
199 /// ```text
200 /// For "no-default-alpn", the presentation and wire format values MUST
201 /// be empty. When "no-default-alpn" is specified in an RR, "alpn" must
202 /// also be specified in order for the RR to be "self-consistent"
203 /// (Section 2.4.3).
204 /// ```
205 fn parse_no_default_alpn(value: Option<&str>) -> Result<SvcParamValue, ParseError> {
206 if value.is_some() {
207 return Err(ParseError::Message("no value expected for NoDefaultAlpn"));
208 }
209
210 Ok(SvcParamValue::NoDefaultAlpn)
211 }
212
213 /// [RFC 9460 SVCB and HTTPS Resource Records, Nov 2023](https://datatracker.ietf.org/doc/html/rfc9460#section-7.2)
214 ///
215 /// ```text
216 /// The presentation value of the SvcParamValue is a single decimal
217 /// integer between 0 and 65535 in ASCII. Any other value (e.g. an
218 /// empty value) is a syntax error. To enable simpler parsing, this
219 /// SvcParam MUST NOT contain escape sequences.
220 /// ```
221 fn parse_port(value: Option<&str>) -> Result<SvcParamValue, ParseError> {
222 let value = value.ok_or(ParseError::Message("a port number for the port option"))?;
223
224 let value = parse_char_data(value)?;
225 let port = u16::from_str(&value)?;
226 Ok(SvcParamValue::Port(port))
227 }
228
229 /// [RFC 9460 SVCB and HTTPS Resource Records, Nov 2023](https://datatracker.ietf.org/doc/html/rfc9460#section-7.3)
230 ///
231 /// ```text
232 /// The presentation value SHALL be a comma-separated list
233 /// (Appendix A.1) of one or more IP addresses of the appropriate family
234 /// in standard textual format [RFC5952]. To enable simpler parsing,
235 /// this SvcParamValue MUST NOT contain escape sequences.
236 /// ```
237 fn parse_ipv4_hint(value: Option<&str>) -> Result<SvcParamValue, ParseError> {
238 let value = value.ok_or(ParseError::Message("expected at least one ipv4 hint"))?;
239
240 let hints = parse_list::<A>(value)?;
241 Ok(SvcParamValue::Ipv4Hint(IpHint(hints)))
242 }
243
244 /// [RFC 9460 SVCB and HTTPS Resource Records, Nov 2023](https://datatracker.ietf.org/doc/html/rfc9460#section-7.3)
245 ///
246 /// ```text
247 /// The presentation value SHALL be a comma-separated list
248 /// (Appendix A.1) of one or more IP addresses of the appropriate family
249 /// in standard textual format [RFC5952]. To enable simpler parsing,
250 /// this SvcParamValue MUST NOT contain escape sequences.
251 /// ```
252 fn parse_ipv6_hint(value: Option<&str>) -> Result<SvcParamValue, ParseError> {
253 let value = value.ok_or(ParseError::Message("expected at least one ipv6 hint"))?;
254
255 let hints = parse_list::<AAAA>(value)?;
256 Ok(SvcParamValue::Ipv6Hint(IpHint(hints)))
257 }
258
259 /// As the documentation states, the presentation format (what this function outputs) must be a BASE64 encoded string.
260 /// hickory-dns will encode to BASE64 during formatting of the internal data, and output the BASE64 value.
261 ///
262 /// [draft-ietf-tls-svcb-ech-01 Bootstrapping TLS Encrypted ClientHello with DNS Service Bindings, Sep 2024](https://datatracker.ietf.org/doc/html/draft-ietf-tls-svcb-ech-01)
263 /// ```text
264 /// In presentation format, the value is the ECHConfigList in Base 64 Encoding
265 /// (Section 4 of [RFC4648]). Base 64 is used here to simplify integration with
266 /// TLS server software. To enable simpler parsing, this SvcParam MUST NOT
267 /// contain escape sequences.
268 /// ```
269 fn parse_ech_config(value: Option<&str>) -> Result<SvcParamValue, ParseError> {
270 let value = value.ok_or(ParseError::Message(
271 "expected a base64 encoded string for EchConfig",
272 ))?;
273
274 let value = parse_char_data(value)?;
275 let ech_config_bytes = data_encoding::BASE64.decode(value.as_bytes())?;
276 Ok(SvcParamValue::EchConfigList(EchConfigList(
277 ech_config_bytes,
278 )))
279 }
280
281 /// [RFC 9460 SVCB and HTTPS Resource Records, Nov 2023](https://datatracker.ietf.org/doc/html/rfc9460#section-2.1)
282 ///
283 /// ```text
284 /// Arbitrary keys can be represented using the unknown-key presentation
285 /// format "keyNNNNN" where NNNNN is the numeric value of the key type
286 /// without leading zeros. A SvcParam in this form SHALL be parsed as specified
287 /// above, and the decoded value SHALL be used as its wire-format encoding.
288 ///
289 /// For some SvcParamKeys, the value corresponds to a list or set of
290 /// items. Presentation formats for such keys SHOULD use a comma-
291 /// separated list (Appendix A.1).
292 ///
293 /// SvcParams in presentation format MAY appear in any order, but keys
294 /// MUST NOT be repeated.
295 /// ```
296 fn parse_unknown(value: Option<&str>) -> Result<SvcParamValue, ParseError> {
297 let unknown: Vec<u8> = if let Some(value) = value {
298 value.as_bytes().to_vec()
299 } else {
300 Vec::new()
301 };
302
303 Ok(SvcParamValue::Unknown(Unknown(unknown)))
304 }
305
306 fn parse_list<T>(value: &str) -> Result<Vec<T>, ParseError>
307 where
308 T: FromStr,
309 T::Err: Into<ParseError>,
310 {
311 let mut result = Vec::new();
312 let mut current_value = String::new();
313 let mut escaping = false;
314
315 for c in value.chars() {
316 match (c, escaping) {
317 // End of value
318 (',', false) => {
319 result.push(T::from_str(&parse_char_data(&current_value)?).map_err(Into::into)?);
320 current_value.clear()
321 }
322 // Start of escape sequence
323 ('\\', false) => escaping = true,
324 // Comma inside escape sequence
325 (',', true) => {
326 current_value.push(',');
327 escaping = false
328 }
329 // Regular character inside escape sequence
330 (_, true) => {
331 current_value.push(c);
332 escaping = false
333 }
334 // Regular character
335 (_, false) => current_value.push(c),
336 }
337 }
338
339 // Push the remaining value if there's any
340 if !current_value.is_empty() {
341 result.push(T::from_str(&parse_char_data(&current_value)?).map_err(Into::into)?);
342 }
343
344 Ok(result)
345 }
346
347 #[cfg(test)]
348 mod tests {
349 use alloc::borrow::ToOwned;
350 use alloc::string::ToString;
351
352 use crate::{
353 rr::{RecordData, rdata::HTTPS},
354 serialize::txt::Parser,
355 };
356
357 use super::*;
358
359 // this assumes that only a single record is parsed
360 // TODO: make Parser return an iterator over all records in a stream.
361 fn parse_record<D: RecordData>(txt: &str) -> D {
362 let records = Parser::new(txt, None, Some(Name::root()))
363 .parse()
364 .expect("failed to parse record")
365 .1;
366 let record_set = records.into_iter().next().expect("no record found").1;
367 D::try_borrow(&record_set.into_iter().next().unwrap().data)
368 .expect("Not the correct record")
369 .clone()
370 }
371
372 #[test]
373 fn test_parsing() {
374 let svcb: HTTPS = parse_record(CF_HTTPS_RECORD);
375
376 assert_eq!(svcb.svc_priority, 1);
377 assert_eq!(svcb.target_name, Name::root());
378
379 let mut params = svcb.svc_params.iter();
380
381 // alpn
382 let param = params.next().expect("not alpn");
383 assert_eq!(param.0, SvcParamKey::Alpn);
384 let SvcParamValue::Alpn(value) = &param.1 else {
385 panic!("expected alpn");
386 };
387 assert_eq!(value.0, &["http/1.1", "h2"]);
388
389 // ipv4 hint
390 let param = params.next().expect("ipv4hint");
391 assert_eq!(SvcParamKey::Ipv4Hint, param.0);
392 let SvcParamValue::Ipv4Hint(value) = &param.1 else {
393 panic!("expected ipv4hint");
394 };
395 assert_eq!(
396 value.0,
397 &[A::new(162, 159, 137, 85), A::new(162, 159, 138, 85)]
398 );
399
400 // echconfig
401 let param = params.next().expect("echconfig");
402 assert_eq!(SvcParamKey::EchConfigList, param.0);
403 let SvcParamValue::EchConfigList(value) = &param.1 else {
404 panic!("expected echconfig");
405 };
406 assert_eq!(
407 value.0,
408 data_encoding::BASE64.decode(b"AEX+DQBBtgAgACBMmGJQR02doup+5VPMjYpe5HQQ/bpntFCxDa8LT2PLAgAEAAEAAQASY2xvdWRmbGFyZS1lY2guY29tAAA=").unwrap()
409 );
410
411 // ipv6 hint
412 let param = params.next().expect("ipv6hint");
413 assert_eq!(SvcParamKey::Ipv6Hint, param.0);
414 let SvcParamValue::Ipv6Hint(value) = &param.1 else {
415 panic!("expected ipv6hint");
416 };
417 assert_eq!(
418 value.0,
419 &[
420 AAAA::new(0x2606, 0x4700, 0x7, 0, 0, 0, 0xa29f, 0x8955),
421 AAAA::new(0x2606, 0x4700, 0x7, 0, 0, 0, 0xa29f, 0x8a5)
422 ]
423 );
424 }
425
426 #[test]
427 fn test_parse_display() {
428 let svcb: SVCB = parse_record(CF_SVCB_RECORD);
429
430 let svcb_display = svcb.to_string();
431
432 // add back the name, etc...
433 let svcb_display = format!("crypto.cloudflare.com. 299 IN SVCB {svcb_display}");
434 let svcb_display = parse_record(&svcb_display);
435
436 assert_eq!(svcb, svcb_display);
437 }
438
439 /// sanity check for https
440 #[test]
441 fn test_parsing_https() {
442 let records = [GOOGLE_HTTPS_RECORD, CF_HTTPS_RECORD];
443 for record in records.iter() {
444 let svcb: HTTPS = parse_record(record);
445
446 assert_eq!(svcb.svc_priority, 1);
447 assert_eq!(svcb.target_name, Name::root());
448 }
449 }
450
451 /// Test with RFC 9460 Appendix D test vectors
452 /// <https://datatracker.ietf.org/doc/html/rfc9460#appendix-D>
453 // TODO(XXX): Consider adding the negative "Failure Cases" from D.3.
454 #[test]
455 fn test_rfc9460_vectors() {
456 #[derive(Debug)]
457 struct TestVector {
458 record: &'static str,
459 record_type: RecordType,
460 target_name: Name,
461 priority: u16,
462 params: Vec<(SvcParamKey, SvcParamValue)>,
463 }
464
465 #[derive(Debug)]
466 enum RecordType {
467 SVCB,
468 HTTPS,
469 }
470
471 // NOTE: In each case the test vector from the RFC was augmented with a TTL (42 in each
472 // case). The parser requires this but the test vectors do not include it.
473 let vectors: [TestVector; 9] = [
474 // https://datatracker.ietf.org/doc/html/rfc9460#appendix-D.1
475 // Figure 2: AliasMode
476 TestVector {
477 record: "example.com. 42 HTTPS 0 foo.example.com.",
478 record_type: RecordType::HTTPS,
479 target_name: Name::from_str("foo.example.com.").unwrap(),
480 priority: 0,
481 params: Vec::new(),
482 },
483 // https://datatracker.ietf.org/doc/html/rfc9460#appendix-D.2
484 // Figure 3: TargetName Is "."
485 TestVector {
486 record: "example.com. 42 SVCB 1 .",
487 record_type: RecordType::SVCB,
488 target_name: Name::from_str(".").unwrap(),
489 priority: 1,
490 params: Vec::new(),
491 },
492 // Figure 4: Specifies a Port
493 TestVector {
494 record: "example.com. 42 SVCB 16 foo.example.com. port=53",
495 record_type: RecordType::SVCB,
496 target_name: Name::from_str("foo.example.com.").unwrap(),
497 priority: 16,
498 params: vec![(SvcParamKey::Port, SvcParamValue::Port(53))],
499 },
500 // Figure 5: A Generic Key and Unquoted Value
501 TestVector {
502 record: "example.com. 42 SVCB 1 foo.example.com. key667=hello",
503 record_type: RecordType::SVCB,
504 target_name: Name::from_str("foo.example.com.").unwrap(),
505 priority: 1,
506 params: vec![(
507 SvcParamKey::Key(667),
508 SvcParamValue::Unknown(Unknown(b"hello".into())),
509 )],
510 },
511 // Figure 6: A Generic Key and Quoted Value with a Decimal Escape
512 TestVector {
513 record: r#"example.com. 42 SVCB 1 foo.example.com. key667="hello\210qoo""#,
514 record_type: RecordType::SVCB,
515 target_name: Name::from_str("foo.example.com.").unwrap(),
516 priority: 1,
517 params: vec![(
518 SvcParamKey::Key(667),
519 SvcParamValue::Unknown(Unknown(b"hello\\210qoo".into())),
520 )],
521 },
522 // Figure 7: Two Quoted IPv6 Hints
523 TestVector {
524 record: r#"example.com. 42 SVCB 1 foo.example.com. (ipv6hint="2001:db8::1,2001:db8::53:1")"#,
525 record_type: RecordType::SVCB,
526 target_name: Name::from_str("foo.example.com.").unwrap(),
527 priority: 1,
528 params: vec![(
529 SvcParamKey::Ipv6Hint,
530 SvcParamValue::Ipv6Hint(IpHint(vec![
531 AAAA::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1),
532 AAAA::new(0x2001, 0xdb8, 0, 0, 0, 0, 0x53, 1),
533 ])),
534 )],
535 },
536 // Figure 8: An IPv6 Hint Using the Embedded IPv4 Syntax
537 TestVector {
538 record: r#"example.com. 42 SVCB 1 example.com. (ipv6hint="2001:db8:122:344::192.0.2.33")"#,
539 record_type: RecordType::SVCB,
540 target_name: Name::from_str("example.com.").unwrap(),
541 priority: 1,
542 params: vec![(
543 SvcParamKey::Ipv6Hint,
544 SvcParamValue::Ipv6Hint(IpHint(vec![AAAA::new(
545 0x2001, 0xdb8, 0x122, 0x344, 0, 0, 0xc000, 0x221,
546 )])),
547 )],
548 },
549 // Figure 9: SvcParamKey Ordering Is Arbitrary in Presentation Format but Sorted in Wire Format
550 TestVector {
551 record: r#"example.com. 42 SVCB 16 foo.example.org. (alpn=h2,h3-19 mandatory=ipv4hint,alpn ipv4hint=192.0.2.1)"#,
552 record_type: RecordType::SVCB,
553 target_name: Name::from_str("foo.example.org.").unwrap(),
554 priority: 16,
555 params: vec![
556 (
557 SvcParamKey::Alpn,
558 SvcParamValue::Alpn(Alpn(vec!["h2".to_owned(), "h3-19".to_owned()])),
559 ),
560 (
561 SvcParamKey::Mandatory,
562 SvcParamValue::Mandatory(Mandatory(vec![
563 SvcParamKey::Ipv4Hint,
564 SvcParamKey::Alpn,
565 ])),
566 ),
567 (
568 SvcParamKey::Ipv4Hint,
569 SvcParamValue::Ipv4Hint(IpHint(vec![A::new(192, 0, 2, 1)])),
570 ),
571 ],
572 },
573 // Figure 10: An "alpn" Value with an Escaped Comma and an Escaped Backslash in Two Presentation Formats
574 TestVector {
575 record: r#"example.com. 42 SVCB 16 foo.example.org. alpn="f\\\\oo\,bar,h2""#,
576 record_type: RecordType::SVCB,
577 target_name: Name::from_str("foo.example.org.").unwrap(),
578 priority: 16,
579 params: vec![(
580 SvcParamKey::Alpn,
581 SvcParamValue::Alpn(Alpn(vec![r#"f\\oo,bar"#.to_owned(), "h2".to_owned()])),
582 )],
583 },
584 /*
585 * TODO(XXX): Parser does not replace escaped characters, does not see "\092," as
586 * an escaped delim.
587 TestVector {
588 record: r#"example.com. 42 SVCB 116 foo.example.org. alpn=f\\\092oo\092,bar,h2""#,
589 record_type: RecordType::SVCB,
590 target_name: Name::from_str("foo.example.org.").unwrap(),
591 priority: 16,
592 params: vec![(
593 SvcParamKey::Alpn,
594 SvcParamValue::Alpn(Alpn(vec![r#"f\\oo,bar"#.to_owned(), "h2".to_owned()])),
595 )],
596 },
597 */
598 ];
599
600 for record in vectors {
601 let expected_scvb = SVCB::new(record.priority, record.target_name, record.params);
602 match record.record_type {
603 RecordType::SVCB => {
604 let parsed: SVCB = parse_record(record.record);
605 assert_eq!(parsed, expected_scvb);
606 }
607 RecordType::HTTPS => {
608 let parsed: HTTPS = parse_record(record.record);
609 assert_eq!(parsed, HTTPS(expected_scvb));
610 }
611 };
612 }
613 }
614
615 const CF_SVCB_RECORD: &str = "crypto.cloudflare.com. 1664 IN SVCB 1 . alpn=\"http/1.1,h2\" ipv4hint=162.159.137.85,162.159.138.85 ech=AEX+DQBBtgAgACBMmGJQR02doup+5VPMjYpe5HQQ/bpntFCxDa8LT2PLAgAEAAEAAQASY2xvdWRmbGFyZS1lY2guY29tAAA= ipv6hint=2606:4700:7::a29f:8955,2606:4700:7::a29f:8a5";
616 const CF_HTTPS_RECORD: &str = "crypto.cloudflare.com. 1664 IN HTTPS 1 . alpn=\"http/1.1,h2\" ipv4hint=162.159.137.85,162.159.138.85 ech=AEX+DQBBtgAgACBMmGJQR02doup+5VPMjYpe5HQQ/bpntFCxDa8LT2PLAgAEAAEAAQASY2xvdWRmbGFyZS1lY2guY29tAAA= ipv6hint=2606:4700:7::a29f:8955,2606:4700:7::a29f:8a5";
617 const GOOGLE_HTTPS_RECORD: &str = "google.com 21132 IN HTTPS 1 . alpn=\"h2,h3\"";
618 }