Skip to content

Commit 32fb08e

Browse files
committed
Update docs
1 parent 0c8b4fc commit 32fb08e

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

crates/stackable-operator/src/kvp/key.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,17 @@ impl Deref for Key {
137137
}
138138

139139
impl 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 {

crates/stackable-operator/src/utils/length_enforcement.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff 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`.
1415
pub 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();

0 commit comments

Comments
 (0)