File tree Expand file tree Collapse file tree
crates/stackable-operator/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -137,17 +137,17 @@ impl Deref for Key {
137137}
138138
139139impl Key {
140- /// (Optionally) shortens the `prefix` and `name` to make sure they produce a valid [`Key`].
140+ /// Shortens `name` if needed, so that it does not exceed the maximum key name length.
141+ ///
142+ /// The `prefix` is used as-is: If it isn't already a valid DNS subdomain name, shortening won't
143+ /// make it one. In particular, a prefix must end in a letters-only TLD, but the appended hash
144+ /// adds a hyphen and probably digits, very likely being an invalid result.
141145 ///
142146 /// See [`ensure_max_string_length`] for details on the shortening algorithm.
143147 pub fn shortened_to_valid_length (
144148 prefix : Option < & str > ,
145149 name : impl Into < String > ,
146150 ) -> Result < Self , KeyError > {
147- // Note that we are *not* shortening the prefix: If it isn't already a valid DNS subdomain
148- // name, shortening won't make it one. In particular, a prefix must end in a letters-only
149- // TLD, but the appended hash adds a hyphen and probably digits, very likely being an
150- // invalid result.
151151 let name = ensure_max_string_length ( name, KEY_NAME_MAX_LEN , 8 ) ;
152152
153153 let key = match prefix {
Original file line number Diff line number Diff line change @@ -10,12 +10,17 @@ use sha2::{Digest, Sha256};
1010///
1111/// # Panics
1212///
13- /// Panics if `max_length_bytes < 1 /* character */ + 1 /* dash */ + hash_length`.
13+ /// Panics if the `hash_length > 64` or
14+ /// `max_length_bytes < 1 /* character */ + 1 /* dash */ + hash_length`.
1415pub fn ensure_max_string_length (
1516 original : impl Into < String > ,
1617 max_length_bytes : usize ,
1718 hash_length : usize ,
1819) -> String {
20+ assert ! (
21+ hash_length <= 64 ,
22+ "We hash using sha256, so we don't produce more than 64 bytes"
23+ ) ;
1924 assert ! ( max_length_bytes >= 1 /* character */ + 1 /* dash */ + hash_length) ;
2025
2126 let original = original. into ( ) ;
You can’t perform that action at this time.
0 commit comments