@@ -21,23 +21,18 @@ use webpki::{RevocationCheckDepth, UnknownStatusPolicy};
21
21
use crate :: error:: { self , rustls_result} ;
22
22
use crate :: rslice:: { rustls_slice_bytes, rustls_str} ;
23
23
use crate :: {
24
- ffi_panic_boundary, free_arc, free_box, set_arc_mut_ptr, set_boxed_mut_ptr, to_arc_const_ptr,
25
- to_boxed_mut_ptr, try_clone_arc, try_mut_from_ptr, try_mut_from_ptr_ptr, try_ref_from_ptr,
26
- try_ref_from_ptr_ptr, try_slice, try_take, Castable , OwnershipArc , OwnershipBox , OwnershipRef ,
24
+ arc_castable, box_castable, ffi_panic_boundary, free_arc, free_box, ref_castable,
25
+ set_arc_mut_ptr, set_boxed_mut_ptr, to_arc_const_ptr, to_boxed_mut_ptr, try_clone_arc,
26
+ try_mut_from_ptr, try_mut_from_ptr_ptr, try_ref_from_ptr, try_ref_from_ptr_ptr, try_slice,
27
+ try_take,
27
28
} ;
28
29
use rustls_result:: { AlreadyUsed , NullParameter } ;
29
30
30
- /// An X.509 certificate, as used in rustls.
31
- /// Corresponds to `CertificateDer` in the Rust pki-types API.
32
- /// <https://docs.rs/rustls-pki-types/latest/rustls_pki_types/struct.CertificateDer.html>
33
- pub struct rustls_certificate < ' a > {
34
- _private : [ u8 ; 0 ] ,
35
- _marker : PhantomData < & ' a ( ) > ,
36
- }
37
-
38
- impl < ' a > Castable for rustls_certificate < ' a > {
39
- type Ownership = OwnershipRef ;
40
- type RustType = CertificateDer < ' a > ;
31
+ ref_castable ! {
32
+ /// An X.509 certificate, as used in rustls.
33
+ /// Corresponds to `CertificateDer` in the Rust pki-types API.
34
+ /// <https://docs.rs/rustls-pki-types/latest/rustls_pki_types/struct.CertificateDer.html>
35
+ pub struct rustls_certificate( CertificateDer <' a>) ;
41
36
}
42
37
43
38
/// Get the DER data of the certificate itself.
@@ -62,14 +57,9 @@ pub extern "C" fn rustls_certificate_get_der(
62
57
}
63
58
}
64
59
65
- /// A cipher suite supported by rustls.
66
- pub struct rustls_supported_ciphersuite {
67
- _private : [ u8 ; 0 ] ,
68
- }
69
-
70
- impl Castable for rustls_supported_ciphersuite {
71
- type Ownership = OwnershipRef ;
72
- type RustType = SupportedCipherSuite ;
60
+ ref_castable ! {
61
+ /// A cipher suite supported by rustls.
62
+ pub struct rustls_supported_ciphersuite( SupportedCipherSuite ) ;
73
63
}
74
64
75
65
impl rustls_supported_ciphersuite {
@@ -207,17 +197,12 @@ pub static mut RUSTLS_DEFAULT_CIPHER_SUITES: [*const rustls_supported_ciphersuit
207
197
#[ no_mangle]
208
198
pub static RUSTLS_DEFAULT_CIPHER_SUITES_LEN : usize = unsafe { RUSTLS_DEFAULT_CIPHER_SUITES . len ( ) } ;
209
199
210
- /// The complete chain of certificates to send during a TLS handshake,
211
- /// plus a private key that matches the end-entity (leaf) certificate.
212
- /// Corresponds to `CertifiedKey` in the Rust API.
213
- /// <https://docs.rs/rustls/latest/rustls/sign/struct.CertifiedKey.html>
214
- pub struct rustls_certified_key {
215
- _private : [ u8 ; 0 ] ,
216
- }
217
-
218
- impl Castable for rustls_certified_key {
219
- type Ownership = OwnershipArc ;
220
- type RustType = CertifiedKey ;
200
+ arc_castable ! {
201
+ /// The complete chain of certificates to send during a TLS handshake,
202
+ /// plus a private key that matches the end-entity (leaf) certificate.
203
+ /// Corresponds to `CertifiedKey` in the Rust API.
204
+ /// <https://docs.rs/rustls/latest/rustls/sign/struct.CertifiedKey.html>
205
+ pub struct rustls_certified_key( CertifiedKey ) ;
221
206
}
222
207
223
208
impl rustls_certified_key {
@@ -385,25 +370,20 @@ impl rustls_certified_key {
385
370
}
386
371
}
387
372
388
- /// A `rustls_root_cert_store` being constructed.
389
- ///
390
- /// A builder can be modified by adding trust anchor root certificates with
391
- /// `rustls_root_cert_store_builder_add_pem`. Once you're done adding root certificates,
392
- /// call `rustls_root_cert_store_builder_build` to turn it into a `rustls_root_cert_store`.
393
- /// This object is not safe for concurrent mutation .
394
- pub struct rustls_root_cert_store_builder {
395
- _private : [ u8 ; 0 ] ,
373
+ box_castable ! {
374
+ /// A `rustls_root_cert_store` being constructed.
375
+ ///
376
+ /// A builder can be modified by adding trust anchor root certificates with
377
+ /// `rustls_root_cert_store_builder_add_pem`. Once you're done adding root certificates,
378
+ /// call `rustls_root_cert_store_builder_build` to turn it into a `rustls_root_cert_store` .
379
+ /// This object is not safe for concurrent mutation.
380
+ pub struct rustls_root_cert_store_builder ( Option < RootCertStoreBuilder > ) ;
396
381
}
397
382
398
383
pub ( crate ) struct RootCertStoreBuilder {
399
384
roots : RootCertStore ,
400
385
}
401
386
402
- impl Castable for rustls_root_cert_store_builder {
403
- type Ownership = OwnershipBox ;
404
- type RustType = Option < RootCertStoreBuilder > ;
405
- }
406
-
407
387
impl rustls_root_cert_store_builder {
408
388
/// Create a `rustls_root_cert_store_builder`.
409
389
///
@@ -562,15 +542,10 @@ impl rustls_root_cert_store_builder {
562
542
}
563
543
}
564
544
565
- /// A root certificate store.
566
- /// <https://docs.rs/rustls/latest/rustls/struct.RootCertStore.html>
567
- pub struct rustls_root_cert_store {
568
- _private : [ u8 ; 0 ] ,
569
- }
570
-
571
- impl Castable for rustls_root_cert_store {
572
- type Ownership = OwnershipArc ;
573
- type RustType = RootCertStore ;
545
+ arc_castable ! {
546
+ /// A root certificate store.
547
+ /// <https://docs.rs/rustls/latest/rustls/struct.RootCertStore.html>
548
+ pub struct rustls_root_cert_store( RootCertStore ) ;
574
549
}
575
550
576
551
impl rustls_root_cert_store {
@@ -584,19 +559,15 @@ impl rustls_root_cert_store {
584
559
}
585
560
}
586
561
587
- /// A built client certificate verifier that can be provided to a `rustls_server_config_builder`
588
- /// with `rustls_server_config_builder_set_client_verifier`.
589
- pub struct rustls_client_cert_verifier {
590
- _private : [ u8 ; 0 ] ,
591
- }
592
-
593
- /// Rustls' ConfigBuilder requires an `Arc<dyn ClientCertVerifier>` here, meaning we
594
- /// must follow the pattern described in CONTRIBUTING.md[0] for handling dynamically sized
595
- /// types (DSTs) across the FFI boundary.
596
- /// [0] <https://github.com/rustls/rustls-ffi/blob/main/CONTRIBUTING.md#dynamically-sized-types>
597
- impl Castable for rustls_client_cert_verifier {
598
- type Ownership = OwnershipBox ;
599
- type RustType = Arc < dyn ClientCertVerifier > ;
562
+ box_castable ! {
563
+ /// A built client certificate verifier that can be provided to a `rustls_server_config_builder`
564
+ /// with `rustls_server_config_builder_set_client_verifier`.
565
+ //
566
+ // Rustls' ConfigBuilder requires an `Arc<dyn ClientCertVerifier>` here, meaning we
567
+ // must follow the pattern described in CONTRIBUTING.md[^0] for handling dynamically sized
568
+ // types (DSTs) across the FFI boundary.
569
+ // [^0]: <https://github.com/rustls/rustls-ffi/blob/main/CONTRIBUTING.md#dynamically-sized-types>
570
+ pub struct rustls_client_cert_verifier( Arc <dyn ClientCertVerifier >) ;
600
571
}
601
572
602
573
impl rustls_client_cert_verifier {
@@ -611,18 +582,6 @@ impl rustls_client_cert_verifier {
611
582
}
612
583
}
613
584
614
- /// A client certificate verifier being constructed. A builder can be modified by,
615
- /// e.g. `rustls_web_pki_client_cert_verifier_builder_add_crl`. Once you're
616
- /// done configuring settings, call `rustls_web_pki_client_cert_verifier_builder_build`
617
- /// to turn it into a `rustls_client_cert_verifier`. This object is not safe
618
- /// for concurrent mutation.
619
- ///
620
- /// See <https://docs.rs/rustls/latest/rustls/server/struct.ClientCertVerifierBuilder.html>
621
- /// for more information.
622
- pub struct rustls_web_pki_client_cert_verifier_builder {
623
- _private : [ u8 ; 0 ] ,
624
- }
625
-
626
585
pub ( crate ) struct ClientCertVerifierBuilder {
627
586
roots : Arc < RootCertStore > ,
628
587
root_hint_subjects : Vec < DistinguishedName > ,
@@ -632,9 +591,16 @@ pub(crate) struct ClientCertVerifierBuilder {
632
591
allow_unauthenticated : bool ,
633
592
}
634
593
635
- impl Castable for rustls_web_pki_client_cert_verifier_builder {
636
- type Ownership = OwnershipBox ;
637
- type RustType = Option < ClientCertVerifierBuilder > ;
594
+ box_castable ! {
595
+ /// A client certificate verifier being constructed. A builder can be modified by,
596
+ /// e.g. `rustls_web_pki_client_cert_verifier_builder_add_crl`. Once you're
597
+ /// done configuring settings, call `rustls_web_pki_client_cert_verifier_builder_build`
598
+ /// to turn it into a `rustls_client_cert_verifier`. This object is not safe
599
+ /// for concurrent mutation.
600
+ ///
601
+ /// See <https://docs.rs/rustls/latest/rustls/server/struct.ClientCertVerifierBuilder.html>
602
+ /// for more information.
603
+ pub struct rustls_web_pki_client_cert_verifier_builder( Option <ClientCertVerifierBuilder >) ;
638
604
}
639
605
640
606
impl rustls_web_pki_client_cert_verifier_builder {
@@ -893,16 +859,16 @@ impl rustls_web_pki_client_cert_verifier_builder {
893
859
}
894
860
}
895
861
896
- /// A server certificate verifier being constructed. A builder can be modified by,
897
- /// e.g. `rustls_web_pki_server_cert_verifier_builder_add_crl`. Once you're
898
- /// done configuring settings, call `rustls_web_pki_server_cert_verifier_builder_build`
899
- /// to turn it into a `rustls_server_cert_verifier`. This object is not safe
900
- /// for concurrent mutation.
901
- ///
902
- /// See <https://docs.rs/rustls/latest/rustls/client/struct.ServerCertVerifierBuilder.html>
903
- /// for more information.
904
- pub struct rustls_web_pki_server_cert_verifier_builder {
905
- _private : [ u8 ; 0 ] ,
862
+ box_castable ! {
863
+ /// A server certificate verifier being constructed. A builder can be modified by,
864
+ /// e.g. `rustls_web_pki_server_cert_verifier_builder_add_crl`. Once you're
865
+ /// done configuring settings, call `rustls_web_pki_server_cert_verifier_builder_build`
866
+ /// to turn it into a `rustls_server_cert_verifier`. This object is not safe
867
+ /// for concurrent mutation.
868
+ ///
869
+ /// See <https://docs.rs/rustls/latest/rustls/client/struct.ServerCertVerifierBuilder.html>
870
+ /// for more information.
871
+ pub struct rustls_web_pki_server_cert_verifier_builder ( Option < ServerCertVerifierBuilder > ) ;
906
872
}
907
873
908
874
pub ( crate ) struct ServerCertVerifierBuilder {
@@ -912,11 +878,6 @@ pub(crate) struct ServerCertVerifierBuilder {
912
878
revocation_policy : UnknownStatusPolicy ,
913
879
}
914
880
915
- impl Castable for rustls_web_pki_server_cert_verifier_builder {
916
- type Ownership = OwnershipBox ;
917
- type RustType = Option < ServerCertVerifierBuilder > ;
918
- }
919
-
920
881
impl ServerCertVerifierBuilder {
921
882
/// Create a `rustls_web_pki_server_cert_verifier_builder`. Caller owns the memory and may
922
883
/// free it with `rustls_web_pki_server_cert_verifier_builder_free`, regardless of whether
@@ -1095,19 +1056,15 @@ impl ServerCertVerifierBuilder {
1095
1056
}
1096
1057
}
1097
1058
1098
- /// A built server certificate verifier that can be provided to a `rustls_client_config_builder`
1099
- /// with `rustls_client_config_builder_set_server_verifier`.
1100
- pub struct rustls_server_cert_verifier {
1101
- _private : [ u8 ; 0 ] ,
1102
- }
1103
-
1104
- /// Rustls' ConfigBuilder requires an `Arc<dyn ServerCertVerifier>` here, meaning we
1105
- /// must follow the pattern described in CONTRIBUTING.md[0] for handling dynamically sized
1106
- /// types (DSTs) across the FFI boundary.
1107
- /// [0] <https://github.com/rustls/rustls-ffi/blob/main/CONTRIBUTING.md#dynamically-sized-types>
1108
- impl Castable for rustls_server_cert_verifier {
1109
- type Ownership = OwnershipBox ;
1110
- type RustType = Arc < dyn ServerCertVerifier > ;
1059
+ box_castable ! {
1060
+ /// A built server certificate verifier that can be provided to a `rustls_client_config_builder`
1061
+ /// with `rustls_client_config_builder_set_server_verifier`.
1062
+ //
1063
+ // Rustls' ConfigBuilder requires an `Arc<dyn ServerCertVerifier>` here, meaning we
1064
+ // must follow the pattern described in CONTRIBUTING.md[^0] for handling dynamically sized
1065
+ // types (DSTs) across the FFI boundary.
1066
+ // [^0]: <https://github.com/rustls/rustls-ffi/blob/main/CONTRIBUTING.md#dynamically-sized-types>
1067
+ pub struct rustls_server_cert_verifier( Arc <dyn ServerCertVerifier >) ;
1111
1068
}
1112
1069
1113
1070
impl rustls_server_cert_verifier {
0 commit comments