1#![no_std]
5#![cfg_attr(docsrs, feature(doc_auto_cfg))]
6#![doc = include_str!("../README.md")]
7#![doc(
8 html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg",
9 html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg"
10)]
11#![forbid(unsafe_code)]
12#![warn(
13 clippy::panic,
14 clippy::panic_in_result_fn,
15 clippy::unwrap_used,
16 missing_docs,
17 rust_2018_idioms,
18 unused_lifetimes,
19 unused_qualifications
20)]
21
22extern crate alloc;
23
24pub mod crypto;
25
26mod compact;
27mod head;
28
29pub use head::{Protected, Unprotected};
30
31use alloc::{vec, vec::Vec};
32
33use jose_b64::serde::{Bytes, Json};
34use serde::{Deserialize, Serialize};
35
36#[derive(Clone, Debug, Serialize, Deserialize)]
38#[non_exhaustive]
39#[allow(clippy::large_enum_variant)]
40#[serde(untagged)]
41pub enum Jws {
42 General(General),
44
45 Flattened(Flattened),
47}
48
49impl From<General> for Jws {
50 fn from(value: General) -> Self {
51 Jws::General(value)
52 }
53}
54
55impl From<Flattened> for Jws {
56 fn from(value: Flattened) -> Self {
57 Jws::Flattened(value)
58 }
59}
60
61#[derive(Clone, Debug, Serialize, Deserialize)]
80pub struct General {
81 pub payload: Option<Bytes>,
83
84 pub signatures: Vec<Signature>,
86}
87
88impl From<Flattened> for General {
89 fn from(value: Flattened) -> Self {
90 Self {
91 payload: value.payload,
92 signatures: vec![value.signature],
93 }
94 }
95}
96
97#[derive(Clone, Debug, Serialize, Deserialize)]
111pub struct Flattened {
112 pub payload: Option<Bytes>,
114
115 #[serde(flatten)]
117 pub signature: Signature,
118}
119
120#[derive(Clone, Debug, Serialize, Deserialize)]
122pub struct Signature {
123 pub header: Option<Unprotected>,
125
126 pub protected: Option<Json<Protected>>,
128
129 pub signature: Bytes,
131}