Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(backward): use the Deprecated type from tfhe-versionable #1710

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
use tfhe_versionable::{Upgrade, Version, VersionsDispatch};
use tfhe_versionable::deprecation::{Deprecable, Deprecated};
use tfhe_versionable::VersionsDispatch;

use crate::core_crypto::prelude::{Container, SeededLweKeyswitchKey, UnsignedInteger};

#[derive(Version)]
pub struct UnsupportedSeededLweKeyswitchKeyV0;

impl<Scalar: UnsignedInteger, C: Container<Element = Scalar>> Upgrade<SeededLweKeyswitchKey<C>>
for UnsupportedSeededLweKeyswitchKeyV0
impl<C: Container> Deprecable for SeededLweKeyswitchKey<C>
where
C::Element: UnsignedInteger,
{
type Error = crate::Error;

fn upgrade(self) -> Result<SeededLweKeyswitchKey<C>, Self::Error> {
Err(crate::Error::new(
"Unable to load SeededLweKeyswitchKey, \
this format is unsupported by this TFHE-rs version."
.to_string(),
))
}
const TYPE_NAME: &'static str = "SeededLweKeyswitchKey";
const MIN_SUPPORTED_APP_VERSION: &'static str = "TFHE-rs v0.9";
}

#[derive(VersionsDispatch)]
pub enum SeededLweKeyswitchKeyVersions<C: Container>
where
C::Element: UnsignedInteger,
{
V0(UnsupportedSeededLweKeyswitchKeyV0),
V0(Deprecated<SeededLweKeyswitchKey<C>>),
V1(SeededLweKeyswitchKey<C>),
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
use tfhe_versionable::{Upgrade, Version, VersionsDispatch};
use tfhe_versionable::deprecation::{Deprecable, Deprecated};
use tfhe_versionable::VersionsDispatch;

use crate::core_crypto::prelude::{Container, SeededLwePackingKeyswitchKey, UnsignedInteger};

#[derive(Version)]
pub struct UnsupportedSeededLwePackingKeyswitchKeyV0;

impl<Scalar: UnsignedInteger, C: Container<Element = Scalar>>
Upgrade<SeededLwePackingKeyswitchKey<C>> for UnsupportedSeededLwePackingKeyswitchKeyV0
impl<C: Container> Deprecable for SeededLwePackingKeyswitchKey<C>
where
C::Element: UnsignedInteger,
{
type Error = crate::Error;

fn upgrade(self) -> Result<SeededLwePackingKeyswitchKey<C>, Self::Error> {
Err(crate::Error::new(
"Unable to load SeededLwePackingKeyswitchKey, \
this format is unsupported by this TFHE-rs version."
.to_string(),
))
}
const TYPE_NAME: &'static str = "SeededLwePackingKeyswitchKey";
const MIN_SUPPORTED_APP_VERSION: &'static str = "TFHE-rs v0.9";
}

#[derive(VersionsDispatch)]
pub enum SeededLwePackingKeyswitchKeyVersions<C: Container>
where
C::Element: UnsignedInteger,
{
V0(UnsupportedSeededLwePackingKeyswitchKeyV0),
V0(Deprecated<SeededLwePackingKeyswitchKey<C>>),
V1(SeededLwePackingKeyswitchKey<C>),
}
89 changes: 15 additions & 74 deletions tfhe/src/high_level_api/backward_compatibility/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::high_level_api::keys::*;
use crate::Tag;
use std::convert::Infallible;
use std::sync::Arc;
use tfhe_versionable::deprecation::{Deprecable, Deprecated};
use tfhe_versionable::{Upgrade, Version, VersionsDispatch};

#[derive(VersionsDispatch)]
Expand Down Expand Up @@ -183,34 +184,9 @@ pub(crate) enum IntegerConfigVersions {
V0(IntegerConfig),
}

#[derive(Version)]
pub struct UnsupportedIntegerClientKeyV0;

#[derive(Version)]
pub struct UnsupportedIntegerClientKeyV1;

impl Upgrade<UnsupportedIntegerClientKeyV1> for UnsupportedIntegerClientKeyV0 {
type Error = crate::Error;

fn upgrade(self) -> Result<UnsupportedIntegerClientKeyV1, Self::Error> {
Err(crate::Error::new(
"Unable to load IntegerClientKey, \
this format is unsupported by this TFHE-rs version."
.to_string(),
))
}
}

impl Upgrade<IntegerClientKeyV2> for UnsupportedIntegerClientKeyV1 {
type Error = crate::Error;

fn upgrade(self) -> Result<IntegerClientKeyV2, Self::Error> {
Err(crate::Error::new(
"Unable to load IntegerClientKey, \
this format is unsupported by this TFHE-rs version."
.to_string(),
))
}
impl Deprecable for IntegerClientKey {
const TYPE_NAME: &'static str = "IntegerClientKey";
const MIN_SUPPORTED_APP_VERSION: &'static str = "TFHE-rs v0.8";
}

#[derive(Version)]
Expand All @@ -237,40 +213,15 @@ impl Upgrade<IntegerClientKey> for IntegerClientKeyV2 {
#[derive(VersionsDispatch)]
#[allow(unused)]
pub(crate) enum IntegerClientKeyVersions {
V0(UnsupportedIntegerClientKeyV0),
V1(UnsupportedIntegerClientKeyV1),
V0(Deprecated<IntegerClientKey>),
V1(Deprecated<IntegerClientKey>),
V2(IntegerClientKeyV2),
V3(IntegerClientKey),
}

#[derive(Version)]
pub struct UnsupportedIntegerServerKeyV0;

#[derive(Version)]
pub struct UnsupportedIntegerServerKeyV1;

impl Upgrade<UnsupportedIntegerServerKeyV1> for UnsupportedIntegerServerKeyV0 {
type Error = crate::Error;

fn upgrade(self) -> Result<UnsupportedIntegerServerKeyV1, Self::Error> {
Err(crate::Error::new(
"Unable to load IntegerServerKey, \
this format is unsupported by this TFHE-rs version."
.to_string(),
))
}
}

impl Upgrade<IntegerServerKeyV2> for UnsupportedIntegerServerKeyV1 {
type Error = crate::Error;

fn upgrade(self) -> Result<IntegerServerKeyV2, Self::Error> {
Err(crate::Error::new(
"Unable to load IntegerServerKey, \
this format is unsupported by this TFHE-rs version."
.to_string(),
))
}
impl Deprecable for IntegerServerKey {
const TYPE_NAME: &'static str = "IntegerServerKey";
const MIN_SUPPORTED_APP_VERSION: &'static str = "TFHE-rs v0.8";
}

#[derive(Version)]
Expand Down Expand Up @@ -301,30 +252,20 @@ impl Upgrade<IntegerServerKey> for IntegerServerKeyV2 {

#[derive(VersionsDispatch)]
pub enum IntegerServerKeyVersions {
V0(UnsupportedIntegerServerKeyV0),
V1(UnsupportedIntegerServerKeyV1),
V0(Deprecated<IntegerServerKey>),
V1(Deprecated<IntegerServerKey>),
V2(IntegerServerKeyV2),
V3(IntegerServerKey),
}

#[derive(Version)]
pub struct UnsupportedIntegerCompressedServerKeyV0;

impl Upgrade<IntegerCompressedServerKey> for UnsupportedIntegerCompressedServerKeyV0 {
type Error = crate::Error;

fn upgrade(self) -> Result<IntegerCompressedServerKey, Self::Error> {
Err(crate::Error::new(
"Unable to load IntegerCompressedServerKey, \
this format is unsupported by this TFHE-rs version."
.to_string(),
))
}
impl Deprecable for IntegerCompressedServerKey {
const TYPE_NAME: &'static str = "IntegerCompressedServerKey";
const MIN_SUPPORTED_APP_VERSION: &'static str = "TFHE-rs v0.9";
}

#[derive(VersionsDispatch)]
pub enum IntegerCompressedServerKeyVersions {
V0(UnsupportedIntegerCompressedServerKeyV0),
V0(Deprecated<IntegerCompressedServerKey>),
V1(IntegerCompressedServerKey),
}

Expand Down
39 changes: 10 additions & 29 deletions tfhe/src/integer/backward_compatibility/key_switching_key.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use tfhe_versionable::{Upgrade, Version, VersionsDispatch};
use tfhe_versionable::deprecation::{Deprecable, Deprecated};
use tfhe_versionable::VersionsDispatch;

use crate::integer::key_switching_key::{
CompressedKeySwitchingKey, CompressedKeySwitchingKeyMaterial, KeySwitchingKey,
Expand All @@ -15,44 +16,24 @@ pub enum KeySwitchingKeyVersions {
V0(KeySwitchingKey),
}

#[derive(Version)]
pub struct UnsupportedCompressedKeySwitchingKeyMaterialV0;

impl Upgrade<CompressedKeySwitchingKeyMaterial> for UnsupportedCompressedKeySwitchingKeyMaterialV0 {
type Error = crate::Error;

fn upgrade(self) -> Result<CompressedKeySwitchingKeyMaterial, Self::Error> {
Err(crate::Error::new(
"Unable to load CompressedKeySwitchingKeyMaterial, \
this format is unsupported by this TFHE-rs version."
.to_string(),
))
}
impl Deprecable for CompressedKeySwitchingKeyMaterial {
const TYPE_NAME: &'static str = "CompressedKeySwitchingKeyMaterial";
const MIN_SUPPORTED_APP_VERSION: &'static str = "TFHE-rs v0.9";
}

#[derive(VersionsDispatch)]
pub enum CompressedKeySwitchingKeyMaterialVersions {
V0(UnsupportedCompressedKeySwitchingKeyMaterialV0),
V0(Deprecated<CompressedKeySwitchingKeyMaterial>),
V1(CompressedKeySwitchingKeyMaterial),
}

#[derive(Version)]
pub struct UnsupportedCompressedKeySwitchingKeyV0;

impl Upgrade<CompressedKeySwitchingKey> for UnsupportedCompressedKeySwitchingKeyV0 {
type Error = crate::Error;

fn upgrade(self) -> Result<CompressedKeySwitchingKey, Self::Error> {
Err(crate::Error::new(
"Unable to load CompressedKeySwitchingKey, \
this format is unsupported by this TFHE-rs version."
.to_string(),
))
}
impl Deprecable for CompressedKeySwitchingKey {
const TYPE_NAME: &'static str = "CompressedKeySwitchingKey";
const MIN_SUPPORTED_APP_VERSION: &'static str = "TFHE-rs v0.9";
}

#[derive(VersionsDispatch)]
pub enum CompressedKeySwitchingKeyVersions {
V0(UnsupportedCompressedKeySwitchingKeyV0),
V0(Deprecated<CompressedKeySwitchingKey>),
V1(CompressedKeySwitchingKey),
}
21 changes: 6 additions & 15 deletions tfhe/src/integer/backward_compatibility/list_compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use crate::integer::compression_keys::{
CompressedCompressionKey, CompressedDecompressionKey, CompressionKey, CompressionPrivateKeys,
DecompressionKey,
};
use tfhe_versionable::{Upgrade, Version, VersionsDispatch};
use tfhe_versionable::deprecation::{Deprecable, Deprecated};
use tfhe_versionable::VersionsDispatch;

#[derive(VersionsDispatch)]
pub enum CompressionKeyVersions {
Expand All @@ -14,24 +15,14 @@ pub enum DecompressionKeyVersions {
V0(DecompressionKey),
}

#[derive(Version)]
pub struct UnsupportedCompressedCompressionKeyV0;

impl Upgrade<CompressedCompressionKey> for UnsupportedCompressedCompressionKeyV0 {
type Error = crate::Error;

fn upgrade(self) -> Result<CompressedCompressionKey, Self::Error> {
Err(crate::Error::new(
"Unable to load CompressedCompressionKey, \
this format is unsupported by this TFHE-rs version."
.to_string(),
))
}
impl Deprecable for CompressedCompressionKey {
const TYPE_NAME: &'static str = "CompressedCompressionKey";
const MIN_SUPPORTED_APP_VERSION: &'static str = "TFHE-rs v0.9";
}

#[derive(VersionsDispatch)]
pub enum CompressedCompressionKeyVersions {
V0(UnsupportedCompressedCompressionKeyV0),
V0(Deprecated<CompressedCompressionKey>),
V1(CompressedCompressionKey),
}

Expand Down
21 changes: 6 additions & 15 deletions tfhe/src/integer/backward_compatibility/server_key/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use tfhe_versionable::{Upgrade, Version, VersionsDispatch};
use tfhe_versionable::deprecation::{Deprecable, Deprecated};
use tfhe_versionable::VersionsDispatch;

use crate::integer::{CompressedServerKey, ServerKey};

Expand All @@ -7,23 +8,13 @@ pub enum ServerKeyVersions {
V0(ServerKey),
}

#[derive(Version)]
pub struct UnsupportedCompressedServerKeyV0;

impl Upgrade<CompressedServerKey> for UnsupportedCompressedServerKeyV0 {
type Error = crate::Error;

fn upgrade(self) -> Result<CompressedServerKey, Self::Error> {
Err(crate::Error::new(
"Unable to load CompressedServerKey, \
this format is unsupported by this TFHE-rs version."
.to_string(),
))
}
impl Deprecable for CompressedServerKey {
const TYPE_NAME: &'static str = "CompressedServerKey";
const MIN_SUPPORTED_APP_VERSION: &'static str = "TFHE-rs v0.9";
}

#[derive(VersionsDispatch)]
pub enum CompressedServerKeyVersions {
V0(UnsupportedCompressedServerKeyV0),
V0(Deprecated<CompressedServerKey>),
V1(CompressedServerKey),
}
39 changes: 10 additions & 29 deletions tfhe/src/shortint/backward_compatibility/key_switching_key.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use tfhe_versionable::{Upgrade, Version, VersionsDispatch};
use tfhe_versionable::deprecation::{Deprecable, Deprecated};
use tfhe_versionable::VersionsDispatch;

use crate::shortint::key_switching_key::{
CompressedKeySwitchingKeyMaterial, KeySwitchingKeyMaterial,
Expand All @@ -15,44 +16,24 @@ pub enum KeySwitchingKeyVersions {
V0(KeySwitchingKey),
}

#[derive(Version)]
pub struct UnsupportedCompressedKeySwitchingKeyMaterialV0;

impl Upgrade<CompressedKeySwitchingKeyMaterial> for UnsupportedCompressedKeySwitchingKeyMaterialV0 {
type Error = crate::Error;

fn upgrade(self) -> Result<CompressedKeySwitchingKeyMaterial, Self::Error> {
Err(crate::Error::new(
"Unable to load CompressedKeySwitchingKeyMaterial, \
this format is unsupported by this TFHE-rs version."
.to_string(),
))
}
impl Deprecable for CompressedKeySwitchingKeyMaterial {
const TYPE_NAME: &'static str = "CompressedKeySwitchingKeyMaterial";
const MIN_SUPPORTED_APP_VERSION: &'static str = "TFHE-rs v0.9";
}

#[derive(VersionsDispatch)]
pub enum CompressedKeySwitchingKeyMaterialVersions {
V0(UnsupportedCompressedKeySwitchingKeyMaterialV0),
V0(Deprecated<CompressedKeySwitchingKeyMaterial>),
V1(CompressedKeySwitchingKeyMaterial),
}

#[derive(Version)]
pub struct UnsupportedCompressedKeySwitchingKeyV0;

impl Upgrade<CompressedKeySwitchingKey> for UnsupportedCompressedKeySwitchingKeyV0 {
type Error = crate::Error;

fn upgrade(self) -> Result<CompressedKeySwitchingKey, Self::Error> {
Err(crate::Error::new(
"Unable to load CompressedKeySwitchingKey, \
this format is unsupported by this TFHE-rs version."
.to_string(),
))
}
impl Deprecable for CompressedKeySwitchingKey {
const TYPE_NAME: &'static str = "CompressedKeySwitchingKey";
const MIN_SUPPORTED_APP_VERSION: &'static str = "TFHE-rs v0.9";
}

#[derive(VersionsDispatch)]
pub enum CompressedKeySwitchingKeyVersions {
V0(UnsupportedCompressedKeySwitchingKeyV0),
V0(Deprecated<CompressedKeySwitchingKey>),
V1(CompressedKeySwitchingKey),
}
Loading
Loading