use super::*;
#[derive(Clone, Data, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct JwtHeader {
pub(crate) alg: String,
#[serde(skip_serializing_if = "Option::is_none")]
#[get(type(clone))]
pub(crate) typ: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
#[get(type(clone))]
pub(crate) kid: Option<String>,
}
#[derive(Deserialize)]
pub(crate) struct JwtHeaderRef<'a> {
#[serde(borrow)]
pub(crate) alg: Cow<'a, str>,
#[serde(borrow, default)]
pub(crate) kid: Option<Cow<'a, str>>,
}
#[derive(Clone, Copy, Debug)]
pub(crate) struct HmacSha256Key {
pub(crate) inner_state: [u32; 8],
pub(crate) outer_state: [u32; 8],
}
pub(crate) struct StackJsonBuf {
pub(crate) stack: [u8; JWT_STACK_PAYLOAD_CAP],
pub(crate) len: usize,
pub(crate) heap: Option<Vec<u8>>,
}
#[derive(Clone, Data, Debug, Default, Deserialize, PartialEq, Serialize)]
pub struct JwtClaims {
pub(crate) sub: String,
#[serde(skip_serializing_if = "Option::is_none")]
#[get(type(clone))]
pub(crate) iss: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
#[get(type(clone))]
pub(crate) aud: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
#[get(type(copy))]
pub(crate) exp: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
#[get(type(copy))]
pub(crate) nbf: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
#[get(type(copy))]
pub(crate) iat: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
#[get(type(clone))]
pub(crate) jti: Option<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub(crate) roles: Vec<String>,
#[serde(flatten, default, skip_serializing_if = "HashMap::is_empty")]
pub(crate) extra: HashMap<String, Value>,
}
#[derive(Clone, Debug)]
pub struct JwtCodec {
pub(crate) default_secret: Vec<u8>,
pub(crate) default_hmac: HmacSha256Key,
pub(crate) default_kid: Option<String>,
pub(crate) default_header_b64: String,
pub(crate) keyring: HashMapXxHash3_64<String, Vec<u8>>,
pub(crate) keyring_hmac: HashMapXxHash3_64<String, HmacSha256Key>,
pub(crate) leeway_secs: u64,
pub(crate) required_issuer: Option<String>,
pub(crate) required_audience: Option<String>,
}
#[derive(Clone, Data, Debug, PartialEq)]
pub struct AuthPrincipal {
pub(crate) subject: String,
pub(crate) roles: Vec<String>,
#[get(type(copy))]
pub(crate) scheme: AuthScheme,
#[get(type(clone))]
pub(crate) claims: Option<JwtClaims>,
}
#[derive(Clone, Debug)]
pub struct JwtAuthenticator {
pub(crate) codec: JwtCodec,
}
#[derive(Clone, Debug)]
pub struct ApiKeyAuthenticator {
pub(crate) header_name: String,
pub(crate) entries: Vec<(Vec<u8>, String, Vec<String>)>,
}
#[derive(Clone, Debug)]
pub struct BasicAuthenticator {
pub(crate) users: HashMapXxHash3_64<String, (Vec<u8>, Vec<String>)>,
}
#[derive(Clone)]
pub struct CompositeAuthenticator {
pub(crate) chain: Vec<SharedAuthenticator>,
}
#[derive(Clone, Data, Debug, Eq, PartialEq)]
pub struct AuthConfig {
pub(crate) exempt_paths: Vec<String>,
pub(crate) required_roles: Vec<String>,
#[get(type(copy))]
pub(crate) require_all_roles: bool,
pub(crate) www_authenticate: String,
}
#[derive(Clone)]
pub struct AuthPlugin {
pub(crate) config: AuthConfig,
pub(crate) authenticator: SharedAuthenticator,
pub(crate) exempt_set: Option<HashSetXxHash3_64<String>>,
}
#[derive(Clone, Copy, Debug, Default)]
#[hyperlane::request_middleware(-90)]
pub struct AuthHook;