Request

Struct Request 

Source
pub struct Request<T> { /* private fields */ }
Expand description

A request which follows the RFC 8885 protocol for HTTP with JWS authentication

ACME prescribes that all requests are POST JWS requests in the flattened JSON format. This structure contains all of the materials except the anti-replay nonce which are required to create an appropriate HTTP request. The nonce is left out of this object that if the crate::Client encounters a bad nonce, it can re-try the same request with a new nonce value without having to re-build the request object.

Create a request with either Request::post or Request::get

For example, a GET request:


// ⚠️ **Do not use this key, it is an example used for testing only!**
let private = "-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgm1tOPOUt86+QgoiJ
kirpEl69+tUxLP848nPw9BbyW1ShRANCAASGWHBM2Lj7uUA4i9/jKSDp1vw4+iyu
hxVHBELXhxaD/LOQKtQAOhumi1uCTg8mMTrFrUM1VOtF8R0+rjrB3UXd
-----END PRIVATE KEY-----";

let key = Arc::new(SigningKey::from_pkcs8_pem(private,
   SignatureKind::Ecdsa(yacme_key::EcdsaAlgorithm::P256))
.unwrap());

let url: Url = "https://letsencrypt.test/new-account-plz/".parse().unwrap();

let request = Request::get(url, key);
println!("{}", request.formatted());

Implementations§

Source§

impl<T> Request<T>

Source

pub fn post<K: Into<Key>>(payload: T, url: Url, key: K) -> Self

Create a POST request with a given payload.

The payload must implement serde::Serialize and will be serialized to JSON and included in the JWS which is sent to the ACME server. The Url is required as it is a part of the JWS header (to prevent re-using a header and signature pair for additional requests). The signing key is also required.

Source

pub fn with_url(self, url: Url) -> Self

Alter the URL on this request to a new value.

Source

pub fn with_key<K: Into<Key>>(self, key: K) -> Self

Alter the Key on this request to a new value.

Source§

impl Request<()>

Source

pub fn get<K: Into<Key>>(url: Url, key: K) -> Self

Create a GET-as-POST request with an empty payload.

When making an authenticated GET request to an ACME server, the client sends a POST request, with a JWS body where the payload is the empty string. This is signed in the same way that a POST request is signed.

Source§

impl<T> Request<T>
where T: Serialize,

Source

pub fn sign(&self, nonce: Nonce) -> Result<SignedRequest, AcmeError>

Sign and finalize this request so that it can be sent over HTTP.

The resulting SignedRequest can be converted to a reqwest::Request for transmission. Normally, this method is not necessary - the crate::Client provides crate::Client::execute for executing Request objects natively.

Source

pub fn as_signed(&self) -> FormatSignedRequest<'_, T>

Provides a formatting proxy which when formatted will include the signature (as a Base64 URL-safe string in the JWS object). The format approximates that used by [RFC 8885][].

Note that this format will include a dummy nonce value, so the signature is consistent and repeatable, but may not match what should have been sent to the ACME service provider.

Use Request::as_signed_with_nonce if you have a real nonce and want to see a representation of this request similar to those in RFC 8885.

Source

pub fn as_signed_with_nonce(&self, nonce: Nonce) -> FormatSignedRequest<'_, T>

Provides a formatting proxy which when formatted will include the signature (as a Base64 URL-safe string in the JWS object). The format approximates that used by RFC 8885.

Note that this format will include the provided nonce value, so the signature can match what would be sent to the ACME service provider.

Use Request::as_signed if you do not have a nonce and want to see a representation of this request similar to those in RFC 8885.

Trait Implementations§

Source§

impl<T> AcmeFormat for Request<T>
where T: Serialize,

Source§

fn fmt<W: Write>(&self, f: &mut IndentWriter<'_, W>) -> Result

Write this format at the current indentation.
Source§

fn fmt_indented<W: Write>(&self, f: &mut IndentWriter<'_, W>) -> Result

Write this format at an indented level one greater than the current level. Read more
Source§

fn fmt_indented_skip_first<W: Write>( &self, f: &mut IndentWriter<'_, W>, ) -> Result

Write this format at an indented level one greater than the current level, but don’t indent the first line.
Source§

fn formatted(&self) -> AcmeFormatted<'_, Self>

Return a formatting proxy which will use the ACME format when used with std::fmt::Display.
Source§

impl<T: Clone> Clone for Request<T>

Source§

fn clone(&self) -> Request<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Request<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Request<T>
where T: Freeze,

§

impl<T> !RefUnwindSafe for Request<T>

§

impl<T> !Send for Request<T>

§

impl<T> !Sync for Request<T>

§

impl<T> Unpin for Request<T>
where T: Unpin,

§

impl<T> !UnwindSafe for Request<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,