|
3 | 3 | //! This module provides functionality for generating privacy-preserving synthetic IDs |
4 | 4 | //! based on various request parameters and a secret key. |
5 | 5 |
|
6 | | -use error_stack::Report; |
| 6 | +use error_stack::{Report, ResultExt}; |
7 | 7 | use fastly::http::header; |
8 | 8 | use fastly::Request; |
9 | 9 | use handlebars::Handlebars; |
@@ -62,20 +62,15 @@ pub fn generate_synthetic_id( |
62 | 62 |
|
63 | 63 | let input_string = handlebars |
64 | 64 | .render_template(&settings.synthetic.template, data) |
65 | | - .map_err(|e| { |
66 | | - Report::new(TrustedServerError::Template { |
67 | | - message: "Failed to render synthetic ID template".to_string(), |
68 | | - }) |
69 | | - .attach_printable(e.to_string()) |
| 65 | + .change_context(TrustedServerError::Template { |
| 66 | + message: "Failed to render synthetic ID template".to_string(), |
70 | 67 | })?; |
| 68 | + |
71 | 69 | log::info!("Input string for fresh ID: {} {}", input_string, data); |
72 | 70 |
|
73 | | - let mut mac = |
74 | | - HmacSha256::new_from_slice(settings.synthetic.secret_key.as_bytes()).map_err(|e| { |
75 | | - Report::new(TrustedServerError::SyntheticId { |
76 | | - message: "Failed to create HMAC instance".to_string(), |
77 | | - }) |
78 | | - .attach_printable(e.to_string()) |
| 71 | + let mut mac = HmacSha256::new_from_slice(settings.synthetic.secret_key.as_bytes()) |
| 72 | + .change_context(TrustedServerError::SyntheticId { |
| 73 | + message: "Failed to create HMAC instance".to_string(), |
79 | 74 | })?; |
80 | 75 | mac.update(input_string.as_bytes()); |
81 | 76 | let fresh_id = hex::encode(mac.finalize().into_bytes()); |
|
0 commit comments