Skip to content

Commit 4fa82e9

Browse files
committed
chore: Remove nspr_types
This moves bindgen closer to what neqo_crypto does. Some unions get generated 'better', i.e. with copy and clone traits, through this
1 parent 4eda38b commit 4fa82e9

15 files changed

Lines changed: 23 additions & 87 deletions

File tree

bindings/bindings.toml

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,6 @@
55
# header with the types/variables/functions/enums declared for generation in
66
# other headers.
77

8-
[nspr_types]
9-
types = [
10-
"PRBool",
11-
"PRIntn",
12-
"PRInt16",
13-
"PRInt32",
14-
"PRInt64",
15-
"PROffset32",
16-
"PROffset64",
17-
"PRSize",
18-
"PRStatus",
19-
"PRUintn",
20-
"PRUint8",
21-
"PRUint16",
22-
"PRUint32",
23-
"PRUint64",
24-
"PRUword",
25-
]
26-
variables = ["PR_FALSE", "PR_TRUE"]
27-
288
[nss_prelude]
299
types = ["SECItem", "SECItemArray", "SECItemStr", "SECStatus"]
3010
functions = ["SECITEM_FreeItem", "SECITEM_FreeArray"]
@@ -296,7 +276,7 @@ functions = ["PR_Close", "PR_CreateIOLayerStub", "PR_GetUniqueIdentity"]
296276
variables = ["PR_AF_INET"]
297277
# opaque is for the stuff we don't plan to use, but we need for function signatures.
298278
opaque = ["PRFileInfo", "PRFileInfo64", "PRFilePrivate", "PRIOVec"]
299-
enums = ["PRDescType", "PRSeekWhence"]
279+
enums = ["PRDescType", "PRStatus", "PRSeekWhence"]
300280

301281
[nspr_time]
302282
types = ["PRTime"]

src/aead.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ use crate::{
1919
CKA_ENCRYPT, CKA_NSS_MESSAGE, CKG_GENERATE_COUNTER_XOR, CKG_NO_GENERATE, CKM_AES_GCM,
2020
CKM_CHACHA20_POLY1305, CK_ATTRIBUTE_TYPE, CK_GENERATOR_FUNCTION, CK_MECHANISM_TYPE,
2121
},
22-
prtypes::{PRUint16, PRUint64, PRUint8},
2322
scoped_ptr, secstatus_to_res,
24-
ssl::SSLAeadContext,
23+
ssl::{PRUint16, PRUint64, PRUint8, SSLAeadContext},
2524
SECItemBorrowed, SymKey,
2625
};
2726

src/agent.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@ use crate::{
4444
null_safe_slice,
4545
p11::{self, hex_with_len, PrivateKey, PublicKey},
4646
prio,
47-
prtypes::PRBool,
4847
replay::AntiReplay,
4948
secrets::SecretHolder,
50-
ssl,
49+
ssl::{self, PRBool},
5150
time::{Time, TimeHolder},
5251
SECItem, SECItemArray, SECItemBorrowed, SECStatus,
5352
};

src/agentio.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,17 @@ use crate::{
2727
err::{nspr, Error, PR_SetError, Res},
2828
null_safe_slice,
2929
p11::hex_with_len,
30-
prio, prtypes,
30+
prio,
3131
selfencrypt::hex,
32-
ssl, PRInt32, PRInt64, PRIntn, PRUint16, PRUint8, SECStatus,
32+
ssl::{self, PRInt32, PRInt64, PRIntn, PRUint16, PRUint8},
33+
SECStatus,
3334
};
3435

3536
// Alias common types.
3637
type PrFd = *mut prio::PRFileDesc;
37-
type PrStatus = prtypes::PRStatus;
38-
const PR_SUCCESS: PrStatus = prtypes::PR_SUCCESS;
39-
const PR_FAILURE: PrStatus = prtypes::PR_FAILURE;
38+
type PrStatus = prio::PRStatus::Type;
39+
const PR_SUCCESS: PrStatus = prio::PRStatus::PR_SUCCESS;
40+
const PR_FAILURE: PrStatus = prio::PRStatus::PR_FAILURE;
4041

4142
/// Convert a pinned, boxed object into a void pointer.
4243
pub fn as_c_void<T: Unpin>(pin: &mut Pin<Box<T>>) -> *mut c_void {
@@ -352,16 +353,16 @@ unsafe extern "C" fn agent_getname(_fd: PrFd, addr: *mut prio::PRNetAddr) -> PrS
352353
return PR_FAILURE;
353354
};
354355
// Cast is safe because prio::PR_AF_INET is 2
355-
a.inet.as_mut().family = prio::PR_AF_INET as PRUint16;
356-
a.inet.as_mut().port = 0;
357-
a.inet.as_mut().ip = 0;
356+
a.inet.family = prio::PR_AF_INET as PRUint16;
357+
a.inet.port = 0;
358+
a.inet.ip = 0;
358359
PR_SUCCESS
359360
}
360361

361362
unsafe extern "C" fn agent_getsockopt(_fd: PrFd, opt: *mut prio::PRSocketOptionData) -> PrStatus {
362363
if let Some(o) = opt.as_mut() {
363364
if o.option == prio::PRSockOption_PR_SockOpt_Nonblocking {
364-
*o.value.non_blocking.as_mut() = 1;
365+
o.value.non_blocking = 1;
365366
return PR_SUCCESS;
366367
}
367368
}

src/ec.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ use crate::{
2222
PK11_ImportDERPrivateKeyInfoAndReturnKey, PK11_ImportPublicKey, PK11_PubDeriveWithKDF,
2323
PK11_ReadRawAttribute, SECKEY_DecodeDERSubjectPublicKeyInfo, Slot, KU_ALL,
2424
},
25+
ssl::PRBool,
2526
util::SECItemMut,
26-
PrivateKey, PublicKey, SECItem, SECItemBorrowed, PR_FALSE,
27+
PrivateKey, PublicKey, SECItem, SECItemBorrowed,
2728
};
2829
//
2930
// Constants
@@ -181,7 +182,7 @@ pub fn import_ec_public_key_from_spki(spki: &[u8]) -> Result<PublicKey, Error> {
181182
crate::p11::SECKEY_ExtractPublicKey(spki.as_mut().ok_or(Error::InvalidInput)?)
182183
.into_result()?;
183184

184-
let handle = PK11_ImportPublicKey(*slot, *pk, PR_FALSE);
185+
let handle = PK11_ImportPublicKey(*slot, *pk, PRBool::from(false));
185186
if handle == pkcs11_bindings::CK_INVALID_HANDLE {
186187
return Err(Error::InvalidInput);
187188
}

src/ech.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::{
1919
experimental_api, null_safe_slice,
2020
p11::{self, PrivateKey, PublicKey, SECKEYPrivateKey, SECKEYPublicKey, Slot},
2121
prio::PRFileDesc,
22-
prtypes::PRBool,
22+
ssl::PRBool,
2323
SECItem, SECItemBorrowed, SECItemMut,
2424
};
2525
pub use crate::{

src/err.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66

77
use std::{os::raw::c_char, str::Utf8Error};
88

9-
use crate::{
10-
nss_prelude::*,
11-
prtypes::{PRInt32, PRUint32},
12-
};
9+
use crate::nss_prelude::*;
1310

1411
include!(concat!(env!("OUT_DIR"), "/nspr_error.rs"));
1512
#[expect(non_snake_case, dead_code, reason = "Code is bindgen-generated.")]

src/ext.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ use crate::{
2222
agentio::as_c_void,
2323
constants::{Extension, HandshakeMessage, TLS_HS_CLIENT_HELLO, TLS_HS_ENCRYPTED_EXTENSIONS},
2424
err::Res,
25+
nss_prelude::PRBool,
2526
null_safe_slice,
2627
prio::PRFileDesc,
27-
prtypes::PRBool,
2828
ssl::{
2929
SECFailure, SECSuccess, SSLAlertDescription, SSLExtensionHandler, SSLExtensionWriter,
3030
SSLHandshakeType,

src/lib.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ pub mod nss_prelude {
9999
)]
100100
pub use _SECStatus::*;
101101

102-
pub use crate::prtypes::*;
103102
include!(concat!(env!("OUT_DIR"), "/nss_prelude.rs"));
104103
}
105104
pub use nss_prelude::{SECItem, SECItemArray, SECItemType, SECStatus};
@@ -110,15 +109,6 @@ mod nss {
110109
include!(concat!(env!("OUT_DIR"), "/nss_init.rs"));
111110
}
112111

113-
pub mod prtypes;
114-
pub use prtypes::*;
115-
116-
// Shadow these bindgen created values to correct their type.
117-
#[expect(clippy::cast_possible_wrap)]
118-
pub const PR_FALSE: PRBool = prtypes::PR_FALSE as PRBool;
119-
#[expect(clippy::cast_possible_wrap)]
120-
pub const PR_TRUE: PRBool = prtypes::PR_TRUE as PRBool;
121-
122112
enum NssLoaded {
123113
External,
124114
NoDb,

src/p11.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,13 @@ mod nss_p11 {
5151
clippy::restriction,
5252
reason = "For included bindgen code."
5353
)]
54-
use crate::{
55-
nss_prelude::*,
56-
prtypes::{PRBool, PRInt32, PRUint32, PRUint8, PRUword},
57-
};
54+
use crate::nss_prelude::*;
5855
include!(concat!(env!("OUT_DIR"), "/nss_p11.rs"));
5956
}
6057

6158
pub use nss_p11::*;
6259

63-
use crate::{null_safe_slice, prtypes::PRBool};
60+
use crate::null_safe_slice;
6461

6562
scoped_ptr!(Certificate, CERTCertificate, CERT_DestroyCertificate);
6663
scoped_ptr!(CertList, CERTCertList, CERT_DestroyCertList);

0 commit comments

Comments
 (0)