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>
impl<T> Request<T>
Sourcepub fn post<K: Into<Key>>(payload: T, url: Url, key: K) -> Self
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§impl Request<()>
impl Request<()>
Sourcepub fn get<K: Into<Key>>(url: Url, key: K) -> Self
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,
impl<T> Request<T>where
T: Serialize,
Sourcepub fn sign(&self, nonce: Nonce) -> Result<SignedRequest, AcmeError>
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.
Sourcepub fn as_signed(&self) -> FormatSignedRequest<'_, T>
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.
Sourcepub fn as_signed_with_nonce(&self, nonce: Nonce) -> FormatSignedRequest<'_, T>
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,
impl<T> AcmeFormat for Request<T>where
T: Serialize,
Source§fn fmt<W: Write>(&self, f: &mut IndentWriter<'_, W>) -> Result
fn fmt<W: Write>(&self, f: &mut IndentWriter<'_, W>) -> Result
Source§fn fmt_indented<W: Write>(&self, f: &mut IndentWriter<'_, W>) -> Result
fn fmt_indented<W: Write>(&self, f: &mut IndentWriter<'_, W>) -> Result
Source§fn fmt_indented_skip_first<W: Write>(
&self,
f: &mut IndentWriter<'_, W>,
) -> Result
fn fmt_indented_skip_first<W: Write>( &self, f: &mut IndentWriter<'_, W>, ) -> Result
Source§fn formatted(&self) -> AcmeFormatted<'_, Self>
fn formatted(&self) -> AcmeFormatted<'_, Self>
std::fmt::Display.