Skip to content
Open
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
20 changes: 19 additions & 1 deletion pod/src/optional_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,27 @@ impl<'de> Deserialize<'de> for OptionalNonZeroPubkey {

/// An `ElGamalPubkey` that encodes `None` as all `0`, meant to be usable as a
/// `Pod` type.
#[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)]
#[deprecated(
since = "0.7.2",
note = "This type will be removed in a future version. Please use `OptionalNonZeroElGamalPubkey` directly from the `solana-zk-sdk`."
)]
#[derive(Clone, Copy, Debug, Default, PartialEq)]
#[repr(transparent)]
pub struct OptionalNonZeroElGamalPubkey(PodElGamalPubkey);
#[allow(deprecated)]
impl OptionalNonZeroElGamalPubkey {
/// Checks equality between an `OptionalNonZeroElGamalPubkey` and an
/// `ElGamalPubkey` when interpreted as bytes.
pub fn equals(&self, other: &PodElGamalPubkey) -> bool {
&self.0 == other
}
}
#[allow(deprecated)]
unsafe impl bytemuck::Zeroable for OptionalNonZeroElGamalPubkey {}

#[allow(deprecated)]
unsafe impl bytemuck::Pod for OptionalNonZeroElGamalPubkey {}
#[allow(deprecated)]
impl TryFrom<Option<PodElGamalPubkey>> for OptionalNonZeroElGamalPubkey {
type Error = ProgramError;
fn try_from(p: Option<PodElGamalPubkey>) -> Result<Self, Self::Error> {
Expand All @@ -155,6 +166,7 @@ impl TryFrom<Option<PodElGamalPubkey>> for OptionalNonZeroElGamalPubkey {
}
}
}
#[allow(deprecated)]
impl From<OptionalNonZeroElGamalPubkey> for Option<PodElGamalPubkey> {
fn from(p: OptionalNonZeroElGamalPubkey) -> Self {
if p.0 == PodElGamalPubkey::default() {
Expand All @@ -165,6 +177,7 @@ impl From<OptionalNonZeroElGamalPubkey> for Option<PodElGamalPubkey> {
}
}

#[allow(deprecated)]
#[cfg(feature = "serde-traits")]
impl Serialize for OptionalNonZeroElGamalPubkey {
fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
Expand All @@ -182,6 +195,7 @@ impl Serialize for OptionalNonZeroElGamalPubkey {
#[cfg(feature = "serde-traits")]
struct OptionalNonZeroElGamalPubkeyVisitor;

#[allow(deprecated)]
#[cfg(feature = "serde-traits")]
impl Visitor<'_> for OptionalNonZeroElGamalPubkeyVisitor {
type Value = OptionalNonZeroElGamalPubkey;
Expand All @@ -206,6 +220,7 @@ impl Visitor<'_> for OptionalNonZeroElGamalPubkeyVisitor {
}
}

#[allow(deprecated)]
#[cfg(feature = "serde-traits")]
impl<'de> Deserialize<'de> for OptionalNonZeroElGamalPubkey {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
Expand Down Expand Up @@ -297,6 +312,7 @@ mod tests {
}

#[test]
#[allow(deprecated)]
fn test_pod_non_zero_elgamal_option() {
assert_eq!(
Some(elgamal_pubkey_from_bytes(
Expand Down Expand Up @@ -327,6 +343,7 @@ mod tests {

#[cfg(feature = "serde-traits")]
#[test]
#[allow(deprecated)]
fn test_pod_non_zero_elgamal_option_serde_some() {
let optional_non_zero_elgamal_pubkey_some = OptionalNonZeroElGamalPubkey(
elgamal_pubkey_from_bytes(&[1; OPTIONAL_NONZERO_ELGAMAL_PUBKEY_LEN]),
Expand All @@ -345,6 +362,7 @@ mod tests {

#[cfg(feature = "serde-traits")]
#[test]
#[allow(deprecated)]
fn test_pod_non_zero_elgamal_option_serde_none() {
let optional_non_zero_elgamal_pubkey_none = OptionalNonZeroElGamalPubkey(
elgamal_pubkey_from_bytes(&[0; OPTIONAL_NONZERO_ELGAMAL_PUBKEY_LEN]),
Expand Down
Loading