proto: fix parse of arbitrary keys in pres. syntax
Previously the `FromStr` impl for `SvcParamKey` had support for parsing the "arbitrary key" presentation syntax where a key can be specified "keyNNNNN", where NNNNN is the numeric value of the key type without leading zeros. The existing code would pull out the numeric component into a `u16` and then use the `TryFrom<u16>` impl for `SvcParamKey` to get the key. However, the `TryFrom<u16>` impl for `SvcParamKey` was using the IANA service parameter keys registry to map from u16s to `SvcParamKey`. Values 0..6 are mapped to the known key entries. The reserved range (65280-65534) was mapped to `SvcParamKey::Key`, and 65535 was mapped to `SvcParamKey::Key65535`. This makes sense when mapping an arbitrary u16, but when we are parsing a "keyNNNNN" presentation syntax item, we want to represent it as `Key(NNNNN)`, no matter if it is/isn't a registered key. This commit fixes this behaviour, constructing a `SvcParamKey::Key()` entry when parsing the arbitrary key presentation syntax, avoiding `TryFrom<u16>`. With this change in place the two arbitrary key test vectors can be included in the svcb test vector unit test. [0] https://datatracker.ietf.org/doc/html/rfc9460#name-initial-contents
This commit is contained in:
parent
2913b659e3
commit
2a91cdb066
|
@ -307,9 +307,7 @@ impl std::str::FromStr for SvcParamKey {
|
|||
)))
|
||||
})?;
|
||||
|
||||
let key_value = u16::from_str(key_value)?;
|
||||
let key = SvcParamKey::from(key_value);
|
||||
Ok(key)
|
||||
Ok(SvcParamKey::Key(u16::from_str(key_value)?))
|
||||
}
|
||||
|
||||
let key = match s {
|
||||
|
|
|
@ -452,7 +452,7 @@ mod tests {
|
|||
|
||||
// NOTE: In each case the test vector from the RFC was augmented with a TTL (42 in each
|
||||
// case). The parser requires this but the test vectors do not include it.
|
||||
let vectors: [TestVector; 6] = [
|
||||
let vectors: [TestVector; 8] = [
|
||||
// https://datatracker.ietf.org/doc/html/rfc9460#appendix-D.1
|
||||
// Figure 2: AliasMode
|
||||
TestVector {
|
||||
|
@ -479,8 +479,6 @@ mod tests {
|
|||
priority: 16,
|
||||
params: vec![(SvcParamKey::Port, SvcParamValue::Port(53))],
|
||||
},
|
||||
/*
|
||||
* TODO(XXX): ParseError { kind: Message("Bad Key type or unsupported, see generic key option, e.g. key1234"), backtrack: None }
|
||||
// Figure 5: A Generic Key and Unquoted Value
|
||||
TestVector {
|
||||
record: "example.com. 42 SVCB 1 foo.example.com. key667=hello",
|
||||
|
@ -503,7 +501,6 @@ mod tests {
|
|||
SvcParamValue::Unknown(Unknown(b"hello\\210qoo".into())),
|
||||
)],
|
||||
},
|
||||
*/
|
||||
// Figure 7: Two Quoted IPv6 Hints
|
||||
TestVector {
|
||||
record: r#"example.com. 42 SVCB 1 foo.example.com. (ipv6hint="2001:db8::1,2001:db8::53:1")"#,
|
||||
|
|
Loading…
Reference in New Issue
Block a user