pub struct Credential { /* private fields */ }Expand description
L2 API credential with HMAC-SHA256 signing for authenticated requests.
Stores the API key as Ustr (interned, used for lookups) and the
decoded secret as Box<[u8]> (zeroized on drop). The base64 secret
is decoded once at construction to avoid repeated decoding per request.
Implementations§
Source§impl Credential
impl Credential
Sourcepub fn new(api_key: &str, api_secret: &str, passphrase: String) -> Result<Self>
pub fn new(api_key: &str, api_secret: &str, passphrase: String) -> Result<Self>
Creates a new credential. The api_secret must be base64-encoded.
pub fn api_key(&self) -> Ustr
pub fn passphrase(&self) -> &str
Sourcepub fn api_secret(&self) -> String
pub fn api_secret(&self) -> String
Returns the raw API secret as a base64-encoded string.
Used for WebSocket user channel authentication which expects the raw secret (not an HMAC signature).
Sourcepub fn sign(
&self,
timestamp: &str,
method: &str,
request_path: &str,
body: &str,
) -> String
pub fn sign( &self, timestamp: &str, method: &str, request_path: &str, body: &str, ) -> String
Signs a request with HMAC-SHA256 and returns the base64-encoded signature.
Message format: {timestamp}{method}{request_path}{body}
Sourcepub fn resolve(
api_key: Option<String>,
api_secret: Option<String>,
passphrase: Option<String>,
) -> Result<Self>
pub fn resolve( api_key: Option<String>, api_secret: Option<String>, passphrase: Option<String>, ) -> Result<Self>
Resolves from provided values, falling back to environment variables.
pub fn from_env() -> Result<Self>
Trait Implementations§
Source§impl Clone for Credential
impl Clone for Credential
Source§fn clone(&self) -> Credential
fn clone(&self) -> Credential
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for Credential
impl Debug for Credential
Auto Trait Implementations§
impl Freeze for Credential
impl RefUnwindSafe for Credential
impl Send for Credential
impl Sync for Credential
impl Unpin for Credential
impl UnsafeUnpin for Credential
impl UnwindSafe for Credential
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more