-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregister.rs
More file actions
56 lines (43 loc) · 1.66 KB
/
register.rs
File metadata and controls
56 lines (43 loc) · 1.66 KB
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
use binary_codec::{FromBytes, ToBytes};
use serde::{Deserialize, Serialize};
use crate::crypto::algorithm::VerificationKey;
/// Register a new identity on the server, which can be used for authentication in future sessions.
#[derive(FromBytes, ToBytes, Serialize, Deserialize, Debug, PartialEq, Clone)]
pub struct RegisterRequestBody {
/// Public keys (new generated) for all algorithms specified in `crypto_settings` in the packet base.
#[multi_enum]
keys: Vec<VerificationKey>,
/// Claims to register, key-value, UTF-8. Separated by ;, like `USERNAME=henk;AGE=12`
claims: String,
}
#[cfg(test)]
mod tests {
use binary_codec::{BinaryDeserializer, BinarySerializer};
use crate::packets::request::PlabbleRequestPacket;
#[test]
fn can_serialize_and_deserialize_register_request() {
let key = "f0a22003a3d06ed16f5920a03c1297c742c281bda4895ea7caca682c276bf098";
let request: PlabbleRequestPacket = toml::from_str(
r#"
version = 1
specify_crypto_settings = true
[crypto_settings]
sign_ed25519 = true
[header]
packet_type = "Register"
[body]
claims = "USERNAME=henk;AGE=24"
[[body.keys]]
Ed25519 = "8KIgA6PQbtFvWSCgPBKXx0LCgb2kiV6nyspoLCdr8Jg"
"#,
)
.unwrap();
let bytes = request.to_bytes(None).unwrap();
assert_eq!(
format!("81310a{}{}", key, hex::encode("USERNAME=henk;AGE=24")),
hex::encode(&bytes)
);
let deserialized = PlabbleRequestPacket::from_bytes(&bytes, None).unwrap();
assert_eq!(request, deserialized);
}
}