diff --git a/library/channels_api/channel_api.nim b/library/channels_api/channel_api.nim index d8daac02b..083a31d55 100644 --- a/library/channels_api/channel_api.nim +++ b/library/channels_api/channel_api.nim @@ -3,19 +3,36 @@ import chronos, results, ffi import logos_delivery/waku/common/base64, logos_delivery, + logos_delivery/channels/encryption/noop_encryption, logos_delivery/waku/waku_core/topics/content_topic, logos_delivery/api/types, ../declare_lib +proc installEncryption(mechanism: string): Result[void, string] = + ## The Encrypt/Decrypt brokers dispatch to a single provider, so this installs + ## it process-wide even though the mechanism is named per channel: channels + ## created with different mechanisms would fight over it, last one winning. + ## Traffic cannot flow until some provider is registered. + case mechanism + of "noop": + setNoopEncryption() + ok() + else: + err("unknown encryption mechanism '" & mechanism & "'; supported: noop") + proc logosdeliveryChannelCreate*( lib: LogosDelivery, channelIdStr: string, contentTopicStr: string, senderIdStr: string, + encryptionStr: string, ): Future[Result[string, string]] {.ffi.} = requireChannels(lib, "ChannelCreate"): return err(errMsg) + installEncryption(encryptionStr).isOkOr: + return err("ChannelCreate failed: " & error) + let id = lib.reliableChannelManager.createReliableChannel( ChannelId(channelIdStr), ContentTopic(contentTopicStr), diff --git a/library/rust_bindings/src/api.rs b/library/rust_bindings/src/api.rs index 865bec979..1ddd3b745 100644 --- a/library/rust_bindings/src/api.rs +++ b/library/rust_bindings/src/api.rs @@ -1365,8 +1365,8 @@ impl LogosDeliveryCtx { decode_cbor::(&raw_bytes) } - pub fn channel_create(&self, channel_id_str: String, content_topic_str: String, sender_id_str: String) -> Result { - let req = LogosdeliveryChannelCreateReq { channel_id_str, content_topic_str, sender_id_str }; + pub fn channel_create(&self, channel_id_str: String, content_topic_str: String, sender_id_str: String, encryption_str: String) -> Result { + let req = LogosdeliveryChannelCreateReq { channel_id_str, content_topic_str, sender_id_str, encryption_str }; let req_bytes = encode_cbor(&req)?; let raw_bytes = ffi_call_sync(self.timeout, |cb, ud| unsafe { ffi::logosdelivery_channel_create(self.ptr, cb, ud, req_bytes.as_ptr(), req_bytes.len()) @@ -1374,8 +1374,8 @@ impl LogosDeliveryCtx { decode_cbor::(&raw_bytes) } - pub async fn channel_create_async(&self, channel_id_str: String, content_topic_str: String, sender_id_str: String) -> Result { - let req = LogosdeliveryChannelCreateReq { channel_id_str, content_topic_str, sender_id_str }; + pub async fn channel_create_async(&self, channel_id_str: String, content_topic_str: String, sender_id_str: String, encryption_str: String) -> Result { + let req = LogosdeliveryChannelCreateReq { channel_id_str, content_topic_str, sender_id_str, encryption_str }; let req_bytes = encode_cbor(&req)?; let ptr = self.ptr as usize; let raw_bytes = ffi_call_async(self.timeout, move |cb, ud| unsafe { diff --git a/library/rust_bindings/src/types.rs b/library/rust_bindings/src/types.rs index 1b48e059d..03ab1c270 100644 --- a/library/rust_bindings/src/types.rs +++ b/library/rust_bindings/src/types.rs @@ -367,6 +367,8 @@ pub struct LogosdeliveryChannelCreateReq { pub content_topic_str: String, #[serde(rename = "senderIdStr")] pub sender_id_str: String, + #[serde(rename = "encryptionStr")] + pub encryption_str: String, } #[derive(Debug, Clone, Serialize, Deserialize)]