@@ -75,6 +75,16 @@ pub(crate) struct PolicyBuilder {
75
75
max_chain_depth : Option < u8 > ,
76
76
}
77
77
78
+ impl PolicyBuilder {
79
+ fn py_clone ( & self , py : pyo3:: Python < ' _ > ) -> PolicyBuilder {
80
+ PolicyBuilder {
81
+ time : self . time . clone ( ) ,
82
+ store : self . store . as_ref ( ) . map ( |s| s. clone_ref ( py) ) ,
83
+ max_chain_depth : self . max_chain_depth ,
84
+ }
85
+ }
86
+ }
87
+
78
88
#[ pyo3:: pymethods]
79
89
impl PolicyBuilder {
80
90
#[ new]
@@ -95,18 +105,20 @@ impl PolicyBuilder {
95
105
96
106
Ok ( PolicyBuilder {
97
107
time : Some ( py_to_datetime ( py, new_time) ?) ,
98
- store : self . store . as_ref ( ) . map ( |s| s. clone_ref ( py) ) ,
99
- max_chain_depth : self . max_chain_depth ,
108
+ ..self . py_clone ( py)
100
109
} )
101
110
}
102
111
103
- fn store ( & self , new_store : pyo3:: Py < PyStore > ) -> CryptographyResult < PolicyBuilder > {
112
+ fn store (
113
+ & self ,
114
+ py : pyo3:: Python < ' _ > ,
115
+ new_store : pyo3:: Py < PyStore > ,
116
+ ) -> CryptographyResult < PolicyBuilder > {
104
117
policy_builder_set_once_check ! ( self , store, "trust store" ) ;
105
118
106
119
Ok ( PolicyBuilder {
107
- time : self . time . clone ( ) ,
108
120
store : Some ( new_store) ,
109
- max_chain_depth : self . max_chain_depth ,
121
+ .. self . py_clone ( py )
110
122
} )
111
123
}
112
124
@@ -118,9 +130,8 @@ impl PolicyBuilder {
118
130
policy_builder_set_once_check ! ( self , max_chain_depth, "maximum chain depth" ) ;
119
131
120
132
Ok ( PolicyBuilder {
121
- time : self . time . clone ( ) ,
122
- store : self . store . as_ref ( ) . map ( |s| s. clone_ref ( py) ) ,
123
133
max_chain_depth : Some ( new_max_chain_depth) ,
134
+ ..self . py_clone ( py)
124
135
} )
125
136
}
126
137
@@ -141,7 +152,8 @@ impl PolicyBuilder {
141
152
None => datetime_now ( py) ?,
142
153
} ;
143
154
144
- let policy = PyCryptoPolicy ( Policy :: client ( PyCryptoOps { } , time, self . max_chain_depth ) ) ;
155
+ // TODO: Pass extension policies here once implemented in cryptography-x509-verification.
156
+ let policy = Policy :: client ( PyCryptoOps { } , time, self . max_chain_depth ) ;
145
157
146
158
Ok ( PyClientVerifier { policy, store } )
147
159
}
@@ -170,12 +182,14 @@ impl PolicyBuilder {
170
182
171
183
let policy = OwnedPolicy :: try_new ( subject_owner, |subject_owner| {
172
184
let subject = build_subject ( py, subject_owner) ?;
173
- Ok :: < PyCryptoPolicy < ' _ > , pyo3:: PyErr > ( PyCryptoPolicy ( Policy :: server (
185
+
186
+ // TODO: Pass extension policies here once implemented in cryptography-x509-verification.
187
+ Ok :: < PyCryptoPolicy < ' _ > , pyo3:: PyErr > ( Policy :: server (
174
188
PyCryptoOps { } ,
175
189
subject,
176
190
time,
177
191
self . max_chain_depth ,
178
- ) ) )
192
+ ) )
179
193
} ) ?;
180
194
181
195
Ok ( PyServerVerifier {
@@ -186,7 +200,7 @@ impl PolicyBuilder {
186
200
}
187
201
}
188
202
189
- struct PyCryptoPolicy < ' a > ( Policy < ' a , PyCryptoOps > ) ;
203
+ type PyCryptoPolicy < ' a > = Policy < ' a , PyCryptoOps > ;
190
204
191
205
/// This enum exists solely to provide heterogeneously typed ownership for `OwnedPolicy`.
192
206
enum SubjectOwner {
@@ -215,7 +229,7 @@ self_cell::self_cell!(
215
229
) ]
216
230
pub ( crate ) struct PyVerifiedClient {
217
231
#[ pyo3( get) ]
218
- subjects : pyo3:: Py < pyo3:: PyAny > ,
232
+ subjects : Option < pyo3:: Py < pyo3:: PyAny > > ,
219
233
#[ pyo3( get) ]
220
234
chain : pyo3:: Py < pyo3:: types:: PyList > ,
221
235
}
@@ -233,7 +247,7 @@ pub(crate) struct PyClientVerifier {
233
247
234
248
impl PyClientVerifier {
235
249
fn as_policy ( & self ) -> & Policy < ' _ , PyCryptoOps > {
236
- & self . policy . 0
250
+ & self . policy
237
251
}
238
252
}
239
253
@@ -305,7 +319,7 @@ impl PyClientVerifier {
305
319
let py_gns = parse_general_names ( py, & leaf_gns) ?;
306
320
307
321
Ok ( PyVerifiedClient {
308
- subjects : py_gns,
322
+ subjects : Some ( py_gns) ,
309
323
chain : py_chain. unbind ( ) ,
310
324
} )
311
325
}
@@ -326,7 +340,7 @@ pub(crate) struct PyServerVerifier {
326
340
327
341
impl PyServerVerifier {
328
342
fn as_policy ( & self ) -> & Policy < ' _ , PyCryptoOps > {
329
- & self . policy . borrow_dependent ( ) . 0
343
+ self . policy . borrow_dependent ( )
330
344
}
331
345
}
332
346
0 commit comments