1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
//! ### Setting up the encryption parameters
//!
//! The public key and user secret keys for encryption can be retrieved from the Private Key
//! Generator (PKG).
//!
//! ```rust
//! use std::time::SystemTime;
//! use pg_core::identity::{Attribute, Policy, EncryptionPolicy};
//!
//! let timestamp = SystemTime::now()
//! .duration_since(SystemTime::UNIX_EPOCH)
//! .unwrap()
//! .as_secs();
//!
//! let id1 = String::from("Bob");
//! let id2 = String::from("Charlie");
//!
//! let p1 = Policy {
//! timestamp,
//! con: vec![Attribute::new(
//! "pbdf.gemeente.personalData.bsn",
//! Some("123bob789"),
//! )],
//! };
//!
//! let p2 = Policy {
//! timestamp,
//! con: vec![
//! Attribute::new("pbdf.gemeente.personalData.name", Some("Charlie")),
//! Attribute::new("pbdf.sidn-pbdf.email.email", Some("charlie@example.com")),
//! ],
//! };
//!
//! let policy = EncryptionPolicy::from([(id1, p1), (id2, p2)]);
//! ```
//!
//! This will specify two recipients who can decrypt, in this case identified by their e-mail
//! address, but this identifier can be anything which uniquely represents a receiver. The
//! recipients are only able to decrypt if they are able to prove the that they own the attributes
//! specified in the `con` field.
//!
//! ### Seal a slice using the Rust Crypto backend
//!
//! ```rust
//! use pg_core::client::rust::{SealerMemoryConfig, UnsealerMemoryConfig};
//! use pg_core::client::{Sealer, Unsealer};
//! # use pg_core::error::Error;
//! use pg_core::test::TestSetup;
//!
//! # fn main() -> Result<(), Error> {
//! let mut rng = rand::thread_rng();
//! # let TestSetup {
//! # ibe_pk,
//! # ibs_pk,
//! # policies,
//! # usks,
//! # signing_keys,
//! # policy,
//! # ..
//! # } = TestSetup::new(&mut rng);
//! # let signing_key = &signing_keys[0];
//! # let id = "Bob";
//! # let usk = &usks[2];
//!
//! // Sender: retrieve public key, setup policy and signing keys.
//!
//! let input = b"SECRET DATA";
//! let sealed = Sealer::<_, SealerMemoryConfig>::new(&ibe_pk, &policy, &signing_key, &mut rng)?
//! .seal(input)?;
//!
//! // Receiver: retrieve USK and verifying key.
//!
//! let (original, verified_sender_id) =
//! Unsealer::<_, UnsealerMemoryConfig>::new(sealed, &ibs_pk)?.unseal(id, &usk)?;
//!
//! assert_eq!(&input.to_vec(), &original);
//!
//! assert_eq!(&verified_sender_id.public, &signing_key.policy);
//! assert_eq!(verified_sender_id.private, None);
//! # Ok(())
//! # }
//! ```
//!
//!
//! ### Using the Web Crypto backend
//!
//! Using the Web Crypto backend in Rust can be useful in Rust web frameworks (e.g.,
//! Yew/Dioxus/Leptos). For use in JavaScript/TypeScript, there is a seperate NPM package called
//! [`pg-wasm`](https://www.npmjs.com/package/@e4a/pg-wasm) which offers an FFI interface generated by `wasm-pack`.
//! See its documentation for examples.
//!
//! ### Wire format
//!
//! The wire format consists of the following segments, followed by their length in bytes:
//!
//! ```text
//! PREAMBLE (10)
//! = PRELUDE (4) || VERSION (2) || HEADER LEN (4)
//!
//! HEADER (*)
//! = HEADER (*) || HEADER SIG LEN (4) || HEADER SIG (*)
//!
//! PAYLOAD (*)
//! = DEM.Enc(M (*) || STREAM SIG (*) || STREAM SIG LEN (4))
//! ```
extern crate std;
// We depend on alloc for String, Vec and BTreeMap/HashMap.
extern crate alloc;
pub use ;
pub use ibs;
pub use *;