@@ -12,12 +12,15 @@ use crate::{
1212 protocol:: { decode_ping_pong_framed, no_duplicates, PingPongMessageType } ,
1313 vdaf:: {
1414 prio2:: prio2_prep_init, prio3:: prio3_prep_init, prio3_draft09:: prio3_draft09_prep_init,
15- VdafConfig , VdafPrepShare , VdafPrepState ,
15+ VdafConfig , VdafPrepShare , VdafPrepState , VdafVerifyKey ,
1616 } ,
17- DapAggregationParam , DapError , DapTaskConfig ,
17+ DapAggregationParam , DapError , DapTaskConfig , DapVersion ,
1818} ;
1919use prio:: codec:: { CodecError , ParameterizedDecode as _} ;
20- use std:: ops:: { Deref , Range } ;
20+ use std:: {
21+ borrow:: Cow ,
22+ ops:: { Deref , Range } ,
23+ } ;
2124
2225/// Report state during aggregation initialization after the VDAF preparation step.
2326///
@@ -43,6 +46,12 @@ pub enum InitializedReport<Peer> {
4346
4447pub struct WithPeerPrepShare ( Vec < u8 > ) ;
4548
49+ impl From < Vec < u8 > > for WithPeerPrepShare {
50+ fn from ( value : Vec < u8 > ) -> Self {
51+ Self ( value)
52+ }
53+ }
54+
4655impl Deref for WithPeerPrepShare {
4756 type Target = Vec < u8 > ;
4857 fn deref ( & self ) -> & Self :: Target {
@@ -51,11 +60,11 @@ impl Deref for WithPeerPrepShare {
5160}
5261
5362impl InitializedReport < ( ) > {
54- pub fn from_client (
63+ pub fn from_client < ' s > (
5564 decrypter : & impl HpkeDecrypter ,
5665 valid_report_range : Range < messages:: Time > ,
5766 task_id : & TaskId ,
58- task_config : & DapTaskConfig ,
67+ task_config : impl Into < PartialDapTaskConfig < ' s > > ,
5968 report_share : ReportShare ,
6069 agg_param : & DapAggregationParam ,
6170 ) -> Result < Self , DapError > {
@@ -72,11 +81,11 @@ impl InitializedReport<()> {
7281}
7382
7483impl InitializedReport < WithPeerPrepShare > {
75- pub fn from_leader (
84+ pub fn from_leader < ' s > (
7685 decrypter : & impl HpkeDecrypter ,
7786 valid_report_range : Range < messages:: Time > ,
7887 task_id : & TaskId ,
79- task_config : & DapTaskConfig ,
88+ task_config : impl Into < PartialDapTaskConfig < ' s > > ,
8089 report_share : ReportShare ,
8190 prep_init_payload : Vec < u8 > ,
8291 agg_param : & DapAggregationParam ,
@@ -93,12 +102,44 @@ impl InitializedReport<WithPeerPrepShare> {
93102 }
94103}
95104
105+ impl < ' s > From < & ' s DapTaskConfig > for PartialDapTaskConfig < ' s > {
106+ fn from ( config : & ' s DapTaskConfig ) -> Self {
107+ PartialDapTaskConfig {
108+ not_after : config. not_after ,
109+ method_is_taskprov : config. method_is_taskprov ( ) ,
110+ version : config. version ,
111+ vdaf : Cow :: Borrowed ( & config. vdaf ) ,
112+ vdaf_verify_key : Cow :: Borrowed ( & config. vdaf_verify_key ) ,
113+ }
114+ }
115+ }
116+
117+ impl < ' s > From < & ' s PartialDapTaskConfig < ' _ > > for PartialDapTaskConfig < ' s > {
118+ fn from ( config : & ' s PartialDapTaskConfig < ' _ > ) -> Self {
119+ Self {
120+ not_after : config. not_after ,
121+ method_is_taskprov : config. method_is_taskprov ,
122+ version : config. version ,
123+ vdaf : Cow :: Borrowed ( & config. vdaf ) ,
124+ vdaf_verify_key : Cow :: Borrowed ( & config. vdaf_verify_key ) ,
125+ }
126+ }
127+ }
128+
129+ pub struct PartialDapTaskConfig < ' s > {
130+ pub not_after : messages:: Time ,
131+ pub method_is_taskprov : bool ,
132+ pub version : DapVersion ,
133+ pub vdaf : Cow < ' s , VdafConfig > ,
134+ pub vdaf_verify_key : Cow < ' s , VdafVerifyKey > ,
135+ }
136+
96137impl < P > InitializedReport < P > {
97- fn initialize < S > (
138+ fn initialize < ' s , S > (
98139 decrypter : & impl HpkeDecrypter ,
99140 valid_report_range : Range < messages:: Time > ,
100141 task_id : & TaskId ,
101- task_config : & DapTaskConfig ,
142+ task_config : impl Into < PartialDapTaskConfig < ' s > > ,
102143 report_share : ReportShare ,
103144 prep_init_payload : S ,
104145 // We need to use this variable for Mastic, which is currently fenced by the
@@ -109,6 +150,7 @@ impl<P> InitializedReport<P> {
109150 where
110151 S : PrepInitPayload < Decoded = P > ,
111152 {
153+ let task_config = task_config. into ( ) ;
112154 macro_rules! reject {
113155 ( $failure: ident) => {
114156 return Ok ( InitializedReport :: Rejected {
@@ -166,7 +208,7 @@ impl<P> InitializedReport<P> {
166208 let mut taskprov_indicated = false ;
167209 for extension in extensions {
168210 match extension {
169- Extension :: Taskprov { .. } if task_config. method_is_taskprov ( ) => {
211+ Extension :: Taskprov { .. } if task_config. method_is_taskprov => {
170212 taskprov_indicated = true ;
171213 }
172214
@@ -175,7 +217,7 @@ impl<P> InitializedReport<P> {
175217 }
176218 }
177219
178- if task_config. method_is_taskprov ( ) && !taskprov_indicated {
220+ if task_config. method_is_taskprov && !taskprov_indicated {
179221 // taskprov: If the task configuration method is taskprov, then we expect each
180222 // report to indicate support.
181223 reject ! ( InvalidMessage ) ;
@@ -196,7 +238,7 @@ impl<P> InitializedReport<P> {
196238 DapAggregatorRole :: Leader => 0 ,
197239 DapAggregatorRole :: Helper => 1 ,
198240 } ;
199- let res = match & task_config. vdaf {
241+ let res = match task_config. vdaf . as_ref ( ) {
200242 VdafConfig :: Prio3Draft09 ( ref prio3_config) => prio3_draft09_prep_init (
201243 prio3_config,
202244 & task_config. vdaf_verify_key ,
0 commit comments