//! Subject validation for key encoding.

use crate::error::{Result, StorageError};

use super::SEPARATOR;

/// Validate that a subject string does not contain the separator byte.
///
/// Subjects containing `\x00` would corrupt key boundaries. This MUST be
/// called on all inbound subjects at the ingestion boundary.
pub fn validate_subject(subject: &str) -> Result<()> {
    if subject.as_bytes().contains(&SEPARATOR) {
        return Err(StorageError::InputValidation(
            "Subject must not contain null byte (\\x00)".to_string(),
        ));
    }
    if subject.is_empty() {
        return Err(StorageError::InputValidation("Subject must not be empty".to_string()));
    }
    Ok(())
}
