pub struct ApiKey(/* private fields */);Expand description
A TypeSafe API key.
The key is wiped from memory when the value is dropped, and nothing in this crate prints it:
Debug shows a placeholder, and there is deliberately no Display, Serialize or PartialEq.
The only way to read it is ApiKey::expose, which keeps every use easy to find and review.
Wiping is best effort. The HTTP stack keeps its own copy of the Authorization header while a
transport is alive, and that copy is outside this type’s control.
use jev_client::ApiKey;
let key = ApiKey::new(String::from("example-key\n")).unwrap();
assert_eq!(key.expose(), "example-key");
assert_eq!(format!("{key:?}"), "ApiKey([REDACTED])");Implementations§
Source§impl ApiKey
impl ApiKey
Sourcepub fn new(key: String) -> Result<Self, InvalidApiKey>
pub fn new(key: String) -> Result<Self, InvalidApiKey>
Wraps a key, trimming surrounding whitespace such as the newline a file or a pipe leaves.
The string is taken by value so that the caller’s copy is consumed; the original buffer is wiped before this returns.
§Errors
Fails when the key is empty, or contains anything other than visible ASCII characters, which could not be sent in an HTTP header. The error never contains the key.