Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add get_asn1_flag to EcGroupRef #1947

Merged
merged 4 commits into from Jun 4, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
14 changes: 14 additions & 0 deletions openssl/src/ec.rs
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(not(any(ossl102, ossl101)))]
fn asn1_flag() {
let mut group = EcGroup::from_curve_name(Nid::X9_62_PRIME256V1).unwrap();
let flag = group.asn1_flag();
assert_eq!(flag.0, Asn1Flag::NAMED_CURVE.0);
reaperhulk marked this conversation as resolved.
Show resolved Hide resolved
}
}