@@ -43,20 +43,22 @@ where
43
43
}
44
44
45
45
/// Generates a stable unique identifier for this order.
46
- pub fn cache_key ( & self ) -> std :: string :: String
46
+ pub fn cache_key ( & self ) -> PrintableOrderId < ' _ , S , A >
47
47
where
48
48
S : fmt:: Display + hash:: Hash ,
49
49
{
50
- if self . identifiers . is_empty ( ) {
51
- return "" . into ( ) ;
52
- }
53
-
54
- let name = self . identifiers [ 0 ] . value ( ) ;
50
+ PrintableOrderId ( self )
51
+ }
55
52
56
- let mut hasher = SipHasher :: default ( ) ;
57
- self . hash ( & mut hasher) ;
53
+ /// Attempts to find the first DNS identifier, with fallback to a first identifier of any kind.
54
+ pub fn first_name ( & self ) -> Option < & S > {
55
+ let dns = self
56
+ . identifiers
57
+ . iter ( )
58
+ . find ( |x| matches ! ( x, Identifier :: Dns ( _) ) ) ;
58
59
59
- std:: format!( "{name}-{hash:x}" , hash = hasher. finish( ) )
60
+ dns. or_else ( || self . identifiers . first ( ) )
61
+ . map ( Identifier :: value)
60
62
}
61
63
62
64
pub fn to_str_order < NewA > ( & self , alloc : NewA ) -> CertificateOrder < & str , NewA >
@@ -247,6 +249,30 @@ impl CertificateOrder<ngx_str_t, Pool> {
247
249
}
248
250
}
249
251
252
+ /// Unique identifier for the CertificateOrder.
253
+ ///
254
+ /// This identifier should be suitable for logs, file names or cache keys.
255
+ pub struct PrintableOrderId < ' a , S , A > ( & ' a CertificateOrder < S , A > )
256
+ where
257
+ A : ngx:: allocator:: Allocator ;
258
+
259
+ impl < S , A > fmt:: Display for PrintableOrderId < ' _ , S , A >
260
+ where
261
+ A : ngx:: allocator:: Allocator ,
262
+ S : fmt:: Display + hash:: Hash ,
263
+ {
264
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
265
+ let Some ( name) = self . 0 . first_name ( ) else {
266
+ return Ok ( ( ) ) ;
267
+ } ;
268
+
269
+ let mut hasher = SipHasher :: default ( ) ;
270
+ self . 0 . hash ( & mut hasher) ;
271
+
272
+ write ! ( f, "{name}-{hash:x}" , hash = hasher. finish( ) )
273
+ }
274
+ }
275
+
250
276
fn validate_host ( pool : & Pool , mut host : ngx_str_t ) -> Result < ngx_str_t , Status > {
251
277
let mut pool = pool. clone ( ) ;
252
278
let rc = Status ( unsafe { nginx_sys:: ngx_http_validate_host ( & mut host, pool. as_mut ( ) , 1 ) } ) ;
0 commit comments