Skip to content

Commit fde3d03

Browse files
authored
Merge pull request #2138 from zh-jq/update-boringssl
add more boringssl methods
2 parents 951d771 + 483ce45 commit fde3d03

File tree

5 files changed

+46
-49
lines changed

5 files changed

+46
-49
lines changed

openssl/src/asn1.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl Asn1Type {
166166
/// [`diff`]: struct.Asn1TimeRef.html#method.diff
167167
/// [`Asn1TimeRef`]: struct.Asn1TimeRef.html
168168
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
169-
#[cfg(ossl102)]
169+
#[cfg(any(ossl102, boringssl))]
170170
pub struct TimeDiff {
171171
/// Difference in days
172172
pub days: c_int,
@@ -199,7 +199,7 @@ foreign_type_and_impl_send_sync! {
199199
impl Asn1TimeRef {
200200
/// Find difference between two times
201201
#[corresponds(ASN1_TIME_diff)]
202-
#[cfg(ossl102)]
202+
#[cfg(any(ossl102, boringssl))]
203203
pub fn diff(&self, compare: &Self) -> Result<TimeDiff, ErrorStack> {
204204
let mut days = 0;
205205
let mut secs = 0;
@@ -215,7 +215,7 @@ impl Asn1TimeRef {
215215

216216
/// Compare two times
217217
#[corresponds(ASN1_TIME_compare)]
218-
#[cfg(ossl102)]
218+
#[cfg(any(ossl102, boringssl))]
219219
pub fn compare(&self, other: &Self) -> Result<Ordering, ErrorStack> {
220220
let d = self.diff(other)?;
221221
if d.days > 0 || d.secs > 0 {
@@ -229,7 +229,7 @@ impl Asn1TimeRef {
229229
}
230230
}
231231

232-
#[cfg(ossl102)]
232+
#[cfg(any(ossl102, boringssl))]
233233
impl PartialEq for Asn1TimeRef {
234234
fn eq(&self, other: &Asn1TimeRef) -> bool {
235235
self.diff(other)
@@ -238,7 +238,7 @@ impl PartialEq for Asn1TimeRef {
238238
}
239239
}
240240

241-
#[cfg(ossl102)]
241+
#[cfg(any(ossl102, boringssl))]
242242
impl PartialEq<Asn1Time> for Asn1TimeRef {
243243
fn eq(&self, other: &Asn1Time) -> bool {
244244
self.diff(other)
@@ -247,7 +247,7 @@ impl PartialEq<Asn1Time> for Asn1TimeRef {
247247
}
248248
}
249249

250-
#[cfg(ossl102)]
250+
#[cfg(any(ossl102, boringssl))]
251251
impl<'a> PartialEq<Asn1Time> for &'a Asn1TimeRef {
252252
fn eq(&self, other: &Asn1Time) -> bool {
253253
self.diff(other)
@@ -256,21 +256,21 @@ impl<'a> PartialEq<Asn1Time> for &'a Asn1TimeRef {
256256
}
257257
}
258258

259-
#[cfg(ossl102)]
259+
#[cfg(any(ossl102, boringssl))]
260260
impl PartialOrd for Asn1TimeRef {
261261
fn partial_cmp(&self, other: &Asn1TimeRef) -> Option<Ordering> {
262262
self.compare(other).ok()
263263
}
264264
}
265265

266-
#[cfg(ossl102)]
266+
#[cfg(any(ossl102, boringssl))]
267267
impl PartialOrd<Asn1Time> for Asn1TimeRef {
268268
fn partial_cmp(&self, other: &Asn1Time) -> Option<Ordering> {
269269
self.compare(other).ok()
270270
}
271271
}
272272

273-
#[cfg(ossl102)]
273+
#[cfg(any(ossl102, boringssl))]
274274
impl<'a> PartialOrd<Asn1Time> for &'a Asn1TimeRef {
275275
fn partial_cmp(&self, other: &Asn1Time) -> Option<Ordering> {
276276
self.compare(other).ok()
@@ -352,9 +352,9 @@ impl Asn1Time {
352352

353353
/// Creates a new time corresponding to the specified X509 time string.
354354
///
355-
/// Requires OpenSSL 1.1.1 or newer.
355+
/// Requires BoringSSL or OpenSSL 1.1.1 or newer.
356356
#[corresponds(ASN1_TIME_set_string_X509)]
357-
#[cfg(ossl111)]
357+
#[cfg(any(ossl111, boringssl))]
358358
pub fn from_str_x509(s: &str) -> Result<Asn1Time, ErrorStack> {
359359
unsafe {
360360
let s = CString::new(s).unwrap();
@@ -367,7 +367,7 @@ impl Asn1Time {
367367
}
368368
}
369369

370-
#[cfg(ossl102)]
370+
#[cfg(any(ossl102, boringssl))]
371371
impl PartialEq for Asn1Time {
372372
fn eq(&self, other: &Asn1Time) -> bool {
373373
self.diff(other)
@@ -376,7 +376,7 @@ impl PartialEq for Asn1Time {
376376
}
377377
}
378378

379-
#[cfg(ossl102)]
379+
#[cfg(any(ossl102, boringssl))]
380380
impl PartialEq<Asn1TimeRef> for Asn1Time {
381381
fn eq(&self, other: &Asn1TimeRef) -> bool {
382382
self.diff(other)
@@ -385,7 +385,7 @@ impl PartialEq<Asn1TimeRef> for Asn1Time {
385385
}
386386
}
387387

388-
#[cfg(ossl102)]
388+
#[cfg(any(ossl102, boringssl))]
389389
impl<'a> PartialEq<&'a Asn1TimeRef> for Asn1Time {
390390
fn eq(&self, other: &&'a Asn1TimeRef) -> bool {
391391
self.diff(other)
@@ -394,21 +394,21 @@ impl<'a> PartialEq<&'a Asn1TimeRef> for Asn1Time {
394394
}
395395
}
396396

397-
#[cfg(ossl102)]
397+
#[cfg(any(ossl102, boringssl))]
398398
impl PartialOrd for Asn1Time {
399399
fn partial_cmp(&self, other: &Asn1Time) -> Option<Ordering> {
400400
self.compare(other).ok()
401401
}
402402
}
403403

404-
#[cfg(ossl102)]
404+
#[cfg(any(ossl102, boringssl))]
405405
impl PartialOrd<Asn1TimeRef> for Asn1Time {
406406
fn partial_cmp(&self, other: &Asn1TimeRef) -> Option<Ordering> {
407407
self.compare(other).ok()
408408
}
409409
}
410410

411-
#[cfg(ossl102)]
411+
#[cfg(any(ossl102, boringssl))]
412412
impl<'a> PartialOrd<&'a Asn1TimeRef> for Asn1Time {
413413
fn partial_cmp(&self, other: &&'a Asn1TimeRef) -> Option<Ordering> {
414414
self.compare(other).ok()
@@ -809,7 +809,7 @@ mod tests {
809809
}
810810

811811
#[test]
812-
#[cfg(ossl102)]
812+
#[cfg(any(ossl102, boringssl))]
813813
fn time_eq() {
814814
let a = Asn1Time::from_str("99991231235959Z").unwrap();
815815
let b = Asn1Time::from_str("99991231235959Z").unwrap();
@@ -828,7 +828,7 @@ mod tests {
828828
}
829829

830830
#[test]
831-
#[cfg(ossl102)]
831+
#[cfg(any(ossl102, boringssl))]
832832
fn time_ord() {
833833
let a = Asn1Time::from_str("99991231235959Z").unwrap();
834834
let b = Asn1Time::from_str("99991231235959Z").unwrap();

openssl/src/ssl/mod.rs

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -654,8 +654,8 @@ impl SslVersion {
654654

655655
/// TLSv1.3
656656
///
657-
/// Requires OpenSSL 1.1.1 or LibreSSL 3.4.0 or newer.
658-
#[cfg(any(ossl111, libressl340))]
657+
/// Requires BoringSSL or OpenSSL 1.1.1 or LibreSSL 3.4.0 or newer.
658+
#[cfg(any(ossl111, libressl340, boringssl))]
659659
pub const TLS1_3: SslVersion = SslVersion(ffi::TLS1_3_VERSION);
660660

661661
/// DTLSv1.0
@@ -666,7 +666,7 @@ impl SslVersion {
666666
/// DTLSv1.2
667667
///
668668
/// DTLS 1.2 corresponds to TLS 1.2 to harmonize versions. There was never a DTLS 1.1.
669-
#[cfg(any(ossl102, libressl332))]
669+
#[cfg(any(ossl102, libressl332, boringssl))]
670670
pub const DTLS1_2: SslVersion = SslVersion(ffi::DTLS1_2_VERSION);
671671
}
672672

@@ -1147,9 +1147,9 @@ impl SslContextBuilder {
11471147
/// A value of `None` will enable protocol versions down to the lowest version supported by
11481148
/// OpenSSL.
11491149
///
1150-
/// Requires OpenSSL 1.1.0 or LibreSSL 2.6.1 or newer.
1150+
/// Requires BoringSSL or OpenSSL 1.1.0 or LibreSSL 2.6.1 or newer.
11511151
#[corresponds(SSL_CTX_set_min_proto_version)]
1152-
#[cfg(any(ossl110, libressl261))]
1152+
#[cfg(any(ossl110, libressl261, boringssl))]
11531153
pub fn set_min_proto_version(&mut self, version: Option<SslVersion>) -> Result<(), ErrorStack> {
11541154
unsafe {
11551155
cvt(ffi::SSL_CTX_set_min_proto_version(
@@ -1165,9 +1165,9 @@ impl SslContextBuilder {
11651165
/// A value of `None` will enable protocol versions up to the highest version supported by
11661166
/// OpenSSL.
11671167
///
1168-
/// Requires OpenSSL 1.1.0 or or LibreSSL 2.6.1 or newer.
1168+
/// Requires BoringSSL or OpenSSL 1.1.0 or or LibreSSL 2.6.1 or newer.
11691169
#[corresponds(SSL_CTX_set_max_proto_version)]
1170-
#[cfg(any(ossl110, libressl261))]
1170+
#[cfg(any(ossl110, libressl261, boringssl))]
11711171
pub fn set_max_proto_version(&mut self, version: Option<SslVersion>) -> Result<(), ErrorStack> {
11721172
unsafe {
11731173
cvt(ffi::SSL_CTX_set_max_proto_version(
@@ -1223,16 +1223,16 @@ impl SslContextBuilder {
12231223
/// and `http/1.1` is encoded as `b"\x06spdy/1\x08http/1.1"`. The protocols are ordered by
12241224
/// preference.
12251225
///
1226-
/// Requires OpenSSL 1.0.2 or LibreSSL 2.6.1 or newer.
1226+
/// Requires BoringSSL or OpenSSL 1.0.2 or LibreSSL 2.6.1 or newer.
12271227
#[corresponds(SSL_CTX_set_alpn_protos)]
1228-
#[cfg(any(ossl102, libressl261))]
1228+
#[cfg(any(ossl102, libressl261, boringssl))]
12291229
pub fn set_alpn_protos(&mut self, protocols: &[u8]) -> Result<(), ErrorStack> {
12301230
unsafe {
12311231
assert!(protocols.len() <= c_uint::max_value() as usize);
12321232
let r = ffi::SSL_CTX_set_alpn_protos(
12331233
self.as_ptr(),
12341234
protocols.as_ptr(),
1235-
protocols.len() as c_uint,
1235+
protocols.len() as _,
12361236
);
12371237
// fun fact, SSL_CTX_set_alpn_protos has a reversed return code D:
12381238
if r == 0 {
@@ -2480,19 +2480,16 @@ impl SslRef {
24802480

24812481
/// Like [`SslContextBuilder::set_alpn_protos`].
24822482
///
2483-
/// Requires OpenSSL 1.0.2 or LibreSSL 2.6.1 or newer.
2483+
/// Requires BoringSSL or OpenSSL 1.0.2 or LibreSSL 2.6.1 or newer.
24842484
///
24852485
/// [`SslContextBuilder::set_alpn_protos`]: struct.SslContextBuilder.html#method.set_alpn_protos
24862486
#[corresponds(SSL_set_alpn_protos)]
2487-
#[cfg(any(ossl102, libressl261))]
2487+
#[cfg(any(ossl102, libressl261, boringssl))]
24882488
pub fn set_alpn_protos(&mut self, protocols: &[u8]) -> Result<(), ErrorStack> {
24892489
unsafe {
24902490
assert!(protocols.len() <= c_uint::max_value() as usize);
2491-
let r = ffi::SSL_set_alpn_protos(
2492-
self.as_ptr(),
2493-
protocols.as_ptr(),
2494-
protocols.len() as c_uint,
2495-
);
2491+
let r =
2492+
ffi::SSL_set_alpn_protos(self.as_ptr(), protocols.as_ptr(), protocols.len() as _);
24962493
// fun fact, SSL_set_alpn_protos has a reversed return code D:
24972494
if r == 0 {
24982495
Ok(())
@@ -2639,9 +2636,9 @@ impl SslRef {
26392636
/// The protocol's name is returned is an opaque sequence of bytes. It is up to the client
26402637
/// to interpret it.
26412638
///
2642-
/// Requires OpenSSL 1.0.2 or LibreSSL 2.6.1 or newer.
2639+
/// Requires BoringSSL or OpenSSL 1.0.2 or LibreSSL 2.6.1 or newer.
26432640
#[corresponds(SSL_get0_alpn_selected)]
2644-
#[cfg(any(ossl102, libressl261))]
2641+
#[cfg(any(ossl102, libressl261, boringssl))]
26452642
pub fn selected_alpn_protocol(&self) -> Option<&[u8]> {
26462643
unsafe {
26472644
let mut data: *const c_uchar = ptr::null();
@@ -3334,9 +3331,9 @@ impl SslRef {
33343331
/// A value of `None` will enable protocol versions down to the lowest version supported by
33353332
/// OpenSSL.
33363333
///
3337-
/// Requires OpenSSL 1.1.0 or LibreSSL 2.6.1 or newer.
3334+
/// Requires BoringSSL or OpenSSL 1.1.0 or LibreSSL 2.6.1 or newer.
33383335
#[corresponds(SSL_set_min_proto_version)]
3339-
#[cfg(any(ossl110, libressl261))]
3336+
#[cfg(any(ossl110, libressl261, boringssl))]
33403337
pub fn set_min_proto_version(&mut self, version: Option<SslVersion>) -> Result<(), ErrorStack> {
33413338
unsafe {
33423339
cvt(ffi::SSL_set_min_proto_version(
@@ -3352,9 +3349,9 @@ impl SslRef {
33523349
/// A value of `None` will enable protocol versions up to the highest version supported by
33533350
/// OpenSSL.
33543351
///
3355-
/// Requires OpenSSL 1.1.0 or or LibreSSL 2.6.1 or newer.
3352+
/// Requires BoringSSL or OpenSSL 1.1.0 or or LibreSSL 2.6.1 or newer.
33563353
#[corresponds(SSL_set_max_proto_version)]
3357-
#[cfg(any(ossl110, libressl261))]
3354+
#[cfg(any(ossl110, libressl261, boringssl))]
33583355
pub fn set_max_proto_version(&mut self, version: Option<SslVersion>) -> Result<(), ErrorStack> {
33593356
unsafe {
33603357
cvt(ffi::SSL_set_max_proto_version(

openssl/src/ssl/test/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ fn test_alpn_server_select_none() {
552552
}
553553

554554
#[test]
555-
#[cfg(any(ossl102, libressl261))]
555+
#[cfg(any(boringssl, ossl102, libressl261))]
556556
fn test_alpn_server_unilateral() {
557557
let server = Server::builder().build();
558558

openssl/src/x509/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,15 +480,15 @@ impl X509Ref {
480480

481481
/// Retrieves the path length extension from a certificate, if it exists.
482482
#[corresponds(X509_get_pathlen)]
483-
#[cfg(ossl110)]
483+
#[cfg(any(ossl110, boringssl))]
484484
pub fn pathlen(&self) -> Option<u32> {
485485
let v = unsafe { ffi::X509_get_pathlen(self.as_ptr()) };
486486
u32::try_from(v).ok()
487487
}
488488

489489
/// Returns this certificate's subject key id, if it exists.
490490
#[corresponds(X509_get0_subject_key_id)]
491-
#[cfg(ossl110)]
491+
#[cfg(any(ossl110, boringssl))]
492492
pub fn subject_key_id(&self) -> Option<&Asn1OctetStringRef> {
493493
unsafe {
494494
let data = ffi::X509_get0_subject_key_id(self.as_ptr());
@@ -498,7 +498,7 @@ impl X509Ref {
498498

499499
/// Returns this certificate's authority key id, if it exists.
500500
#[corresponds(X509_get0_authority_key_id)]
501-
#[cfg(ossl110)]
501+
#[cfg(any(ossl110, boringssl))]
502502
pub fn authority_key_id(&self) -> Option<&Asn1OctetStringRef> {
503503
unsafe {
504504
let data = ffi::X509_get0_authority_key_id(self.as_ptr());

openssl/src/x509/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ fn test_subject_alt_name() {
172172
}
173173

174174
#[test]
175-
#[cfg(ossl110)]
175+
#[cfg(any(ossl110, boringssl))]
176176
fn test_retrieve_pathlen() {
177177
let cert = include_bytes!("../../test/root-ca.pem");
178178
let cert = X509::from_pem(cert).unwrap();
@@ -188,7 +188,7 @@ fn test_retrieve_pathlen() {
188188
}
189189

190190
#[test]
191-
#[cfg(ossl110)]
191+
#[cfg(any(ossl110, boringssl))]
192192
fn test_subject_key_id() {
193193
let cert = include_bytes!("../../test/certv3.pem");
194194
let cert = X509::from_pem(cert).unwrap();
@@ -201,7 +201,7 @@ fn test_subject_key_id() {
201201
}
202202

203203
#[test]
204-
#[cfg(ossl110)]
204+
#[cfg(any(ossl110, boringssl))]
205205
fn test_authority_key_id() {
206206
let cert = include_bytes!("../../test/certv3.pem");
207207
let cert = X509::from_pem(cert).unwrap();

0 commit comments

Comments
 (0)