Skip to content

Commit 92dca6b

Browse files
authored
Merge pull request #1947 from reaperhulk/ec-more
add get_asn1_flag to EcGroupRef
2 parents d5cc54b + 37966b3 commit 92dca6b

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

openssl-sys/src/handwritten/ec.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ extern "C" {
4646

4747
pub fn EC_GROUP_set_asn1_flag(key: *mut EC_GROUP, flag: c_int);
4848

49+
pub fn EC_GROUP_get_asn1_flag(group: *const EC_GROUP) -> c_int;
50+
4951
pub fn EC_GROUP_get_curve_GFp(
5052
group: *const EC_GROUP,
5153
p: *mut BIGNUM,

openssl/src/ec.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl PointConversionForm {
5757
/// Named Curve or Explicit
5858
///
5959
/// This type acts as a boolean as to whether the `EcGroup` is named or explicit.
60-
#[derive(Copy, Clone)]
60+
#[derive(Copy, Clone, Debug, PartialEq)]
6161
pub struct Asn1Flag(c_int);
6262

6363
impl Asn1Flag {
@@ -294,6 +294,12 @@ impl EcGroupRef {
294294
}
295295
}
296296

297+
/// Gets the flag determining if the group corresponds to a named curve.
298+
#[corresponds(EC_GROUP_get_asn1_flag)]
299+
pub fn asn1_flag(&mut self) -> Asn1Flag {
300+
unsafe { Asn1Flag(ffi::EC_GROUP_get_asn1_flag(self.as_ptr())) }
301+
}
302+
297303
/// Returns the name of the curve, if a name is associated.
298304
#[corresponds(EC_GROUP_get_curve_name)]
299305
pub fn curve_name(&self) -> Option<Nid> {
@@ -1265,4 +1271,12 @@ mod test {
12651271
let group2 = EcGroup::from_curve_name(Nid::X9_62_PRIME239V3).unwrap();
12661272
assert!(!g.is_on_curve(&group2, &mut ctx).unwrap());
12671273
}
1274+
1275+
#[test]
1276+
#[cfg(any(boringssl, ossl111, libressl350))]
1277+
fn asn1_flag() {
1278+
let mut group = EcGroup::from_curve_name(Nid::X9_62_PRIME256V1).unwrap();
1279+
let flag = group.asn1_flag();
1280+
assert_eq!(flag, Asn1Flag::NAMED_CURVE);
1281+
}
12681282
}

0 commit comments

Comments
 (0)