Skip to content

Commit

Permalink
resolve some smaller issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Erk- committed Jun 15, 2024
1 parent e1ab4f5 commit 094684e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions examples/model-webhook-slash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use twilight_model::{
},
http::interaction::{InteractionResponse, InteractionResponseData, InteractionResponseType},
};
use twilight_util::signature_validation::{Key, TIMESTAMP_HEADER};
use twilight_util::signature_validation::{Key, Signature, TIMESTAMP_HEADER};

/// Public key given from Discord.
static PUB_KEY: Lazy<Key> = Lazy::new(|| Key::from_hex("PUBLIC_KEY".as_bytes()).unwrap());
Expand Down Expand Up @@ -64,7 +64,12 @@ where
.headers()
.get(twilight_util::signature_validation::SIGNATURE_HEADER)
{
hex_sig.to_owned()
let Ok(sig) = Signature::from_slice(hex_sig.as_bytes()) else {
return Ok(Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(Full::default())?);
};
sig
} else {
return Ok(Response::builder()
.status(StatusCode::BAD_REQUEST)
Expand All @@ -77,7 +82,7 @@ where

// Check if the signature matches and else return a error response.
if PUB_KEY
.verify(signature.as_bytes(), timestamp.as_bytes(), &whole_body)
.verify(&signature, timestamp.as_bytes(), &whole_body)
.is_err()
{
return Ok(Response::builder()
Expand Down
2 changes: 1 addition & 1 deletion twilight-util/src/signature_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub fn check_signature(
let mut buf = Vec::with_capacity(timestamp.len() + body.len());
buf.extend_from_slice(timestamp);
buf.extend_from_slice(body);
match key.0.verify_strict(&buf, &signature.inner) {
match key.inner.verify_strict(&buf, &signature.inner) {
Ok(()) => Ok(()),
Err(e) => Err(SignatureValidationFailure {
kind: SignatureValidationFailureKind::InvalidSignature,
Expand Down

0 comments on commit 094684e

Please sign in to comment.