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
use super::*;
pub fn decode_crypto_info(
reader: &veilid_capnp::crypto_info::Reader,
) -> Result<CryptoInfo, RPCError> {
let ck = reader.get_crypto_kind();
match ck {
#[cfg(feature = "enable-crypto-none")]
CRYPTO_KIND_NONE_FOURCC => {
let none = reader
.get_detail()
.get_as::<veilid_capnp::crypto_info_n_o_n_e::Reader>()?;
let public_key = BarePublicKey::new(none.get_public_key()?);
Ok(CryptoInfo::NONE { public_key })
}
#[cfg(feature = "enable-crypto-vld0")]
CRYPTO_KIND_VLD0_FOURCC => {
let vld0 = reader
.get_detail()
.get_as::<veilid_capnp::crypto_info_v_l_d0::Reader>()?;
let public_key = BarePublicKey::new(vld0.get_public_key()?);
Ok(CryptoInfo::VLD0 { public_key })
}
// #[cfg(feature = "enable-crypto-vld1")]
// CRYPTO_KIND_VLD1_FOURCC => {
// let vld1 = reader
// .get_detail()
// .get_as::<veilid_capnp::crypto_info_v_l_d1::Reader>()?;
// let encapsulation_key = BareEncapsulationKey::new(vld1.get_encapsulation_key()?);
// let signing_key = BarePublicKey::new(vld1.get_signing_key()?);
// Ok(CryptoInfo::VLD1 {
// encapsulation_key,
// signing_key,
// })
// }
_ => Err(RPCError::ignore("unknown crypto kind")),
}
}
pub fn encode_crypto_info(
crypto_info: &CryptoInfo,
builder: &mut veilid_capnp::crypto_info::Builder,
) {
match crypto_info {
#[cfg(feature = "enable-crypto-none")]
CryptoInfo::NONE { public_key } => {
builder.set_crypto_kind(CRYPTO_KIND_NONE_FOURCC);
let mut noneb = builder
.reborrow()
.init_detail()
.init_as::<veilid_capnp::crypto_info_n_o_n_e::Builder>();
noneb.set_public_key(public_key);
}
#[cfg(feature = "enable-crypto-vld0")]
CryptoInfo::VLD0 { public_key } => {
builder.set_crypto_kind(CRYPTO_KIND_VLD0_FOURCC);
let mut vld0b = builder
.reborrow()
.init_detail()
.init_as::<veilid_capnp::crypto_info_v_l_d0::Builder>();
vld0b.set_public_key(public_key);
} // #[cfg(feature = "enable-crypto-vld1")]
// CryptoInfo::VLD1 {
// encapsulation_key,
// signing_key,
// } => {
// builder.set_crypto_kind(CRYPTO_KIND_VLD1_FOURCC);
// let mut vld1b = builder.reborrow()
// .init_detail()
// .init_as::<veilid_capnp::crypto_info_v_l_d1::Builder>();
// vld1b.set_encapsulation_key(encapsulation_key);
// vld1b.set_signing_key(signing_key);
// }
};
}