diff options
author | Wiktor Kwapisiewicz <wiktor@metacode.biz> | 2023-05-30 12:32:57 +0200 |
---|---|---|
committer | Wiktor Kwapisiewicz <wiktor@metacode.biz> | 2023-06-06 11:23:29 +0200 |
commit | afad47bcb023fbcdbe67d5f0343fb32bfcf917f4 (patch) | |
tree | 3592694e02f85655da770e5d22f3dfa86856655c | |
parent | f5f9b14a304321816526c30ce98edbd6535df9c4 (diff) |
openpgp: Deprecate `types::Curve::len`.
- It does the same as `types::Curve::bits` (modulo the return type).
- Update `types::Curve::bits` documentation as well as a NEWS entry.
- Since it only returns the number of bits that is basically static
the `Result` return code is not needed (see [#966].
- Fixes https://gitlab.com/sequoia-pgp/sequoia/-/issues/988 but does
not remove `field_size` as it is useful in a small number of places.
- Related: https://gitlab.com/sequoia-pgp/sequoia/-/issues/765
[#966]: https://gitlab.com/sequoia-pgp/sequoia/-/issues/966
-rw-r--r-- | openpgp/NEWS | 2 | ||||
-rw-r--r-- | openpgp/src/crypto/mpi.rs | 2 | ||||
-rw-r--r-- | openpgp/src/types/mod.rs | 19 |
3 files changed, 9 insertions, 14 deletions
diff --git a/openpgp/NEWS b/openpgp/NEWS index 60db1dd3..7ccf8727 100644 --- a/openpgp/NEWS +++ b/openpgp/NEWS @@ -6,6 +6,8 @@ * Changes in 1.17.0 ** New functionality - types::AEADAlgorithm::GCM +** Deprecated functionality + - types::Curve::len, use types::Curve::bits instead * Changes in 1.16.0 ** New functionality - Add KeyFlags::set_certification_to. diff --git a/openpgp/src/crypto/mpi.rs b/openpgp/src/crypto/mpi.rs index fa27beb7..b0223460 100644 --- a/openpgp/src/crypto/mpi.rs +++ b/openpgp/src/crypto/mpi.rs @@ -216,7 +216,7 @@ impl MPI { => { // Length of one coordinate in bytes, rounded up. - let coordinate_length = (curve.len()? + 7) / 8; + let coordinate_length = curve.field_size()?; // Check length of Q. let expected_length = diff --git a/openpgp/src/types/mod.rs b/openpgp/src/types/mod.rs index 88fe1505..0a3bfe0b 100644 --- a/openpgp/src/types/mod.rs +++ b/openpgp/src/types/mod.rs @@ -381,6 +381,8 @@ impl Curve { /// For the Kobliz curves this is the size of the underlying /// finite field. For X25519 it is 256. /// + /// This value is also equal to the length of a coordinate in bits. + /// /// Note: This information is useless and should not be used to /// gauge the security of a particular curve. This function exists /// only because some legacy PGP application like HKP need it. @@ -578,20 +580,11 @@ impl Curve { /// /// Returns `Error::UnsupportedEllipticCurve` if the curve is not /// supported. + #[deprecated(note = "Use bits()", since = "1.17.0")] pub fn len(&self) -> Result<usize> { - match self { - Curve::NistP256 => Ok(256), - Curve::NistP384 => Ok(384), - Curve::NistP521 => Ok(521), - Curve::BrainpoolP256 => Ok(256), - Curve::Unknown(_) if self.is_brainpoolp384() => Ok(384), - Curve::BrainpoolP512 => Ok(512), - Curve::Ed25519 => Ok(256), - Curve::Cv25519 => Ok(256), - Curve::Unknown(_) => - Err(Error::UnsupportedEllipticCurve(self.clone()) - .into()), - } + self.bits() + .ok_or_else(|| Error::UnsupportedEllipticCurve(self.clone()).into()) + } /// Returns whether this algorithm is supported. |