@@ -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 {
@@ -257,17 +247,12 @@ mod tests {
257
247
}
258
248
}
259
249
260
- /// The complete chain of certificates to send during a TLS handshake,
261
- /// plus a private key that matches the end-entity (leaf) certificate.
262
- /// Corresponds to `CertifiedKey` in the Rust API.
263
- /// <https://docs.rs/rustls/latest/rustls/sign/struct.CertifiedKey.html>
264
- pub struct rustls_certified_key {
265
- _private : [ u8 ; 0 ] ,
266
- }
267
-
268
- impl Castable for rustls_certified_key {
269
- type Ownership = OwnershipArc ;
270
- type RustType = CertifiedKey ;
250
+ arc_castable ! {
251
+ /// The complete chain of certificates to send during a TLS handshake,
252
+ /// plus a private key that matches the end-entity (leaf) certificate.
253
+ /// Corresponds to `CertifiedKey` in the Rust API.
254
+ /// <https://docs.rs/rustls/latest/rustls/sign/struct.CertifiedKey.html>
255
+ pub struct rustls_certified_key( CertifiedKey ) ;
271
256
}
272
257
273
258
impl rustls_certified_key {
@@ -435,25 +420,20 @@ impl rustls_certified_key {
435
420
}
436
421
}
437
422
438
- /// A `rustls_root_cert_store` being constructed.
439
- ///
440
- /// A builder can be modified by adding trust anchor root certificates with
441
- /// `rustls_root_cert_store_builder_add_pem`. Once you're done adding root certificates,
442
- /// call `rustls_root_cert_store_builder_build` to turn it into a `rustls_root_cert_store`.
443
- /// This object is not safe for concurrent mutation .
444
- pub struct rustls_root_cert_store_builder {
445
- _private : [ u8 ; 0 ] ,
423
+ box_castable ! {
424
+ /// A `rustls_root_cert_store` being constructed.
425
+ ///
426
+ /// A builder can be modified by adding trust anchor root certificates with
427
+ /// `rustls_root_cert_store_builder_add_pem`. Once you're done adding root certificates,
428
+ /// call `rustls_root_cert_store_builder_build` to turn it into a `rustls_root_cert_store` .
429
+ /// This object is not safe for concurrent mutation.
430
+ pub struct rustls_root_cert_store_builder ( Option < RootCertStoreBuilder > ) ;
446
431
}
447
432
448
433
pub ( crate ) struct RootCertStoreBuilder {
449
434
roots : RootCertStore ,
450
435
}
451
436
452
- impl Castable for rustls_root_cert_store_builder {
453
- type Ownership = OwnershipBox ;
454
- type RustType = Option < RootCertStoreBuilder > ;
455
- }
456
-
457
437
impl rustls_root_cert_store_builder {
458
438
/// Create a `rustls_root_cert_store_builder`.
459
439
///
@@ -612,15 +592,10 @@ impl rustls_root_cert_store_builder {
612
592
}
613
593
}
614
594
615
- /// A root certificate store.
616
- /// <https://docs.rs/rustls/latest/rustls/struct.RootCertStore.html>
617
- pub struct rustls_root_cert_store {
618
- _private : [ u8 ; 0 ] ,
619
- }
620
-
621
- impl Castable for rustls_root_cert_store {
622
- type Ownership = OwnershipArc ;
623
- type RustType = RootCertStore ;
595
+ arc_castable ! {
596
+ /// A root certificate store.
597
+ /// <https://docs.rs/rustls/latest/rustls/struct.RootCertStore.html>
598
+ pub struct rustls_root_cert_store( RootCertStore ) ;
624
599
}
625
600
626
601
impl rustls_root_cert_store {
@@ -634,19 +609,15 @@ impl rustls_root_cert_store {
634
609
}
635
610
}
636
611
637
- /// A built client certificate verifier that can be provided to a `rustls_server_config_builder`
638
- /// with `rustls_server_config_builder_set_client_verifier`.
639
- pub struct rustls_client_cert_verifier {
640
- _private : [ u8 ; 0 ] ,
641
- }
642
-
643
- /// Rustls' ConfigBuilder requires an `Arc<dyn ClientCertVerifier>` here, meaning we
644
- /// must follow the pattern described in CONTRIBUTING.md[0] for handling dynamically sized
645
- /// types (DSTs) across the FFI boundary.
646
- /// [0] <https://github.com/rustls/rustls-ffi/blob/main/CONTRIBUTING.md#dynamically-sized-types>
647
- impl Castable for rustls_client_cert_verifier {
648
- type Ownership = OwnershipBox ;
649
- type RustType = Arc < dyn ClientCertVerifier > ;
612
+ box_castable ! {
613
+ /// A built client certificate verifier that can be provided to a `rustls_server_config_builder`
614
+ /// with `rustls_server_config_builder_set_client_verifier`.
615
+ //
616
+ // Rustls' ConfigBuilder requires an `Arc<dyn ClientCertVerifier>` here, meaning we
617
+ // must follow the pattern described in CONTRIBUTING.md[^0] for handling dynamically sized
618
+ // types (DSTs) across the FFI boundary.
619
+ // [^0]: <https://github.com/rustls/rustls-ffi/blob/main/CONTRIBUTING.md#dynamically-sized-types>
620
+ pub struct rustls_client_cert_verifier( Arc <dyn ClientCertVerifier >) ;
650
621
}
651
622
652
623
impl rustls_client_cert_verifier {
@@ -661,18 +632,6 @@ impl rustls_client_cert_verifier {
661
632
}
662
633
}
663
634
664
- /// A client certificate verifier being constructed. A builder can be modified by,
665
- /// e.g. `rustls_web_pki_client_cert_verifier_builder_add_crl`. Once you're
666
- /// done configuring settings, call `rustls_web_pki_client_cert_verifier_builder_build`
667
- /// to turn it into a `rustls_client_cert_verifier`. This object is not safe
668
- /// for concurrent mutation.
669
- ///
670
- /// See <https://docs.rs/rustls/latest/rustls/server/struct.ClientCertVerifierBuilder.html>
671
- /// for more information.
672
- pub struct rustls_web_pki_client_cert_verifier_builder {
673
- _private : [ u8 ; 0 ] ,
674
- }
675
-
676
635
pub ( crate ) struct ClientCertVerifierBuilder {
677
636
roots : Arc < RootCertStore > ,
678
637
root_hint_subjects : Vec < DistinguishedName > ,
@@ -682,9 +641,16 @@ pub(crate) struct ClientCertVerifierBuilder {
682
641
allow_unauthenticated : bool ,
683
642
}
684
643
685
- impl Castable for rustls_web_pki_client_cert_verifier_builder {
686
- type Ownership = OwnershipBox ;
687
- type RustType = Option < ClientCertVerifierBuilder > ;
644
+ box_castable ! {
645
+ /// A client certificate verifier being constructed. A builder can be modified by,
646
+ /// e.g. `rustls_web_pki_client_cert_verifier_builder_add_crl`. Once you're
647
+ /// done configuring settings, call `rustls_web_pki_client_cert_verifier_builder_build`
648
+ /// to turn it into a `rustls_client_cert_verifier`. This object is not safe
649
+ /// for concurrent mutation.
650
+ ///
651
+ /// See <https://docs.rs/rustls/latest/rustls/server/struct.ClientCertVerifierBuilder.html>
652
+ /// for more information.
653
+ pub struct rustls_web_pki_client_cert_verifier_builder( Option <ClientCertVerifierBuilder >) ;
688
654
}
689
655
690
656
impl rustls_web_pki_client_cert_verifier_builder {
@@ -943,16 +909,16 @@ impl rustls_web_pki_client_cert_verifier_builder {
943
909
}
944
910
}
945
911
946
- /// A server certificate verifier being constructed. A builder can be modified by,
947
- /// e.g. `rustls_web_pki_server_cert_verifier_builder_add_crl`. Once you're
948
- /// done configuring settings, call `rustls_web_pki_server_cert_verifier_builder_build`
949
- /// to turn it into a `rustls_server_cert_verifier`. This object is not safe
950
- /// for concurrent mutation.
951
- ///
952
- /// See <https://docs.rs/rustls/latest/rustls/client/struct.ServerCertVerifierBuilder.html>
953
- /// for more information.
954
- pub struct rustls_web_pki_server_cert_verifier_builder {
955
- _private : [ u8 ; 0 ] ,
912
+ box_castable ! {
913
+ /// A server certificate verifier being constructed. A builder can be modified by,
914
+ /// e.g. `rustls_web_pki_server_cert_verifier_builder_add_crl`. Once you're
915
+ /// done configuring settings, call `rustls_web_pki_server_cert_verifier_builder_build`
916
+ /// to turn it into a `rustls_server_cert_verifier`. This object is not safe
917
+ /// for concurrent mutation.
918
+ ///
919
+ /// See <https://docs.rs/rustls/latest/rustls/client/struct.ServerCertVerifierBuilder.html>
920
+ /// for more information.
921
+ pub struct rustls_web_pki_server_cert_verifier_builder ( Option < ServerCertVerifierBuilder > ) ;
956
922
}
957
923
958
924
pub ( crate ) struct ServerCertVerifierBuilder {
@@ -962,11 +928,6 @@ pub(crate) struct ServerCertVerifierBuilder {
962
928
revocation_policy : UnknownStatusPolicy ,
963
929
}
964
930
965
- impl Castable for rustls_web_pki_server_cert_verifier_builder {
966
- type Ownership = OwnershipBox ;
967
- type RustType = Option < ServerCertVerifierBuilder > ;
968
- }
969
-
970
931
impl ServerCertVerifierBuilder {
971
932
/// Create a `rustls_web_pki_server_cert_verifier_builder`. Caller owns the memory and may
972
933
/// free it with `rustls_web_pki_server_cert_verifier_builder_free`, regardless of whether
@@ -1145,19 +1106,15 @@ impl ServerCertVerifierBuilder {
1145
1106
}
1146
1107
}
1147
1108
1148
- /// A built server certificate verifier that can be provided to a `rustls_client_config_builder`
1149
- /// with `rustls_client_config_builder_set_server_verifier`.
1150
- pub struct rustls_server_cert_verifier {
1151
- _private : [ u8 ; 0 ] ,
1152
- }
1153
-
1154
- /// Rustls' ConfigBuilder requires an `Arc<dyn ServerCertVerifier>` here, meaning we
1155
- /// must follow the pattern described in CONTRIBUTING.md[0] for handling dynamically sized
1156
- /// types (DSTs) across the FFI boundary.
1157
- /// [0] <https://github.com/rustls/rustls-ffi/blob/main/CONTRIBUTING.md#dynamically-sized-types>
1158
- impl Castable for rustls_server_cert_verifier {
1159
- type Ownership = OwnershipBox ;
1160
- type RustType = Arc < dyn ServerCertVerifier > ;
1109
+ box_castable ! {
1110
+ /// A built server certificate verifier that can be provided to a `rustls_client_config_builder`
1111
+ /// with `rustls_client_config_builder_set_server_verifier`.
1112
+ //
1113
+ // Rustls' ConfigBuilder requires an `Arc<dyn ServerCertVerifier>` here, meaning we
1114
+ // must follow the pattern described in CONTRIBUTING.md[^0] for handling dynamically sized
1115
+ // types (DSTs) across the FFI boundary.
1116
+ // [^0]: <https://github.com/rustls/rustls-ffi/blob/main/CONTRIBUTING.md#dynamically-sized-types>
1117
+ pub struct rustls_server_cert_verifier( Arc <dyn ServerCertVerifier >) ;
1161
1118
}
1162
1119
1163
1120
impl rustls_server_cert_verifier {
0 commit comments