#![no_std]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![doc = include_str!("../README.md")]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg",
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg"
)]
#![forbid(unsafe_code)]
#![warn(
clippy::panic,
clippy::panic_in_result_fn,
clippy::unwrap_used,
missing_docs,
rust_2018_idioms,
unused_lifetimes,
unused_qualifications
)]
extern crate alloc;
pub mod crypto;
mod compact;
mod head;
pub use head::{Protected, Unprotected};
use alloc::{vec, vec::Vec};
use jose_b64::serde::{Bytes, Json};
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Serialize, Deserialize)]
#[non_exhaustive]
#[allow(clippy::large_enum_variant)]
#[serde(untagged)]
pub enum Jws {
General(General),
Flattened(Flattened),
}
impl From<General> for Jws {
fn from(value: General) -> Self {
Jws::General(value)
}
}
impl From<Flattened> for Jws {
fn from(value: Flattened) -> Self {
Jws::Flattened(value)
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct General {
pub payload: Option<Bytes>,
pub signatures: Vec<Signature>,
}
impl From<Flattened> for General {
fn from(value: Flattened) -> Self {
Self {
payload: value.payload,
signatures: vec![value.signature],
}
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Flattened {
pub payload: Option<Bytes>,
#[serde(flatten)]
pub signature: Signature,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Signature {
pub header: Option<Unprotected>,
pub protected: Option<Json<Protected>>,
pub signature: Bytes,
}