Skip to content

Commit

Permalink
Merge pull request #1947 from reaperhulk/ec-more
Browse files Browse the repository at this point in the history
add get_asn1_flag to EcGroupRef
  • Loading branch information
alex committed Jun 4, 2023
2 parents d5cc54b + 37966b3 commit 92dca6b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions openssl-sys/src/handwritten/ec.rs
Expand Up @@ -46,6 +46,8 @@ extern "C" {

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

pub fn EC_GROUP_get_asn1_flag(group: *const EC_GROUP) -> c_int;

pub fn EC_GROUP_get_curve_GFp(
group: *const EC_GROUP,
p: *mut BIGNUM,
Expand Down
16 changes: 15 additions & 1 deletion openssl/src/ec.rs
Expand Up @@ -57,7 +57,7 @@ impl PointConversionForm {
/// Named Curve or Explicit
///
/// This type acts as a boolean as to whether the `EcGroup` is named or explicit.
#[derive(Copy, Clone)]
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct Asn1Flag(c_int);

impl Asn1Flag {
Expand Down Expand Up @@ -294,6 +294,12 @@ impl EcGroupRef {
}
}

/// Gets the flag determining if the group corresponds to a named curve.
#[corresponds(EC_GROUP_get_asn1_flag)]
pub fn asn1_flag(&mut self) -> Asn1Flag {
unsafe { Asn1Flag(ffi::EC_GROUP_get_asn1_flag(self.as_ptr())) }
}

/// Returns the name of the curve, if a name is associated.
#[corresponds(EC_GROUP_get_curve_name)]
pub fn curve_name(&self) -> Option<Nid> {
Expand Down Expand Up @@ -1265,4 +1271,12 @@ mod test {
let group2 = EcGroup::from_curve_name(Nid::X9_62_PRIME239V3).unwrap();
assert!(!g.is_on_curve(&group2, &mut ctx).unwrap());
}

#[test]
#[cfg(any(boringssl, ossl111, libressl350))]
fn asn1_flag() {
let mut group = EcGroup::from_curve_name(Nid::X9_62_PRIME256V1).unwrap();
let flag = group.asn1_flag();
assert_eq!(flag, Asn1Flag::NAMED_CURVE);
}
}

0 comments on commit 92dca6b

Please sign in to comment.