pub struct ApiKey(/* private fields */);Expand description
API key (validated, never logged or displayed).
This type ensures API keys are:
- Validated on construction
- Never logged in Debug output
- Never serialized in plain text
- Only exposed through explicit
expose()method
§Example
use simple_agent_type::validation::ApiKey;
let key = ApiKey::new("sk-1234567890abcdef1234567890").unwrap();
let debug_str = format!("{:?}", key);
assert!(debug_str.contains("REDACTED"));
assert!(!debug_str.contains("sk-"));Implementations§
Source§impl ApiKey
impl ApiKey
Sourcepub fn new(key: impl Into<String>) -> Result<Self>
pub fn new(key: impl Into<String>) -> Result<Self>
Create a new API key with validation.
§Validation Rules
- Must not be empty
- Must be at least 20 characters
- Must not contain null bytes (security)
§Example
use simple_agent_type::validation::ApiKey;
let key = ApiKey::new("sk-1234567890abcdef1234567890");
assert!(key.is_ok());
let invalid = ApiKey::new("short");
assert!(invalid.is_err());Sourcepub fn expose(&self) -> &str
pub fn expose(&self) -> &str
Expose the raw API key.
§Security Warning
Only use this when actually making API requests. Never log or display the result.
§Example
use simple_agent_type::validation::ApiKey;
let key = ApiKey::new("sk-1234567890abcdef1234567890").unwrap();
let raw = key.expose();
assert_eq!(raw, "sk-1234567890abcdef1234567890");Sourcepub fn preview(&self) -> String
pub fn preview(&self) -> String
Get a redacted preview of the key (for debugging).
Shows only the prefix and length.
§Example
use simple_agent_type::validation::ApiKey;
let key = ApiKey::new("sk-1234567890abcdef1234567890").unwrap();
let preview = key.preview();
assert!(preview.contains("sk-"));
assert!(preview.contains("29 chars"));Trait Implementations§
Source§impl<'de> Deserialize<'de> for ApiKey
impl<'de> Deserialize<'de> for ApiKey
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for ApiKey
Auto Trait Implementations§
impl Freeze for ApiKey
impl RefUnwindSafe for ApiKey
impl Send for ApiKey
impl Sync for ApiKey
impl Unpin for ApiKey
impl UnwindSafe for ApiKey
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more