pub struct HttpAuthRequest {
pub url: Url,
pub method: HttpMethod,
pub payload_hash: Option<[u8; 32]>,
}Expand description
Typed bundle for a kind: 27235 HTTP-auth event.
Fields§
§url: UrlAbsolute request URL (the u tag).
method: HttpMethodHTTP method (the method tag).
payload_hash: Option<[u8; 32]>Optional SHA-256 over the request body (the payload tag).
None matches a body-less request.
Implementations§
Source§impl HttpAuthRequest
impl HttpAuthRequest
Sourcepub const fn new(url: Url, method: HttpMethod) -> Self
pub const fn new(url: Url, method: HttpMethod) -> Self
Construct a body-less request bundle.
Sourcepub const fn payload_hash(self, hash: [u8; 32]) -> Self
pub const fn payload_hash(self, hash: [u8; 32]) -> Self
Attach a SHA-256 hash of the request body.
Sourcepub fn payload(self, body: &[u8]) -> Self
pub fn payload(self, body: &[u8]) -> Self
Convenience: hash body with SHA-256 and attach the digest.
Use this when the caller already has the body bytes in hand.
Render to the tag list of a kind: 27235 event.
Sourcepub fn from_event(event: &Event) -> Result<Self, HttpAuthError>
pub fn from_event(event: &Event) -> Result<Self, HttpAuthError>
Parse a kind: 27235 event back into a typed bundle.
§Errors
HttpAuthError::WrongKindfor any other kind.HttpAuthError::MissingUrl/MissingMethodwhen a required tag is absent.HttpAuthError::InvalidUrl/InvalidPayloadHashwhen a tag value is malformed.
Sourcepub fn validate(
&self,
signed_at: Timestamp,
now: Timestamp,
skew_secs: u64,
request_url: &Url,
request_method: &HttpMethod,
body: Option<&[u8]>,
) -> Result<(), HttpAuthError>
pub fn validate( &self, signed_at: Timestamp, now: Timestamp, skew_secs: u64, request_url: &Url, request_method: &HttpMethod, body: Option<&[u8]>, ) -> Result<(), HttpAuthError>
Server-side validation per NIP-98 §“Servers MUST perform the following checks”:
- Event kind is
27235(already enforced when the bundle came fromSelf::from_event). created_atis within±skewofnow. Default skew isDEFAULT_TIMESTAMP_SKEW_SECS.- The bundle’s
Self::urlequalsrequest_urlbyte-for-byte. - The bundle’s
Self::methodequalsrequest_method.
When body is Some, the SHA-256 over those bytes must
equal the bundle’s Self::payload_hash.
A body == None + payload_hash == Some(_) mismatch fails
validation; a body == Some + payload_hash == None is
allowed (spec uses “SHOULD include”, not “MUST”), but
most servers will want to reject it themselves with a
higher-level rule.
§Errors
One of the variants of HttpAuthError tagged with
Validation*.
Trait Implementations§
Source§impl Clone for HttpAuthRequest
impl Clone for HttpAuthRequest
Source§fn clone(&self) -> HttpAuthRequest
fn clone(&self) -> HttpAuthRequest
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for HttpAuthRequest
impl Debug for HttpAuthRequest
impl Eq for HttpAuthRequest
Source§impl PartialEq for HttpAuthRequest
impl PartialEq for HttpAuthRequest
impl StructuralPartialEq for HttpAuthRequest
Auto Trait Implementations§
impl Freeze for HttpAuthRequest
impl RefUnwindSafe for HttpAuthRequest
impl Send for HttpAuthRequest
impl Sync for HttpAuthRequest
impl Unpin for HttpAuthRequest
impl UnsafeUnpin for HttpAuthRequest
impl UnwindSafe for HttpAuthRequest
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.