Skip to content

Commit

Permalink
Document challenge types in specific methods
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Nov 15, 2022
1 parent b87f572 commit 8c0a179
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,13 +422,9 @@ trait Signer {

/// The response value to use for challenge responses
///
/// Use [`KeyAuthorization::dns_value()`] for DNS challenges,
/// [`KeyAuthorization::to_bytes()`] for TLS challenges, and
/// [`KeyAuthorization::as_str()`] for HTTP challenges.
/// Refer to the methods below to see which encoding to use for your challenge type.
///
/// <https://datatracker.ietf.org/doc/html/rfc8555#section-8.1>
///
/// <https://datatracker.ietf.org/doc/html/rfc8737#section-3>
pub struct KeyAuthorization(String);

impl KeyAuthorization {
Expand All @@ -437,16 +433,24 @@ impl KeyAuthorization {
}

/// Get the key authorization value
///
/// This can be used for HTTP-01 challenge responses.
pub fn as_str(&self) -> &str {
&self.0
}

/// Get the SHA256 digest of the key authorization
/// Get the SHA-256 digest of the key authorization
///
/// This can be used for TLS-ALPN-01 challenge responses.
///
/// <https://datatracker.ietf.org/doc/html/rfc8737#section-3>
pub fn to_bytes(&self) -> impl AsRef<[u8]> {
digest(&SHA256, self.0.as_bytes())
}

/// Get the base64-encoded SHA256 digest of the key authorization
///
/// This can be used for DNS-01 challenge responses.
pub fn dns_value(&self) -> String {
base64::encode_config(self.to_bytes(), URL_SAFE_NO_PAD)
}
Expand Down

0 comments on commit 8c0a179

Please sign in to comment.