pub struct PublicKey<G: Group> { /* private fields */ }
Expand description
Implementations§
Source§impl<G: Group> PublicKey<G>
impl<G: Group> PublicKey<G>
Sourcepub fn encrypt<T, R: CryptoRng + RngCore>(
&self,
value: T,
rng: &mut R,
) -> Ciphertext<G>
pub fn encrypt<T, R: CryptoRng + RngCore>( &self, value: T, rng: &mut R, ) -> Ciphertext<G>
Encrypts a value for this key.
Sourcepub fn encrypt_element<R: CryptoRng + RngCore>(
&self,
value: G::Element,
rng: &mut R,
) -> Ciphertext<G>
pub fn encrypt_element<R: CryptoRng + RngCore>( &self, value: G::Element, rng: &mut R, ) -> Ciphertext<G>
Encrypts a group element.
Sourcepub fn encrypt_zero<R>(
&self,
rng: &mut R,
) -> (Ciphertext<G>, LogEqualityProof<G>)
pub fn encrypt_zero<R>( &self, rng: &mut R, ) -> (Ciphertext<G>, LogEqualityProof<G>)
Encrypts zero value and provides a zero-knowledge proof of encryption correctness.
Sourcepub fn verify_zero(
&self,
ciphertext: Ciphertext<G>,
proof: &LogEqualityProof<G>,
) -> Result<(), VerificationError>
pub fn verify_zero( &self, ciphertext: Ciphertext<G>, proof: &LogEqualityProof<G>, ) -> Result<(), VerificationError>
Verifies that this is an encryption of a zero value.
§Errors
Returns an error if the proof
does not verify.
Sourcepub fn encrypt_bool<R: CryptoRng + RngCore>(
&self,
value: bool,
rng: &mut R,
) -> (Ciphertext<G>, RingProof<G>)
pub fn encrypt_bool<R: CryptoRng + RngCore>( &self, value: bool, rng: &mut R, ) -> (Ciphertext<G>, RingProof<G>)
Encrypts a boolean value (0 or 1) and provides a zero-knowledge proof of encryption correctness.
§Examples
See Ciphertext
docs for an example of usage.
Sourcepub fn verify_bool(
&self,
ciphertext: Ciphertext<G>,
proof: &RingProof<G>,
) -> Result<(), VerificationError>
pub fn verify_bool( &self, ciphertext: Ciphertext<G>, proof: &RingProof<G>, ) -> Result<(), VerificationError>
Verifies a proof of encryption correctness of a boolean value, which was presumably
obtained via Self::encrypt_bool()
.
§Errors
Returns an error if the proof
does not verify.
§Examples
See Ciphertext
docs for an example of usage.
Sourcepub fn encrypt_range<R: CryptoRng + RngCore>(
&self,
range: &PreparedRange<G>,
value: u64,
rng: &mut R,
) -> (Ciphertext<G>, RangeProof<G>)
pub fn encrypt_range<R: CryptoRng + RngCore>( &self, range: &PreparedRange<G>, value: u64, rng: &mut R, ) -> (Ciphertext<G>, RangeProof<G>)
Encrypts value
and provides a zero-knowledge proof that it lies in the specified range
.
§Panics
Panics if value
is out of range
.
§Examples
See Ciphertext
docs for an example of usage.
Sourcepub fn verify_range(
&self,
range: &PreparedRange<G>,
ciphertext: Ciphertext<G>,
proof: &RangeProof<G>,
) -> Result<(), VerificationError>
pub fn verify_range( &self, range: &PreparedRange<G>, ciphertext: Ciphertext<G>, proof: &RangeProof<G>, ) -> Result<(), VerificationError>
Verifies proof
that ciphertext
encrypts a value lying in range
.
The proof
should be created with a call to Self::encrypt_range()
with the same
PreparedRange
; otherwise, the proof will not verify.
§Errors
Returns an error if the proof
does not verify.
Source§impl<G: Group> PublicKey<G>
impl<G: Group> PublicKey<G>
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, PublicKeyConversionError>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, PublicKeyConversionError>
Deserializes a public key from bytes.
§Errors
Returns an error if bytes
has invalid byte size, does not represent a valid group element
or represents the group identity.
Sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Returns bytes representing the group element corresponding to this key.
Sourcepub fn as_element(&self) -> G::Element
pub fn as_element(&self) -> G::Element
Returns the group element equivalent to this key.
Trait Implementations§
Source§impl<'de, G: Group> Deserialize<'de> for PublicKey<G>
impl<'de, G: Group> Deserialize<'de> for PublicKey<G>
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Auto Trait Implementations§
impl<G> Freeze for PublicKey<G>
impl<G> RefUnwindSafe for PublicKey<G>
impl<G> Send for PublicKey<G>
impl<G> Sync for PublicKey<G>
impl<G> Unpin for PublicKey<G>
impl<G> UnwindSafe for PublicKey<G>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)