Skip to content

Commit bf0e21c

Browse files
kornelskirushilmehra
authored andcommitted
Use corresponds macro
1 parent 05270fa commit bf0e21c

File tree

16 files changed

+171
-620
lines changed

16 files changed

+171
-620
lines changed

boring/src/derive.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Shared secret derivation.
22
use crate::ffi;
33
use foreign_types::ForeignTypeRef;
4+
use openssl_macros::corresponds;
45
use std::marker::PhantomData;
56
use std::ptr;
67

@@ -25,10 +26,7 @@ impl Drop for Deriver<'_> {
2526
#[allow(clippy::len_without_is_empty)]
2627
impl<'a> Deriver<'a> {
2728
/// Creates a new `Deriver` using the provided private key.
28-
///
29-
/// This corresponds to [`EVP_PKEY_derive_init`].
30-
///
31-
/// [`EVP_PKEY_derive_init`]: https://www.openssl.org/docs/man1.0.2/crypto/EVP_PKEY_derive_init.html
29+
#[corresponds(EVP_PKEY_derive_init)]
3230
pub fn new<T>(key: &'a PKeyRef<T>) -> Result<Deriver<'a>, ErrorStack>
3331
where
3432
T: HasPrivate,
@@ -41,10 +39,7 @@ impl<'a> Deriver<'a> {
4139
}
4240

4341
/// Sets the peer key used for secret derivation.
44-
///
45-
/// This corresponds to [`EVP_PKEY_derive_set_peer`]:
46-
///
47-
/// [`EVP_PKEY_derive_set_peer`]: https://www.openssl.org/docs/man1.0.2/crypto/EVP_PKEY_derive_init.html
42+
#[corresponds(EVP_PKEY_derive_set_peer)]
4843
pub fn set_peer<T>(&mut self, key: &'a PKeyRef<T>) -> Result<(), ErrorStack>
4944
where
5045
T: HasPublic,
@@ -55,10 +50,7 @@ impl<'a> Deriver<'a> {
5550
/// Returns the size of the shared secret.
5651
///
5752
/// It can be used to size the buffer passed to [`Deriver::derive`].
58-
///
59-
/// This corresponds to [`EVP_PKEY_derive`].
60-
///
61-
/// [`Deriver::derive`]: #method.derive
53+
#[corresponds(EVP_PKEY_derive)]
6254
/// [`EVP_PKEY_derive`]: https://www.openssl.org/docs/man1.0.2/crypto/EVP_PKEY_derive_init.html
6355
pub fn len(&mut self) -> Result<usize, ErrorStack> {
6456
unsafe {
@@ -70,10 +62,7 @@ impl<'a> Deriver<'a> {
7062
/// Derives a shared secret between the two keys, writing it into the buffer.
7163
///
7264
/// Returns the number of bytes written.
73-
///
74-
/// This corresponds to [`EVP_PKEY_derive`].
75-
///
76-
/// [`EVP_PKEY_derive`]: https://www.openssl.org/docs/man1.0.2/crypto/EVP_PKEY_derive_init.html
65+
#[corresponds(EVP_PKEY_derive)]
7766
pub fn derive(&mut self, buf: &mut [u8]) -> Result<usize, ErrorStack> {
7867
let mut len = buf.len();
7968
unsafe {

boring/src/dh.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::error::ErrorStack;
22
use crate::ffi;
33
use foreign_types::{ForeignType, ForeignTypeRef};
4+
use openssl_macros::corresponds;
45
use std::mem;
56
use std::ptr;
67

@@ -25,20 +26,14 @@ where
2526
/// Serializes the parameters into a PEM-encoded PKCS#3 DHparameter structure.
2627
///
2728
/// The output will have a header of `-----BEGIN DH PARAMETERS-----`.
28-
///
29-
/// This corresponds to [`PEM_write_bio_DHparams`].
30-
///
31-
/// [`PEM_write_bio_DHparams`]: https://www.openssl.org/docs/manmaster/man3/PEM_write_bio_DHparams.html
29+
#[corresponds(PEM_write_bio_DHparams)]
3230
params_to_pem,
3331
ffi::PEM_write_bio_DHparams
3432
}
3533

3634
to_der! {
3735
/// Serializes the parameters into a DER-encoded PKCS#3 DHparameter structure.
38-
///
39-
/// This corresponds to [`i2d_DHparams`].
40-
///
41-
/// [`i2d_DHparams`]: https://www.openssl.org/docs/man1.1.0/crypto/i2d_DHparams.html
36+
#[corresponds(i2d_DHparams)]
4237
params_to_der,
4338
ffi::i2d_DHparams
4439
}
@@ -58,21 +53,15 @@ impl Dh<Params> {
5853
/// Deserializes a PEM-encoded PKCS#3 DHpararameters structure.
5954
///
6055
/// The input should have a header of `-----BEGIN DH PARAMETERS-----`.
61-
///
62-
/// This corresponds to [`PEM_read_bio_DHparams`].
63-
///
64-
/// [`PEM_read_bio_DHparams`]: https://www.openssl.org/docs/man1.0.2/crypto/PEM_read_bio_DHparams.html
56+
#[corresponds(PEM_read_bio_DHparams)]
6557
params_from_pem,
6658
Dh<Params>,
6759
ffi::PEM_read_bio_DHparams
6860
}
6961

7062
from_der! {
7163
/// Deserializes a DER-encoded PKCS#3 DHparameters structure.
72-
///
73-
/// This corresponds to [`d2i_DHparams`].
74-
///
75-
/// [`d2i_DHparams`]: https://www.openssl.org/docs/man1.1.0/crypto/d2i_DHparams.html
64+
#[corresponds(d2i_DHparams)]
7665
params_from_der,
7766
Dh<Params>,
7867
ffi::d2i_DHparams,

boring/src/dsa.rs

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use crate::ffi;
99
use foreign_types::{ForeignType, ForeignTypeRef};
1010
use libc::c_uint;
11+
use openssl_macros::corresponds;
1112
use std::fmt;
1213
use std::mem;
1314
use std::ptr;
@@ -84,20 +85,14 @@ where
8485
/// Serialies the public key into a PEM-encoded SubjectPublicKeyInfo structure.
8586
///
8687
/// The output will have a header of `-----BEGIN PUBLIC KEY-----`.
87-
///
88-
/// This corresponds to [`PEM_write_bio_DSA_PUBKEY`].
89-
///
90-
/// [`PEM_write_bio_DSA_PUBKEY`]: https://www.openssl.org/docs/man1.1.0/crypto/PEM_write_bio_DSA_PUBKEY.html
88+
#[corresponds(PEM_write_bio_DSA_PUBKEY)]
9189
public_key_to_pem,
9290
ffi::PEM_write_bio_DSA_PUBKEY
9391
}
9492

9593
to_der! {
9694
/// Serializes the public key into a DER-encoded SubjectPublicKeyInfo structure.
97-
///
98-
/// This corresponds to [`i2d_DSA_PUBKEY`].
99-
///
100-
/// [`i2d_DSA_PUBKEY`]: https://www.openssl.org/docs/man1.1.0/crypto/i2d_DSA_PUBKEY.html
95+
#[corresponds(i2d_DSA_PUBKEY)]
10196
public_key_to_der,
10297
ffi::i2d_DSA_PUBKEY
10398
}
@@ -120,18 +115,12 @@ where
120115
/// Serializes the private key to a PEM-encoded DSAPrivateKey structure.
121116
///
122117
/// The output will have a header of `-----BEGIN DSA PRIVATE KEY-----`.
123-
///
124-
/// This corresponds to [`PEM_write_bio_DSAPrivateKey`].
125-
///
126-
/// [`PEM_write_bio_DSAPrivateKey`]: https://www.openssl.org/docs/man1.1.0/crypto/PEM_write_bio_DSAPrivateKey.html
118+
#[corresponds(PEM_write_bio_DSAPrivateKey)]
127119
private_key_to_pem,
128120
/// Serializes the private key to a PEM-encoded encrypted DSAPrivateKey structure.
129121
///
130122
/// The output will have a header of `-----BEGIN DSA PRIVATE KEY-----`.
131-
///
132-
/// This corresponds to [`PEM_write_bio_DSAPrivateKey`].
133-
///
134-
/// [`PEM_write_bio_DSAPrivateKey`]: https://www.openssl.org/docs/man1.1.0/crypto/PEM_write_bio_DSAPrivateKey.html
123+
#[corresponds(PEM_write_bio_DSAPrivateKey)]
135124
private_key_to_pem_passphrase,
136125
ffi::PEM_write_bio_DSAPrivateKey
137126
}
@@ -151,10 +140,7 @@ where
151140
T: HasParams,
152141
{
153142
/// Returns the maximum size of the signature output by `self` in bytes.
154-
///
155-
/// OpenSSL documentation at [`DSA_size`]
156-
///
157-
/// [`DSA_size`]: https://www.openssl.org/docs/man1.1.0/crypto/DSA_size.html
143+
#[corresponds(DSA_size)]
158144
pub fn size(&self) -> u32 {
159145
unsafe { ffi::DSA_size(self.as_ptr()) as u32 }
160146
}
@@ -244,21 +230,15 @@ impl Dsa<Public> {
244230
/// Decodes a PEM-encoded SubjectPublicKeyInfo structure containing a DSA key.
245231
///
246232
/// The input should have a header of `-----BEGIN PUBLIC KEY-----`.
247-
///
248-
/// This corresponds to [`PEM_read_bio_DSA_PUBKEY`].
249-
///
250-
/// [`PEM_read_bio_DSA_PUBKEY`]: https://www.openssl.org/docs/man1.0.2/crypto/PEM_read_bio_DSA_PUBKEY.html
233+
#[corresponds(PEM_read_bio_DSA_PUBKEY)]
251234
public_key_from_pem,
252235
Dsa<Public>,
253236
ffi::PEM_read_bio_DSA_PUBKEY
254237
}
255238

256239
from_der! {
257240
/// Decodes a DER-encoded SubjectPublicKeyInfo structure containing a DSA key.
258-
///
259-
/// This corresponds to [`d2i_DSA_PUBKEY`].
260-
///
261-
/// [`d2i_DSA_PUBKEY`]: https://www.openssl.org/docs/man1.0.2/crypto/d2i_DSA_PUBKEY.html
241+
#[corresponds(d2i_DSA_PUBKEY)]
262242
public_key_from_der,
263243
Dsa<Public>,
264244
ffi::d2i_DSA_PUBKEY,

0 commit comments

Comments
 (0)