diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2021-10-06 14:31:12 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2022-05-12 17:57:11 +0200 |
commit | 9190e983315c9421ae4b6829997f161141a733c5 (patch) | |
tree | 2fa75b992f9933b1b5344471a9b0a4690df62806 | |
parent | a0afd6bffafa208751fc1b736bb4a3f7a2c9bd24 (diff) |
openpgp: Add MPI::zero and MPI::is_zero.
-rw-r--r-- | openpgp/NEWS | 2 | ||||
-rw-r--r-- | openpgp/src/crypto/mpi.rs | 10 |
2 files changed, 12 insertions, 0 deletions
diff --git a/openpgp/NEWS b/openpgp/NEWS index 69887b90..77998d4e 100644 --- a/openpgp/NEWS +++ b/openpgp/NEWS @@ -6,6 +6,8 @@ ** New functionality - AEADAlgorithm::nonce_size replaces AEADAlgorithm::iv_size - crypto::backend + - MPI::is_zero + - MPI::zero - packet::Any - Packet::version - SignatureBuilder::set_reference_time diff --git a/openpgp/src/crypto/mpi.rs b/openpgp/src/crypto/mpi.rs index 9e34f96f..e21ba98a 100644 --- a/openpgp/src/crypto/mpi.rs +++ b/openpgp/src/crypto/mpi.rs @@ -117,6 +117,16 @@ impl MPI { val } + /// Creates a new MPI representing zero. + pub fn zero() -> Self { + Self::new(&[]) + } + + /// Tests whether the MPI represents zero. + pub fn is_zero(&self) -> bool { + self.value().is_empty() + } + /// Returns the length of the MPI in bits. /// /// Leading zero-bits are not included in the returned size. |