summaryrefslogtreecommitdiffstats
path: root/openpgp/src/constants.rs
diff options
context:
space:
mode:
authorKai Michaelis <kai@sequoia-pgp.org>2019-01-08 14:39:12 +0100
committerKai Michaelis <kai@sequoia-pgp.org>2019-01-09 12:03:49 +0100
commit3f89bf4477018c5bd75b78253c1fed68baa4e424 (patch)
treef4894b5e8ac4fbb048febf7e869e4cbb9804bd5f /openpgp/src/constants.rs
parent8433faaa9328ce6516722af73ba92422bb5557c7 (diff)
openpgp: implement PublicKey::bits() and Curve::bits()
Hagrind needs this information to correctly implement HKP.
Diffstat (limited to 'openpgp/src/constants.rs')
-rw-r--r--openpgp/src/constants.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/openpgp/src/constants.rs b/openpgp/src/constants.rs
index 60176f06..4b0c568b 100644
--- a/openpgp/src/constants.rs
+++ b/openpgp/src/constants.rs
@@ -168,6 +168,29 @@ pub enum Curve {
Unknown(Box<[u8]>),
}
+impl Curve {
+ /// Returns the 'bits' of the curve.
+ ///
+ /// For the Kobliz curves this is the size of the underlying finite field.
+ /// For X25519 it's 128. 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.
+ pub fn bits(&self) -> usize {
+ use self::Curve::*;
+
+ match self {
+ NistP256 => 256,
+ NistP384 => 384,
+ NistP521 => 521,
+ BrainpoolP256 => 256,
+ BrainpoolP512 => 512,
+ Ed25519 => 128,
+ Cv25519 => 128,
+ Unknown(_) => 0,
+ }
+ }
+}
+
impl fmt::Display for Curve {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::Curve::*;