Skip to content

Commit

Permalink
Rename DapVersion::Latest to DapVersion::DraftLatest
Browse files Browse the repository at this point in the history
  • Loading branch information
cjpatton committed Nov 29, 2023
1 parent 5a79b6e commit 8a31bd4
Show file tree
Hide file tree
Showing 16 changed files with 189 additions and 167 deletions.
87 changes: 48 additions & 39 deletions daphne/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,31 +68,33 @@ impl DapMediaType {
pub fn from_str_for_version(version: DapVersion, content_type: Option<&str>) -> Self {
match (version, content_type) {
(DapVersion::Draft02, Some(DRAFT02_MEDIA_TYPE_AGG_CONT_REQ))
| (DapVersion::Latest, Some(MEDIA_TYPE_AGG_JOB_CONT_REQ)) => {
| (DapVersion::DraftLatest, Some(MEDIA_TYPE_AGG_JOB_CONT_REQ)) => {
Self::AggregationJobContinueReq
}
(DapVersion::Draft02, Some(DRAFT02_MEDIA_TYPE_AGG_CONT_RESP)) => {
Self::Draft02AggregateContinueResp
}
(DapVersion::Draft02, Some(DRAFT02_MEDIA_TYPE_AGG_INIT_REQ))
| (DapVersion::Latest, Some(MEDIA_TYPE_AGG_JOB_INIT_REQ)) => {
| (DapVersion::DraftLatest, Some(MEDIA_TYPE_AGG_JOB_INIT_REQ)) => {
Self::AggregationJobInitReq
}
(DapVersion::Draft02, Some(DRAFT02_MEDIA_TYPE_AGG_INIT_RESP))
| (DapVersion::Latest, Some(MEDIA_TYPE_AGG_JOB_RESP)) => Self::AggregationJobResp,
| (DapVersion::DraftLatest, Some(MEDIA_TYPE_AGG_JOB_RESP)) => Self::AggregationJobResp,
(DapVersion::Draft02, Some(DRAFT02_MEDIA_TYPE_AGG_SHARE_RESP))
| (DapVersion::Latest, Some(MEDIA_TYPE_AGG_SHARE)) => Self::AggregateShare,
| (DapVersion::DraftLatest, Some(MEDIA_TYPE_AGG_SHARE)) => Self::AggregateShare,
(DapVersion::Draft02, Some(DRAFT02_MEDIA_TYPE_COLLECT_RESP))
| (DapVersion::Latest, Some(MEDIA_TYPE_COLLECTION)) => Self::Collection,
| (DapVersion::DraftLatest, Some(MEDIA_TYPE_COLLECTION)) => Self::Collection,
(DapVersion::Draft02, Some(DRAFT02_MEDIA_TYPE_HPKE_CONFIG))
| (DapVersion::Latest, Some(MEDIA_TYPE_HPKE_CONFIG_LIST)) => Self::HpkeConfigList,
(DapVersion::Draft02 | DapVersion::Latest, Some(MEDIA_TYPE_AGG_SHARE_REQ)) => {
| (DapVersion::DraftLatest, Some(MEDIA_TYPE_HPKE_CONFIG_LIST)) => Self::HpkeConfigList,
(DapVersion::Draft02 | DapVersion::DraftLatest, Some(MEDIA_TYPE_AGG_SHARE_REQ)) => {
Self::AggregateShareReq
}
(DapVersion::Draft02 | DapVersion::Latest, Some(MEDIA_TYPE_COLLECT_REQ)) => {
(DapVersion::Draft02 | DapVersion::DraftLatest, Some(MEDIA_TYPE_COLLECT_REQ)) => {
Self::CollectReq
}
(DapVersion::Draft02 | DapVersion::Latest, Some(MEDIA_TYPE_REPORT)) => Self::Report,
(DapVersion::Draft02 | DapVersion::DraftLatest, Some(MEDIA_TYPE_REPORT)) => {
Self::Report
}
(_, Some(content_type)) => Self::Invalid(content_type.to_string()),
(_, None) => Self::Missing,
}
Expand All @@ -104,33 +106,37 @@ impl DapMediaType {
(DapVersion::Draft02, Self::AggregationJobInitReq) => {
Some(DRAFT02_MEDIA_TYPE_AGG_INIT_REQ)
}
(DapVersion::Latest, Self::AggregationJobInitReq) => Some(MEDIA_TYPE_AGG_JOB_INIT_REQ),
(DapVersion::DraftLatest, Self::AggregationJobInitReq) => {
Some(MEDIA_TYPE_AGG_JOB_INIT_REQ)
}
(DapVersion::Draft02, Self::AggregationJobResp) => {
Some(DRAFT02_MEDIA_TYPE_AGG_INIT_RESP)
}
(DapVersion::Latest, Self::AggregationJobResp) => Some(MEDIA_TYPE_AGG_JOB_RESP),
(DapVersion::DraftLatest, Self::AggregationJobResp) => Some(MEDIA_TYPE_AGG_JOB_RESP),
(DapVersion::Draft02, Self::AggregationJobContinueReq) => {
Some(DRAFT02_MEDIA_TYPE_AGG_CONT_REQ)
}
(DapVersion::Latest, Self::AggregationJobContinueReq) => {
(DapVersion::DraftLatest, Self::AggregationJobContinueReq) => {
Some(MEDIA_TYPE_AGG_JOB_CONT_REQ)
}
(DapVersion::Draft02, Self::Draft02AggregateContinueResp) => {
Some(DRAFT02_MEDIA_TYPE_AGG_CONT_RESP)
}
(DapVersion::Draft02 | DapVersion::Latest, Self::AggregateShareReq) => {
(DapVersion::Draft02 | DapVersion::DraftLatest, Self::AggregateShareReq) => {
Some(MEDIA_TYPE_AGG_SHARE_REQ)
}
(DapVersion::Draft02, Self::AggregateShare) => Some(DRAFT02_MEDIA_TYPE_AGG_SHARE_RESP),
(DapVersion::Latest, Self::AggregateShare) => Some(MEDIA_TYPE_AGG_SHARE),
(DapVersion::Draft02 | DapVersion::Latest, Self::CollectReq) => {
(DapVersion::DraftLatest, Self::AggregateShare) => Some(MEDIA_TYPE_AGG_SHARE),
(DapVersion::Draft02 | DapVersion::DraftLatest, Self::CollectReq) => {
Some(MEDIA_TYPE_COLLECT_REQ)
}
(DapVersion::Draft02, Self::Collection) => Some(DRAFT02_MEDIA_TYPE_COLLECT_RESP),
(DapVersion::Latest, Self::Collection) => Some(MEDIA_TYPE_COLLECTION),
(DapVersion::DraftLatest, Self::Collection) => Some(MEDIA_TYPE_COLLECTION),
(DapVersion::Draft02, Self::HpkeConfigList) => Some(DRAFT02_MEDIA_TYPE_HPKE_CONFIG),
(DapVersion::Latest, Self::HpkeConfigList) => Some(MEDIA_TYPE_HPKE_CONFIG_LIST),
(DapVersion::Draft02 | DapVersion::Latest, Self::Report) => Some(MEDIA_TYPE_REPORT),
(DapVersion::DraftLatest, Self::HpkeConfigList) => Some(MEDIA_TYPE_HPKE_CONFIG_LIST),
(DapVersion::Draft02 | DapVersion::DraftLatest, Self::Report) => {
Some(MEDIA_TYPE_REPORT)
}
(_, Self::Draft02AggregateContinueResp | Self::Missing) => None,
(_, Self::Invalid(ref content_type)) => Some(content_type),
}
Expand All @@ -141,7 +147,7 @@ impl DapMediaType {
pub(crate) fn agg_job_cont_resp_for_version(version: DapVersion) -> Self {
match version {
DapVersion::Draft02 => Self::Draft02AggregateContinueResp,
DapVersion::Latest => Self::AggregationJobResp,
DapVersion::DraftLatest => Self::AggregationJobResp,
}
}
}
Expand Down Expand Up @@ -220,70 +226,70 @@ mod test {

assert_eq!(
DapMediaType::from_str_for_version(
DapVersion::Latest,
DapVersion::DraftLatest,
Some("application/dap-hpke-config-list")
),
DapMediaType::HpkeConfigList
);
assert_eq!(
DapMediaType::from_str_for_version(
DapVersion::Latest,
DapVersion::DraftLatest,
Some("application/dap-aggregation-job-init-req")
),
DapMediaType::AggregationJobInitReq,
);
assert_eq!(
DapMediaType::from_str_for_version(
DapVersion::Latest,
DapVersion::DraftLatest,
Some("application/dap-aggregation-job-resp")
),
DapMediaType::AggregationJobResp,
);
assert_eq!(
DapMediaType::from_str_for_version(
DapVersion::Latest,
DapVersion::DraftLatest,
Some("application/dap-aggregation-job-continue-req")
),
DapMediaType::AggregationJobContinueReq,
);
assert_eq!(
DapMediaType::from_str_for_version(
DapVersion::Latest,
DapVersion::DraftLatest,
Some("application/dap-aggregate-share-req")
),
DapMediaType::AggregateShareReq,
);
assert_eq!(
DapMediaType::from_str_for_version(
DapVersion::Latest,
DapVersion::DraftLatest,
Some("application/dap-aggregate-share")
),
DapMediaType::AggregateShare,
);
assert_eq!(
DapMediaType::from_str_for_version(
DapVersion::Latest,
DapVersion::DraftLatest,
Some("application/dap-collect-req")
),
DapMediaType::CollectReq,
);
assert_eq!(
DapMediaType::from_str_for_version(
DapVersion::Latest,
DapVersion::DraftLatest,
Some("application/dap-collection")
),
DapMediaType::Collection,
);

// Invalid media type
assert_eq!(
DapMediaType::from_str_for_version(DapVersion::Latest, Some("blah-blah-blah")),
DapMediaType::from_str_for_version(DapVersion::DraftLatest, Some("blah-blah-blah")),
DapMediaType::Invalid("blah-blah-blah".into()),
);

// Missing media type
assert_eq!(
DapMediaType::from_str_for_version(DapVersion::Latest, None),
DapMediaType::from_str_for_version(DapVersion::DraftLatest, None),
DapMediaType::Missing,
);
}
Expand All @@ -292,27 +298,30 @@ mod test {
fn round_trip() {
for (version, media_type) in [
(DapVersion::Draft02, DapMediaType::AggregationJobInitReq),
(DapVersion::Latest, DapMediaType::AggregationJobInitReq),
(DapVersion::DraftLatest, DapMediaType::AggregationJobInitReq),
(DapVersion::Draft02, DapMediaType::AggregationJobResp),
(DapVersion::Latest, DapMediaType::AggregationJobResp),
(DapVersion::DraftLatest, DapMediaType::AggregationJobResp),
(DapVersion::Draft02, DapMediaType::AggregationJobContinueReq),
(DapVersion::Latest, DapMediaType::AggregationJobContinueReq),
(
DapVersion::DraftLatest,
DapMediaType::AggregationJobContinueReq,
),
(
DapVersion::Draft02,
DapMediaType::Draft02AggregateContinueResp,
),
(DapVersion::Draft02, DapMediaType::AggregateShareReq),
(DapVersion::Latest, DapMediaType::AggregateShareReq),
(DapVersion::DraftLatest, DapMediaType::AggregateShareReq),
(DapVersion::Draft02, DapMediaType::AggregateShare),
(DapVersion::Latest, DapMediaType::AggregateShare),
(DapVersion::DraftLatest, DapMediaType::AggregateShare),
(DapVersion::Draft02, DapMediaType::CollectReq),
(DapVersion::Latest, DapMediaType::CollectReq),
(DapVersion::DraftLatest, DapMediaType::CollectReq),
(DapVersion::Draft02, DapMediaType::Collection),
(DapVersion::Latest, DapMediaType::Collection),
(DapVersion::DraftLatest, DapMediaType::Collection),
(DapVersion::Draft02, DapMediaType::HpkeConfigList),
(DapVersion::Latest, DapMediaType::HpkeConfigList),
(DapVersion::DraftLatest, DapMediaType::HpkeConfigList),
(DapVersion::Draft02, DapMediaType::Report),
(DapVersion::Latest, DapMediaType::Report),
(DapVersion::DraftLatest, DapMediaType::Report),
] {
assert_eq!(
DapMediaType::from_str_for_version(version, media_type.as_str_for_version(version)),
Expand All @@ -333,7 +342,7 @@ mod test {

assert_eq!(
DapMediaType::AggregationJobResp,
DapMediaType::agg_job_cont_resp_for_version(DapVersion::Latest)
DapMediaType::agg_job_cont_resp_for_version(DapVersion::DraftLatest)
);
}
}
24 changes: 13 additions & 11 deletions daphne/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ pub enum DapVersion {

#[serde(rename = "v09")]
#[default]
Latest,
DraftLatest,
}

impl FromStr for DapVersion {
type Err = DapAbort;
fn from_str(version: &str) -> Result<Self, Self::Err> {
match version {
"v02" => Ok(DapVersion::Draft02),
"v09" => Ok(DapVersion::Latest),
"v09" => Ok(DapVersion::DraftLatest),
_ => Err(DapAbort::version_unknown()),
}
}
Expand All @@ -126,7 +126,7 @@ impl AsRef<str> for DapVersion {
fn as_ref(&self) -> &str {
match self {
DapVersion::Draft02 => "v02",
DapVersion::Latest => "v09",
DapVersion::DraftLatest => "v09",
}
}
}
Expand Down Expand Up @@ -496,7 +496,9 @@ impl DapTaskParameters {
.unwrap();

let (taskprov_advertisement, taskprov_report_extension_payload) = match self.version {
DapVersion::Latest => (Some(encode_base64url(&encoded_taskprov_config)), Vec::new()),
DapVersion::DraftLatest => {
(Some(encode_base64url(&encoded_taskprov_config)), Vec::new())
}
// draft02 compatibility: The taskprov config is advertised in an HTTP header in
// the latest draft. In draft02, it is carried by a report extension.
DapVersion::Draft02 => (None, encoded_taskprov_config),
Expand Down Expand Up @@ -1124,7 +1126,7 @@ pub struct DapRequest<S> {
impl<S> Default for DapRequest<S> {
fn default() -> Self {
Self {
version: DapVersion::Latest,
version: DapVersion::DraftLatest,
media_type: Default::default(),
task_id: Default::default(),
resource: Default::default(),
Expand Down Expand Up @@ -1218,7 +1220,7 @@ pub struct DapLeaderProcessTelemetry {
#[derive(Clone, Debug)]
pub enum MetaAggregationJobId {
Draft02(Draft02AggregationJobId),
Latest(AggregationJobId),
DraftLatest(AggregationJobId),
}

impl MetaAggregationJobId {
Expand All @@ -1227,7 +1229,7 @@ impl MetaAggregationJobId {
let mut rng = thread_rng();
match version {
DapVersion::Draft02 => Self::Draft02(Draft02AggregationJobId(rng.gen())),
DapVersion::Latest => Self::Latest(AggregationJobId(rng.gen())),
DapVersion::DraftLatest => Self::DraftLatest(AggregationJobId(rng.gen())),
}
}

Expand All @@ -1236,7 +1238,7 @@ impl MetaAggregationJobId {
pub(crate) fn for_request_payload(&self) -> Option<Draft02AggregationJobId> {
match self {
Self::Draft02(agg_job_id) => Some(*agg_job_id),
Self::Latest(..) => None,
Self::DraftLatest(..) => None,
}
}

Expand All @@ -1246,23 +1248,23 @@ impl MetaAggregationJobId {
match self {
// In draft02, the aggregation job ID is not determined until the payload is parsed.
Self::Draft02(..) => DapResource::Undefined,
Self::Latest(agg_job_id) => DapResource::AggregationJob(*agg_job_id),
Self::DraftLatest(agg_job_id) => DapResource::AggregationJob(*agg_job_id),
}
}

/// Convert this aggregation job ID into hex.
pub fn to_hex(&self) -> String {
match self {
Self::Draft02(agg_job_id) => agg_job_id.to_hex(),
Self::Latest(agg_job_id) => agg_job_id.to_hex(),
Self::DraftLatest(agg_job_id) => agg_job_id.to_hex(),
}
}

/// Convert this aggregation job ID into base64url form.
pub fn to_base64url(&self) -> String {
match self {
Self::Draft02(agg_job_id) => agg_job_id.to_base64url(),
Self::Latest(agg_job_id) => agg_job_id.to_base64url(),
Self::DraftLatest(agg_job_id) => agg_job_id.to_base64url(),
}
}
}
Loading

0 comments on commit 8a31bd4

Please sign in to comment.