Skip to content

Commit

Permalink
Replace draft04 references with draft05
Browse files Browse the repository at this point in the history
  • Loading branch information
cjpatton committed Jun 20, 2023
1 parent a45876f commit d913ce7
Show file tree
Hide file tree
Showing 16 changed files with 115 additions and 115 deletions.
38 changes: 19 additions & 19 deletions daphne/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,30 +68,30 @@ 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::Draft04, Some(MEDIA_TYPE_AGG_JOB_CONT_REQ)) => {
| (DapVersion::Draft05, 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::Draft04, Some(MEDIA_TYPE_AGG_JOB_INIT_REQ)) => {
| (DapVersion::Draft05, Some(MEDIA_TYPE_AGG_JOB_INIT_REQ)) => {
Self::AggregationJobInitReq
}
(DapVersion::Draft02, Some(DRAFT02_MEDIA_TYPE_AGG_INIT_RESP))
| (DapVersion::Draft04, Some(MEDIA_TYPE_AGG_JOB_RESP)) => Self::AggregationJobResp,
| (DapVersion::Draft05, Some(MEDIA_TYPE_AGG_JOB_RESP)) => Self::AggregationJobResp,
(DapVersion::Draft02, Some(DRAFT02_MEDIA_TYPE_AGG_SHARE_RESP))
| (DapVersion::Draft04, Some(MEDIA_TYPE_AGG_SHARE)) => Self::AggregateShare,
| (DapVersion::Draft05, Some(MEDIA_TYPE_AGG_SHARE)) => Self::AggregateShare,
(DapVersion::Draft02, Some(DRAFT02_MEDIA_TYPE_COLLECT_RESP))
| (DapVersion::Draft04, Some(MEDIA_TYPE_COLLECTION)) => Self::Collection,
| (DapVersion::Draft05, Some(MEDIA_TYPE_COLLECTION)) => Self::Collection,
(DapVersion::Draft02, Some(DRAFT02_MEDIA_TYPE_HPKE_CONFIG))
| (DapVersion::Draft04, Some(MEDIA_TYPE_HPKE_CONFIG_LIST)) => Self::HpkeConfigList,
| (DapVersion::Draft05, Some(MEDIA_TYPE_HPKE_CONFIG_LIST)) => Self::HpkeConfigList,
(DapVersion::Draft02, Some(MEDIA_TYPE_AGG_SHARE_REQ))
| (DapVersion::Draft04, Some(MEDIA_TYPE_AGG_SHARE_REQ)) => Self::AggregateShareReq,
| (DapVersion::Draft05, Some(MEDIA_TYPE_AGG_SHARE_REQ)) => Self::AggregateShareReq,
(DapVersion::Draft02, Some(MEDIA_TYPE_COLLECT_REQ))
| (DapVersion::Draft04, Some(MEDIA_TYPE_COLLECT_REQ)) => Self::CollectReq,
| (DapVersion::Draft05, Some(MEDIA_TYPE_COLLECT_REQ)) => Self::CollectReq,
(DapVersion::Draft02, Some(MEDIA_TYPE_REPORT))
| (DapVersion::Draft04, Some(MEDIA_TYPE_REPORT)) => Self::Report,
| (DapVersion::Draft05, Some(MEDIA_TYPE_REPORT)) => Self::Report,
(_, Some(content_type)) => Self::Invalid(content_type.to_string()),
(_, None) => Self::Missing,
}
Expand All @@ -103,33 +103,33 @@ impl DapMediaType {
(DapVersion::Draft02, Self::AggregationJobInitReq) => {
Some(DRAFT02_MEDIA_TYPE_AGG_INIT_REQ)
}
(DapVersion::Draft04, Self::AggregationJobInitReq) => Some(MEDIA_TYPE_AGG_JOB_INIT_REQ),
(DapVersion::Draft05, Self::AggregationJobInitReq) => Some(MEDIA_TYPE_AGG_JOB_INIT_REQ),
(DapVersion::Draft02, Self::AggregationJobResp) => {
Some(DRAFT02_MEDIA_TYPE_AGG_INIT_RESP)
}
(DapVersion::Draft04, Self::AggregationJobResp) => Some(MEDIA_TYPE_AGG_JOB_RESP),
(DapVersion::Draft05, Self::AggregationJobResp) => Some(MEDIA_TYPE_AGG_JOB_RESP),
(DapVersion::Draft02, Self::AggregationJobContinueReq) => {
Some(DRAFT02_MEDIA_TYPE_AGG_CONT_REQ)
}
(DapVersion::Draft04, Self::AggregationJobContinueReq) => {
(DapVersion::Draft05, Self::AggregationJobContinueReq) => {
Some(MEDIA_TYPE_AGG_JOB_CONT_REQ)
}
(DapVersion::Draft02, Self::Draft02AggregateContinueResp) => {
Some(DRAFT02_MEDIA_TYPE_AGG_CONT_RESP)
}
(_, Self::Draft02AggregateContinueResp) => None,
(DapVersion::Draft02, Self::AggregateShareReq)
| (DapVersion::Draft04, Self::AggregateShareReq) => Some(MEDIA_TYPE_AGG_SHARE_REQ),
| (DapVersion::Draft05, Self::AggregateShareReq) => Some(MEDIA_TYPE_AGG_SHARE_REQ),
(DapVersion::Draft02, Self::AggregateShare) => Some(DRAFT02_MEDIA_TYPE_AGG_SHARE_RESP),
(DapVersion::Draft04, Self::AggregateShare) => Some(MEDIA_TYPE_AGG_SHARE),
(DapVersion::Draft02, Self::CollectReq) | (DapVersion::Draft04, Self::CollectReq) => {
(DapVersion::Draft05, Self::AggregateShare) => Some(MEDIA_TYPE_AGG_SHARE),
(DapVersion::Draft02, Self::CollectReq) | (DapVersion::Draft05, Self::CollectReq) => {
Some(MEDIA_TYPE_COLLECT_REQ)
}
(DapVersion::Draft02, Self::Collection) => Some(DRAFT02_MEDIA_TYPE_COLLECT_RESP),
(DapVersion::Draft04, Self::Collection) => Some(MEDIA_TYPE_COLLECTION),
(DapVersion::Draft05, Self::Collection) => Some(MEDIA_TYPE_COLLECTION),
(DapVersion::Draft02, Self::HpkeConfigList) => Some(DRAFT02_MEDIA_TYPE_HPKE_CONFIG),
(DapVersion::Draft04, Self::HpkeConfigList) => Some(MEDIA_TYPE_HPKE_CONFIG_LIST),
(DapVersion::Draft02, Self::Report) | (DapVersion::Draft04, Self::Report) => {
(DapVersion::Draft05, Self::HpkeConfigList) => Some(MEDIA_TYPE_HPKE_CONFIG_LIST),
(DapVersion::Draft02, Self::Report) | (DapVersion::Draft05, Self::Report) => {
Some(MEDIA_TYPE_REPORT)
}
(_, Self::Invalid(ref content_type)) => Some(content_type),
Expand All @@ -143,7 +143,7 @@ impl DapMediaType {
pub(crate) fn agg_job_cont_resp_for_version(version: DapVersion) -> Self {
match version {
DapVersion::Draft02 => Self::Draft02AggregateContinueResp,
DapVersion::Draft04 => Self::AggregationJobResp,
DapVersion::Draft05 => Self::AggregationJobResp,
_ => unreachable!("unhandled version {version:?}"),
}
}
Expand Down
42 changes: 21 additions & 21 deletions daphne/src/constants_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,70 +70,70 @@ fn from_str_for_version() {
DapMediaType::Collection,
);

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

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

// Missing media type
assert_eq!(
DapMediaType::from_str_for_version(DapVersion::Draft04, None),
DapMediaType::from_str_for_version(DapVersion::Draft05, None),
DapMediaType::Missing,
);
}
Expand All @@ -142,27 +142,27 @@ fn from_str_for_version() {
fn round_trip() {
for (version, media_type) in [
(DapVersion::Draft02, DapMediaType::AggregationJobInitReq),
(DapVersion::Draft04, DapMediaType::AggregationJobInitReq),
(DapVersion::Draft05, DapMediaType::AggregationJobInitReq),
(DapVersion::Draft02, DapMediaType::AggregationJobResp),
(DapVersion::Draft04, DapMediaType::AggregationJobResp),
(DapVersion::Draft05, DapMediaType::AggregationJobResp),
(DapVersion::Draft02, DapMediaType::AggregationJobContinueReq),
(DapVersion::Draft04, DapMediaType::AggregationJobContinueReq),
(DapVersion::Draft05, DapMediaType::AggregationJobContinueReq),
(
DapVersion::Draft02,
DapMediaType::Draft02AggregateContinueResp,
),
(DapVersion::Draft02, DapMediaType::AggregateShareReq),
(DapVersion::Draft04, DapMediaType::AggregateShareReq),
(DapVersion::Draft05, DapMediaType::AggregateShareReq),
(DapVersion::Draft02, DapMediaType::AggregateShare),
(DapVersion::Draft04, DapMediaType::AggregateShare),
(DapVersion::Draft05, DapMediaType::AggregateShare),
(DapVersion::Draft02, DapMediaType::CollectReq),
(DapVersion::Draft04, DapMediaType::CollectReq),
(DapVersion::Draft05, DapMediaType::CollectReq),
(DapVersion::Draft02, DapMediaType::Collection),
(DapVersion::Draft04, DapMediaType::Collection),
(DapVersion::Draft05, DapMediaType::Collection),
(DapVersion::Draft02, DapMediaType::HpkeConfigList),
(DapVersion::Draft04, DapMediaType::HpkeConfigList),
(DapVersion::Draft05, DapMediaType::HpkeConfigList),
(DapVersion::Draft02, DapMediaType::Report),
(DapVersion::Draft04, DapMediaType::Report),
(DapVersion::Draft05, DapMediaType::Report),
] {
assert_eq!(
DapMediaType::from_str_for_version(version, media_type.as_str_for_version(version)),
Expand All @@ -183,6 +183,6 @@ fn media_type_for_agg_cont_req() {

assert_eq!(
DapMediaType::AggregationJobResp,
DapMediaType::agg_job_cont_resp_for_version(DapVersion::Draft04)
DapMediaType::agg_job_cont_resp_for_version(DapVersion::Draft05)
);
}
26 changes: 13 additions & 13 deletions daphne/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//! PPM working group of the IETF. See [`VdafConfig`] for a listing of supported
//! [VDAFs](https://github.com/cfrg/draft-irtf-cfrg-vdaf).
//!
//! Daphne implements draft-ietf-ppm-dap-02 and draft-ietf-ppm-dap-03.
//! Daphne implements draft-ietf-ppm-dap-02 and draft-ietf-ppm-dap-05.
//!
//! Daphne does not provide the complete, end-to-end functionality of any party in the protocol.
//! Instead, it defines traits for the functionalities that a concrete instantiation of the
Expand Down Expand Up @@ -74,8 +74,8 @@ pub enum DapVersion {
#[serde(rename = "v02")]
Draft02,

#[serde(rename = "v04")]
Draft04,
#[serde(rename = "v05")]
Draft05,

#[serde(other)]
#[serde(rename = "unknown_version")]
Expand All @@ -87,7 +87,7 @@ impl From<&str> for DapVersion {
fn from(version: &str) -> Self {
match version {
"v02" => DapVersion::Draft02,
"v04" => DapVersion::Draft04,
"v05" => DapVersion::Draft05,
_ => DapVersion::Unknown,
}
}
Expand All @@ -97,8 +97,8 @@ impl AsRef<str> for DapVersion {
fn as_ref(&self) -> &str {
match self {
DapVersion::Draft02 => "v02",
DapVersion::Draft04 => "v04",
_ => panic!("tried to construct string from unknown DAP version"),
DapVersion::Draft05 => "v05",
_ => unreachable!("tried to construct string from unknown DAP version"),
}
}
}
Expand Down Expand Up @@ -862,13 +862,13 @@ pub struct DapLeaderProcessTelemetry {
}

/// draft02 compatibility: A logical aggregation job ID. In the latest draft, this is a 32-byte
/// string included in the HTTP request payload; in draft04, this is a 16-byte string included in
/// string included in the HTTP request payload; in draft05, this is a 16-byte string included in
/// the HTTP request path. This type unifies these into one type so that any protocol logic that
/// is agnostic to these details can use the same object.
#[derive(Clone, Debug)]
pub enum MetaAggregationJobId<'a> {
Draft02(Cow<'a, Draft02AggregationJobId>),
Draft04(Cow<'a, AggregationJobId>),
Draft05(Cow<'a, AggregationJobId>),
}

impl MetaAggregationJobId<'_> {
Expand All @@ -877,7 +877,7 @@ impl MetaAggregationJobId<'_> {
let mut rng = thread_rng();
match version {
DapVersion::Draft02 => Self::Draft02(Cow::Owned(Draft02AggregationJobId(rng.gen()))),
DapVersion::Draft04 => Self::Draft04(Cow::Owned(AggregationJobId(rng.gen()))),
DapVersion::Draft05 => Self::Draft05(Cow::Owned(AggregationJobId(rng.gen()))),
DapVersion::Unknown => unreachable!("unhandled version {version:?}"),
}
}
Expand All @@ -887,7 +887,7 @@ impl MetaAggregationJobId<'_> {
pub(crate) fn for_request_payload(&self) -> Option<Draft02AggregationJobId> {
match self {
Self::Draft02(agg_job_id) => Some(agg_job_id.clone().into_owned()),
Self::Draft04(..) => None,
Self::Draft05(..) => None,
}
}

Expand All @@ -897,7 +897,7 @@ impl MetaAggregationJobId<'_> {
match self {
// In draft02, the aggregation job ID is not determined until the payload is parsed.
Self::Draft02(..) => DapResource::Undefined,
Self::Draft04(agg_job_id) => {
Self::Draft05(agg_job_id) => {
DapResource::AggregationJob(agg_job_id.clone().into_owned())
}
}
Expand All @@ -907,15 +907,15 @@ impl MetaAggregationJobId<'_> {
pub fn to_hex(&self) -> String {
match self {
Self::Draft02(agg_job_id) => agg_job_id.to_hex(),
Self::Draft04(agg_job_id) => agg_job_id.to_hex(),
Self::Draft05(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::Draft04(agg_job_id) => agg_job_id.to_base64url(),
Self::Draft05(agg_job_id) => agg_job_id.to_base64url(),
}
}
}
Expand Down
Loading

0 comments on commit d913ce7

Please sign in to comment.