jsonprooftoken/jwp/
header.rs1use serde::{Deserialize, Serialize};
16
17use crate::{
18 jpa::algs::{PresentationProofAlgorithm, ProofAlgorithm},
19 jpt::claims::Claims,
20};
21
22#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
23pub struct IssuerProtectedHeader {
24 #[serde(skip_serializing_if = "Option::is_none")]
26 typ: Option<String>,
27 alg: ProofAlgorithm,
29 #[serde(skip_serializing_if = "Option::is_none")]
31 kid: Option<String>,
32 #[serde(skip_serializing_if = "Option::is_none")]
34 cid: Option<String>,
35 #[serde(skip_serializing_if = "Option::is_none")]
37 claims: Option<Claims>,
38}
39
40impl IssuerProtectedHeader {
41 pub fn new(alg: ProofAlgorithm) -> Self {
42 Self {
43 typ: Some("JPT".to_owned()),
44 alg,
45 kid: None,
46 cid: None,
47 claims: None,
48 }
49 }
50
51 pub fn alg(&self) -> ProofAlgorithm {
53 self.alg
54 }
55
56 pub fn typ(&self) -> Option<&String> {
58 self.typ.as_ref()
59 }
60
61 pub fn set_typ(&mut self, value: Option<String>) {
63 self.typ = value;
64 }
65
66 pub fn kid(&self) -> Option<&String> {
68 self.kid.as_ref()
69 }
70
71 pub fn set_kid(&mut self, value: Option<String>) {
73 self.kid = value;
74 }
75
76 pub fn cid(&self) -> Option<&String> {
78 self.cid.as_ref()
79 }
80
81 pub fn set_cid(&mut self, value: Option<String>) {
83 self.cid = value;
84 }
85
86 pub fn claims(&self) -> Option<&Claims> {
88 self.claims.as_ref()
89 }
90
91 pub(crate) fn set_claims(&mut self, value: Option<Claims>) {
93 self.claims = value;
94 }
95}
96
97#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
98pub struct PresentationProtectedHeader {
99 alg: PresentationProofAlgorithm,
100 #[serde(skip_serializing_if = "Option::is_none")]
102 kid: Option<String>,
103 #[serde(skip_serializing_if = "Option::is_none")]
105 aud: Option<String>,
106 #[serde(skip_serializing_if = "Option::is_none")]
108 nonce: Option<String>,
109}
110
111impl PresentationProtectedHeader {
112 pub fn new(alg: PresentationProofAlgorithm) -> Self {
113 Self {
114 alg,
115 kid: None,
116 aud: None,
117 nonce: None,
118 }
119 }
120
121 pub fn alg(&self) -> PresentationProofAlgorithm {
123 self.alg
124 }
125
126 pub fn kid(&self) -> Option<&String> {
128 self.kid.as_ref()
129 }
130
131 pub fn set_kid(&mut self, value: Option<String>) {
133 self.kid = value;
134 }
135
136 pub fn aud(&self) -> Option<&String> {
138 self.aud.as_ref()
139 }
140
141 pub fn set_aud(&mut self, value: Option<String>) {
143 self.aud = value;
144 }
145
146 pub fn nonce(&self) -> Option<&String> {
148 self.nonce.as_ref()
149 }
150
151 pub fn set_nonce(&mut self, value: Option<String>) {
153 self.nonce = value;
154 }
155}