identity_jose/jwk/curve/bls.rs
1// Copyright 2020-2024 IOTA Stiftung, Fondazione Links
2// SPDX-License-Identifier: Apache-2.0
3
4use core::fmt::Display;
5use core::fmt::Formatter;
6use core::fmt::Result;
7
8/// Supported BLS Curves.
9///
10/// [More Info](https://datatracker.ietf.org/doc/html/draft-ietf-cose-bls-key-representations-05#name-curve-parameter-registratio)
11#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
12pub enum BlsCurve {
13 /// A cryptographic key on the Barreto-Lynn-Scott (BLS) curve featuring an embedding degree 12 with 381-bit p in the
14 /// subgroup of G1.
15 BLS12381G1,
16 /// A cryptographic key on the Barreto-Lynn-Scott (BLS) curve featuring an embedding degree 12 with 381-bit p in the
17 /// subgroup of G2.
18 BLS12381G2,
19 /// A cryptographic key on the Barreto-Lynn-Scott (BLS) curve featuring an embedding degree 48 with 581-bit p in the
20 /// subgroup of G1.
21 BLS48581G1,
22 /// A cryptographic key on the Barreto-Lynn-Scott (BLS) curve featuring an embedding degree 48 with 581-bit p in the
23 /// subgroup of G2.
24 BLS48581G2,
25}
26
27impl BlsCurve {
28 /// Returns the name of the curve as a string slice.
29 pub const fn name(self) -> &'static str {
30 match self {
31 Self::BLS12381G1 => "BLS12381G1",
32 Self::BLS12381G2 => "BLS12381G2",
33 Self::BLS48581G1 => "BLS48581G1",
34 Self::BLS48581G2 => "BLS48581G2",
35 }
36 }
37}
38
39impl Display for BlsCurve {
40 fn fmt(&self, f: &mut Formatter<'_>) -> Result {
41 f.write_str(self.name())
42 }
43}