mirror of
https://git.asonix.dog/asonix/http-signature-normalization.git
synced 2024-11-21 17:00:59 +00:00
Rename PrivateKey to VerifyKey
This commit is contained in:
parent
8c9e7af2b9
commit
8697413adb
2 changed files with 21 additions and 21 deletions
|
@ -1,6 +1,6 @@
|
||||||
use actix_web::{http::StatusCode, web, App, HttpRequest, HttpResponse, HttpServer, ResponseError};
|
use actix_web::{http::StatusCode, web, App, HttpRequest, HttpResponse, HttpServer, ResponseError};
|
||||||
use http_signature_normalization_actix_extractor::{
|
use http_signature_normalization_actix_extractor::{
|
||||||
Algorithm, Config, ConfigGenerator, PrivateKey, Signed,
|
Algorithm, Config, ConfigGenerator, Signed, VerifyKey,
|
||||||
};
|
};
|
||||||
use sha2::Sha256;
|
use sha2::Sha256;
|
||||||
|
|
||||||
|
@ -23,17 +23,29 @@ async fn protected(signed_request: Signed<String, Cfg, Sha256, Key>) -> &'static
|
||||||
|
|
||||||
pub struct Cfg;
|
pub struct Cfg;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Key;
|
||||||
|
|
||||||
|
#[derive(Debug, thiserror::Error)]
|
||||||
|
pub enum MyError {
|
||||||
|
#[error("Unsupported algorithm")]
|
||||||
|
Algorithm,
|
||||||
|
|
||||||
|
#[error("Couldn't decode signature")]
|
||||||
|
Decode,
|
||||||
|
|
||||||
|
#[error("Invalid key")]
|
||||||
|
Key,
|
||||||
|
}
|
||||||
|
|
||||||
impl ConfigGenerator for Cfg {
|
impl ConfigGenerator for Cfg {
|
||||||
fn config() -> Config {
|
fn config() -> Config {
|
||||||
Config::new().require_header("accept")
|
Config::new().require_header("accept")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct Key;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl PrivateKey for Key {
|
impl VerifyKey for Key {
|
||||||
type Error = MyError;
|
type Error = MyError;
|
||||||
|
|
||||||
async fn init(
|
async fn init(
|
||||||
|
@ -65,18 +77,6 @@ impl PrivateKey for Key {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
|
||||||
pub enum MyError {
|
|
||||||
#[error("Unsupported algorithm")]
|
|
||||||
Algorithm,
|
|
||||||
|
|
||||||
#[error("Couldn't decode signature")]
|
|
||||||
Decode,
|
|
||||||
|
|
||||||
#[error("Invalid key")]
|
|
||||||
Key,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ResponseError for MyError {
|
impl ResponseError for MyError {
|
||||||
fn status_code(&self) -> StatusCode {
|
fn status_code(&self) -> StatusCode {
|
||||||
StatusCode::BAD_REQUEST
|
StatusCode::BAD_REQUEST
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
pub use actix_web_lab::extract::RequestSignature;
|
pub use actix_web_lab::extract::RequestSignature;
|
||||||
pub use http_signature_normalization::{verify::Algorithm, Config};
|
pub use http_signature_normalization::{verify::Algorithm, Config};
|
||||||
|
|
||||||
pub type Signed<Extractor, Config, Digest, PrivateKey> =
|
pub type Signed<Extractor, Config, Digest, VerifyKey> =
|
||||||
RequestSignature<Extractor, SignatureScheme<Config, Digest, PrivateKey>>;
|
RequestSignature<Extractor, SignatureScheme<Config, Digest, VerifyKey>>;
|
||||||
|
|
||||||
#[cfg(feature = "sha-2")]
|
#[cfg(feature = "sha-2")]
|
||||||
mod sha2_digest;
|
mod sha2_digest;
|
||||||
|
@ -93,7 +93,7 @@ pub trait ConfigGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
pub trait PrivateKey: Sized + Send {
|
pub trait VerifyKey: Sized + Send {
|
||||||
type Error: Into<actix_web::Error>;
|
type Error: Into<actix_web::Error>;
|
||||||
|
|
||||||
async fn init(
|
async fn init(
|
||||||
|
@ -118,7 +118,7 @@ impl<C, D, K> actix_web_lab::extract::RequestSignatureScheme for SignatureScheme
|
||||||
where
|
where
|
||||||
C: ConfigGenerator,
|
C: ConfigGenerator,
|
||||||
D: VerifyDigest,
|
D: VerifyDigest,
|
||||||
K: PrivateKey,
|
K: VerifyKey,
|
||||||
{
|
{
|
||||||
type Signature = Signature<D, K>;
|
type Signature = Signature<D, K>;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue