From 22cf251b1e80874947141c018fa1e9b4abc94518 Mon Sep 17 00:00:00 2001 From: "Mayeul@Zama" <69792125+mayeul-zama@users.noreply.github.com> Date: Thu, 20 Feb 2025 17:31:39 +0100 Subject: [PATCH] chore(docs): add HL strings documentation --- tfhe/docs/SUMMARY.md | 1 + .../operations/string-operations.md | 55 +++++++++++++++++++ tfhe/src/test_user_docs.rs | 4 ++ 3 files changed, 60 insertions(+) create mode 100644 tfhe/docs/fhe-computation/operations/string-operations.md diff --git a/tfhe/docs/SUMMARY.md b/tfhe/docs/SUMMARY.md index cf15fbe64c..0ef4fcc78b 100644 --- a/tfhe/docs/SUMMARY.md +++ b/tfhe/docs/SUMMARY.md @@ -27,6 +27,7 @@ * [Ternary conditional operations](fhe-computation/operations/ternary-conditional-operations.md) * [Casting operations](fhe-computation/operations/casting-operations.md) * [Boolean Operations](fhe-computation/operations/boolean-operations.md) + * [String Operations](fhe-computation/operations/string-operations.md) * [Core workflow](fhe-computation/compute/README.md) * [Configuration and key generation](fhe-computation/compute/configure-and-generate-keys.md) * [Server key](fhe-computation/compute/set-the-server-key.md) diff --git a/tfhe/docs/fhe-computation/operations/string-operations.md b/tfhe/docs/fhe-computation/operations/string-operations.md new file mode 100644 index 0000000000..8fe4325235 --- /dev/null +++ b/tfhe/docs/fhe-computation/operations/string-operations.md @@ -0,0 +1,55 @@ +# String operations + +This document details the string operations supported by **TFHE-rs**. + +| clear name | fhe name | first input type | second input type | third input type +| --------------------------------------------------------------------------------------------------------------- | -------------------- | -------------- | ---------------------------------------------- | ------------------ +| [eq](https://doc.rust-lang.org/stable/std/primitive.str.html#method.eq) |eq | FheAsciiString | FheAsciiString or ClearString | +| [ne](https://doc.rust-lang.org/stable/std/primitive.str.html#method.ne) |ne | FheAsciiString | FheAsciiString or ClearString | +| [le](https://doc.rust-lang.org/stable/std/primitive.str.html#method.le) |le | FheAsciiString | FheAsciiString or ClearString | +| [ge](https://doc.rust-lang.org/stable/std/primitive.str.html#method.ge) |ge | FheAsciiString | FheAsciiString or ClearString | +| [lt](https://doc.rust-lang.org/stable/std/primitive.str.html#method.lt) |lt | FheAsciiString | FheAsciiString or ClearString | +| [gt](https://doc.rust-lang.org/stable/std/primitive.str.html#method.gt) |gt | FheAsciiString | FheAsciiString or ClearString | +| [len](https://doc.rust-lang.org/stable/std/primitive.str.html#method.len) |len | FheAsciiString | | +| [is_empty](https://doc.rust-lang.org/stable/std/primitive.str.html#method.is_empty) |is_empty | FheAsciiString | | +| [eq_ignore_ascii_case](https://doc.rust-lang.org/stable/std/primitive.str.html#method.eq_ignore_ascii_case) |eq_ignore_case | FheAsciiString | FheAsciiString or ClearString | +| [to_lowercase](https://doc.rust-lang.org/stable/std/primitive.str.html#method.to_lowercase) |to_lowercase | FheAsciiString | | +| [to_uppercase](https://doc.rust-lang.org/stable/std/primitive.str.html#method.to_uppercase) |to_uppercase | FheAsciiString | | +| [contains](https://doc.rust-lang.org/stable/std/primitive.str.html#method.contains) |contains | FheAsciiString | FheAsciiString or ClearString | +| [ends_with](https://doc.rust-lang.org/stable/std/primitive.str.html#method.ends_with) |ends_with | FheAsciiString | FheAsciiString or ClearString | +| [starts_with](https://doc.rust-lang.org/stable/std/primitive.str.html#method.starts_with) |starts_with | FheAsciiString | FheAsciiString or ClearString | +| [find](https://doc.rust-lang.org/stable/std/primitive.str.html#method.find) |find | FheAsciiString | FheAsciiString or ClearString | +| [rfind](https://doc.rust-lang.org/stable/std/primitive.str.html#method.rfind) |rfind | FheAsciiString | FheAsciiString or ClearString | +| [strip_prefix](https://doc.rust-lang.org/stable/std/primitive.str.html#method.strip_prefix) |strip_prefix | FheAsciiString | FheAsciiString or ClearString | +| [strip_suffix](https://doc.rust-lang.org/stable/std/primitive.str.html#method.strip_suffix) |strip_suffix | FheAsciiString | FheAsci---iString or ClearString | +| [concat](https://doc.rust-lang.org/stable/std/primitive.str.html#method.concat) |concat | FheAsciiString | FheAsciiString | +| [repeat](https://doc.rust-lang.org/stable/std/primitive.str.html#method.repeat) |repeat | FheAsciiString | u16 or u32 or i32 or usize or (FheUint16, u16) | +| [trim_end](https://doc.rust-lang.org/stable/std/primitive.str.html#method.trim_end) |trim_end | FheAsciiString | | +| [trim_start](https://doc.rust-lang.org/stable/std/primitive.str.html#method.trim_start) |trim_start | FheAsciiString | | +| [trim](https://doc.rust-lang.org/stable/std/primitive.str.html#method.trim) |trim | FheAsciiString | | +| [replace](https://doc.rust-lang.org/stable/std/primitive.str.html#method.replace) |replace | FheAsciiString | FheAsciiString | +| [replacen](https://doc.rust-lang.org/stable/std/primitive.str.html#method.replacen) |replacen | FheAsciiString | FheAsciiString or ClearString | u16 or u32 or i32 or usize or (FheUint16, u16) + +The following example shows how to perform string operations: + +```rust +use tfhe::prelude::*; +use tfhe::{ + generate_keys, set_server_key, ConfigBuilder, FheAsciiString, FheStringLen, +}; + +fn main() -> Result<(), Box> { + + let config = ConfigBuilder::default().build(); + let (client_key, server_key) = generate_keys(config); + set_server_key(server_key); + + let string1 = FheAsciiString::try_encrypt("tfhe-RS", &client_key).unwrap(); + let string2 = FheAsciiString::try_encrypt("TFHE-rs", &client_key).unwrap(); + let is_eq = string1.eq_ignore_case(&string2); + + assert!(is_eq.decrypt(&client_key)); + + Ok(()) +} +``` diff --git a/tfhe/src/test_user_docs.rs b/tfhe/src/test_user_docs.rs index 6b07880567..08a1169a00 100644 --- a/tfhe/src/test_user_docs.rs +++ b/tfhe/src/test_user_docs.rs @@ -101,6 +101,10 @@ mod test_cpu_doc { "../docs/fhe-computation/operations/ternary-conditional-operations.md", operations_ternary_conditional_operations ); + doctest!( + "../docs/fhe-computation/operations/string-operations.md", + operations_string_operations + ); // TOOLING doctest!("../docs/fhe-computation/tooling/debug.md", tooling_debug);