Skip to content

Commit

Permalink
fix(hlapi): fixes after strings move
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeul-zama committed Oct 24, 2024
1 parent beb36dc commit faf6d3e
Show file tree
Hide file tree
Showing 16 changed files with 148 additions and 215 deletions.
2 changes: 1 addition & 1 deletion tfhe/src/strings/assert_functions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
mod test_vectors;

use super::*;
use crate::ciphertext::{ClearString, GenericPattern};
use crate::strings::ciphertext::{ClearString, GenericPattern};
use std::time::Duration;

fn result_message<T>(str: &str, expected: T, dec: T, dur: Duration)
Expand Down
2 changes: 1 addition & 1 deletion tfhe/src/strings/assert_functions/test_vectors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::Keys;
use crate::strings::Keys;

const TEST_CASES_MATCH: [(&str, u32); 15] = [
("", 0),
Expand Down
10 changes: 5 additions & 5 deletions tfhe/src/strings/ciphertext.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::client_key::{ClientKey, EncU16};
use crate::server_key::ServerKey;
use crate::N;
use tfhe::integer::{IntegerCiphertext, IntegerRadixCiphertext, RadixCiphertext};
use crate::strings::client_key::{ClientKey, EncU16};
use crate::strings::server_key::ServerKey;
use crate::strings::N;
use crate::integer::{IntegerCiphertext, IntegerRadixCiphertext, RadixCiphertext};

/// Represents a encrypted ASCII character.
#[derive(Clone)]
Expand Down Expand Up @@ -189,7 +189,7 @@ impl FheString {
#[cfg(test)]
mod tests {
use super::*;
use crate::server_key::gen_keys;
use crate::strings::server_key::gen_keys;

#[test]
fn test_uint_conversion() {
Expand Down
6 changes: 3 additions & 3 deletions tfhe/src/strings/client_key.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::ciphertext::{FheAsciiChar, FheString};
use tfhe::integer::{ClientKey as FheClientKey, RadixCiphertext};
use tfhe::shortint::prelude::PARAM_MESSAGE_2_CARRY_2;
use crate::integer::{ClientKey as FheClientKey, RadixCiphertext};
use crate::shortint::prelude::PARAM_MESSAGE_2_CARRY_2;
use crate::strings::ciphertext::{FheAsciiChar, FheString};

/// Represents a client key for encryption and decryption of strings.
#[derive(serde::Serialize, serde::Deserialize, Clone)]
Expand Down
111 changes: 22 additions & 89 deletions tfhe/src/strings/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::ciphertext::{FheString, UIntArg};
use crate::client_key::ClientKey;
use crate::server_key::{gen_keys, FheStringIsEmpty, FheStringIterator, FheStringLen, ServerKey};
use clap::{value_parser, Arg, Command};
use crate::strings::ciphertext::{FheString, UIntArg};
use crate::strings::client_key::ClientKey;
use crate::strings::server_key::{
gen_keys, FheStringIsEmpty, FheStringIterator, FheStringLen, ServerKey,
};
// use clap::{value_parser, Arg, Command};
use std::time::Instant;

pub mod ciphertext;
Expand All @@ -14,92 +16,23 @@ mod assert_functions;
// ClearString
const N: usize = 4;

fn main() {
let matches = Command::new("FHE str API")
.arg(
Arg::new("string")
.long("str")
.help("str that will be used for the functions")
.allow_hyphen_values(true)
.required(true)
)
.arg(
Arg::new("string_padding")
.long("str_pad")
.help("the number of padding nulls to use in str")
.value_parser(value_parser!(u32))
)
.arg(
Arg::new("pattern")
.long("pat")
.help("pat that will be used for the functions")
.allow_hyphen_values(true)
.required(true)
)
.arg(
Arg::new("pattern_padding")
.long("pat_pad")
.help("the number of padding nulls to use in pat")
.value_parser(value_parser!(u32))
)
.arg(
Arg::new("to")
.long("to")
.help("the argument used to replace the pattern in `replace` and `replacen`")
.allow_hyphen_values(true)
.required(true)
)
.arg(
Arg::new("to_padding")
.long("to_pad")
.help("The number of padding nulls to use in to")
.value_parser(value_parser!(u32))
)
.arg(
Arg::new("rhs")
.long("rhs")
.help("The right side string used in `concat` and all comparisons")
.allow_hyphen_values(true)
.required(true)
)
.arg(
Arg::new("rhs_padding")
.long("rhs_pad")
.help("The number of padding nulls to use in rhs")
.value_parser(value_parser!(u32))
)
.arg(
Arg::new("count")
.long("n")
.help("The count number that will be used in some functions like `replacen` and `splitn`")
.value_parser(value_parser!(u16))
.required(true)
)
.arg(
Arg::new("max_count")
.long("max")
.help("The max number that the n argument can take (useful for when n is encrypted, \
as we need a worst case scenario of how many times we will repeat something)")
.value_parser(value_parser!(u16))
.required(true)
)
.get_matches();

let str = matches.get_one::<String>("string").unwrap();
let str_pad = matches.get_one("string_padding").copied();

let pat = matches.get_one::<String>("pattern").unwrap();
let pat_pad = matches.get_one("pattern_padding").copied();

let to = matches.get_one::<String>("to").unwrap();
let to_pad: Option<u32> = matches.get_one("to_padding").copied();

let rhs = matches.get_one::<String>("rhs").unwrap();
let rhs_pad = matches.get_one("rhs_padding").copied();

let n: u16 = matches.get_one("count").copied().unwrap();
let max: u16 = matches.get_one("max_count").copied().unwrap();
#[test]
fn test_all2() {
test_all("", None, "", None, "", None, "", None, 0, 0);
}

pub fn test_all(
str: &str,
str_pad: Option<u32>,
pat: &str,
pat_pad: Option<u32>,
to: &str,
to_pad: Option<u32>,
rhs: &str,
rhs_pad: Option<u32>,
n: u16,
max: u16,
) {
let keys = Keys::new();

keys.assert_len(str, str_pad);
Expand Down
30 changes: 15 additions & 15 deletions tfhe/src/strings/server_key/comp.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::ciphertext::{FheString, GenericPattern};
use crate::server_key::{FheStringIsEmpty, ServerKey};
use tfhe::integer::BooleanBlock;
use crate::integer::BooleanBlock;
use crate::strings::ciphertext::{FheString, GenericPattern};
use crate::strings::server_key::{FheStringIsEmpty, ServerKey};

impl ServerKey {
fn eq_length_checks(&self, lhs: &FheString, rhs: &FheString) -> Option<BooleanBlock> {
Expand Down Expand Up @@ -53,8 +53,8 @@ impl ServerKey {
/// # Examples
///
/// ```rust
/// use crate::ciphertext::{FheString, GenericPattern};
/// use crate::server_key::gen_keys;
/// use tfhe::strings::ciphertext::{FheString, GenericPattern};
/// use tfhe::strings::server_key::gen_keys;
///
/// let (ck, sk) = gen_keys();
/// let (s1, s2) = ("hello", "hello");
Expand Down Expand Up @@ -107,8 +107,8 @@ impl ServerKey {
/// # Examples
///
/// ```rust
/// use crate::ciphertext::{FheString, GenericPattern};
/// use crate::server_key::gen_keys;
/// use tfhe::strings::ciphertext::{FheString, GenericPattern};
/// use tfhe::strings::server_key::gen_keys;
///
/// let (ck, sk) = gen_keys();
/// let (s1, s2) = ("hello", "world");
Expand All @@ -134,8 +134,8 @@ impl ServerKey {
/// # Examples
///
/// ```rust
/// use crate::ciphertext::FheString;
/// use crate::server_key::gen_keys;
/// use tfhe::strings::ciphertext::FheString;
/// use tfhe::strings::server_key::gen_keys;
///
/// let (ck, sk) = gen_keys();
/// let (s1, s2) = ("apple", "banana");
Expand Down Expand Up @@ -164,8 +164,8 @@ impl ServerKey {
/// # Examples
///
/// ```rust
/// use crate::ciphertext::FheString;
/// use crate::server_key::gen_keys;
/// use tfhe::strings::ciphertext::FheString;
/// use tfhe::strings::server_key::gen_keys;
///
/// let (ck, sk) = gen_keys();
/// let (s1, s2) = ("banana", "apple");
Expand Down Expand Up @@ -195,8 +195,8 @@ impl ServerKey {
/// # Examples
///
/// ```rust
/// use crate::ciphertext::FheString;
/// use crate::server_key::gen_keys;
/// use tfhe::strings::ciphertext::FheString;
/// use tfhe::strings::server_key::gen_keys;
///
/// let (ck, sk) = gen_keys();
/// let (s1, s2) = ("apple", "banana");
Expand Down Expand Up @@ -226,8 +226,8 @@ impl ServerKey {
/// # Examples
///
/// ```rust
/// use crate::ciphertext::FheString;
/// use crate::server_key::gen_keys;
/// use tfhe::strings::ciphertext::FheString;
/// use tfhe::strings::server_key::gen_keys;
///
/// let (ck, sk) = gen_keys();
/// let (s1, s2) = ("banana", "apple");
Expand Down
12 changes: 6 additions & 6 deletions tfhe/src/strings/server_key/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ mod no_patterns;
mod pattern;
mod trim;

use crate::ciphertext::{FheAsciiChar, FheString};
use crate::client_key::ClientKey;
use crate::N;
use crate::integer::bigint::static_unsigned::StaticUnsignedBigInt;
use crate::integer::prelude::*;
use crate::integer::{BooleanBlock, RadixCiphertext, ServerKey as FheServerKey};
use crate::strings::ciphertext::{FheAsciiChar, FheString};
use crate::strings::client_key::ClientKey;
use crate::strings::N;
use rayon::prelude::*;
use std::cmp::Ordering;
use tfhe::integer::bigint::static_unsigned::StaticUnsignedBigInt;
use tfhe::integer::prelude::*;
use tfhe::integer::{BooleanBlock, RadixCiphertext, ServerKey as FheServerKey};

/// Represents a server key to operate homomorphically on [`FheString`].
#[derive(serde::Serialize, serde::Deserialize, Clone)]
Expand Down
34 changes: 17 additions & 17 deletions tfhe/src/strings/server_key/no_patterns.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::ciphertext::{ClearString, FheString, GenericPattern, UIntArg};
use crate::server_key::{FheStringIsEmpty, FheStringLen, ServerKey};
use crate::integer::BooleanBlock;
use crate::strings::ciphertext::{ClearString, FheString, GenericPattern, UIntArg};
use crate::strings::server_key::{FheStringIsEmpty, FheStringLen, ServerKey};
use rayon::prelude::*;
use tfhe::integer::BooleanBlock;

impl ServerKey {
/// Returns the length of an encrypted string as an `FheStringLen` enum.
Expand All @@ -13,8 +13,8 @@ impl ServerKey {
/// # Examples
///
/// ```rust
/// use crate::ciphertext::FheString;
/// use crate::server_key::{gen_keys, FheStringLen};
/// use tfhe::strings::ciphertext::FheString;
/// use tfhe::strings::server_key::{gen_keys, FheStringLen};
///
/// let (ck, sk) = gen_keys();
/// let s = "hello";
Expand Down Expand Up @@ -72,8 +72,8 @@ impl ServerKey {
/// # Examples
///
/// ```rust
/// use crate::ciphertext::FheString;
/// use crate::server_key::{gen_keys, FheStringIsEmpty};
/// use tfhe::strings::ciphertext::FheString;
/// use tfhe::strings::server_key::{gen_keys, FheStringIsEmpty};
///
/// let (ck, sk) = gen_keys();
/// let s = "";
Expand Down Expand Up @@ -119,8 +119,8 @@ impl ServerKey {
/// # Examples
///
/// ```rust
/// use crate::ciphertext::FheString;
/// use crate::server_key::gen_keys;
/// use tfhe::strings::ciphertext::FheString;
/// use tfhe::strings::server_key::gen_keys;
///
/// let (ck, sk) = gen_keys();
/// let s = "Hello World";
Expand Down Expand Up @@ -172,8 +172,8 @@ impl ServerKey {
/// # Examples
///
/// ```rust
/// use crate::ciphertext::FheString;
/// use crate::server_key::gen_keys;
/// use tfhe::strings::ciphertext::FheString;
/// use tfhe::strings::server_key::gen_keys;
///
/// let (ck, sk) = gen_keys();
/// let s = "Hello World";
Expand Down Expand Up @@ -231,8 +231,8 @@ impl ServerKey {
/// # Examples
///
/// ```rust
/// use crate::ciphertext::{FheString, GenericPattern};
/// use crate::server_key::gen_keys;
/// use tfhe::strings::ciphertext::{FheString, GenericPattern};
/// use tfhe::strings::server_key::gen_keys;
///
/// let (ck, sk) = gen_keys();
/// let (s1, s2) = ("Hello", "hello");
Expand Down Expand Up @@ -266,8 +266,8 @@ impl ServerKey {
/// # Examples
///
/// ```rust
/// use crate::ciphertext::FheString;
/// use crate::server_key::gen_keys;
/// use tfhe::strings::ciphertext::FheString;
/// use tfhe::strings::server_key::gen_keys;
///
/// let (ck, sk) = gen_keys();
/// let (lhs, rhs) = ("Hello, ", "world!");
Expand Down Expand Up @@ -317,8 +317,8 @@ impl ServerKey {
/// # Examples
///
/// ```rust
/// use crate::ciphertext::{FheString, UIntArg};
/// use crate::server_key::gen_keys;
/// use tfhe::strings::ciphertext::{FheString, UIntArg};
/// use tfhe::strings::server_key::gen_keys;
///
/// let (ck, sk) = gen_keys();
/// let s = "hi";
Expand Down
Loading

0 comments on commit faf6d3e

Please sign in to comment.