Rename created_at and expire_at as not_before and not_after
This commit is contained in:
parent
3690351c13
commit
d47f68944a
2 changed files with 52 additions and 52 deletions
48
src/ikm.rs
48
src/ikm.rs
|
@ -21,8 +21,8 @@ pub struct InputKeyMaterial {
|
||||||
pub id: IkmId,
|
pub id: IkmId,
|
||||||
pub scheme: Scheme,
|
pub scheme: Scheme,
|
||||||
pub(crate) content: Vec<u8>,
|
pub(crate) content: Vec<u8>,
|
||||||
pub created_at: SystemTime,
|
pub not_before: SystemTime,
|
||||||
pub expire_at: SystemTime,
|
pub not_after: SystemTime,
|
||||||
pub is_revoked: bool,
|
pub is_revoked: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,14 +35,14 @@ impl InputKeyMaterial {
|
||||||
res.extend_from_slice(&self.content);
|
res.extend_from_slice(&self.content);
|
||||||
res.extend_from_slice(
|
res.extend_from_slice(
|
||||||
&self
|
&self
|
||||||
.created_at
|
.not_before
|
||||||
.duration_since(SystemTime::UNIX_EPOCH)?
|
.duration_since(SystemTime::UNIX_EPOCH)?
|
||||||
.as_secs()
|
.as_secs()
|
||||||
.to_le_bytes(),
|
.to_le_bytes(),
|
||||||
);
|
);
|
||||||
res.extend_from_slice(
|
res.extend_from_slice(
|
||||||
&self
|
&self
|
||||||
.expire_at
|
.not_after
|
||||||
.duration_since(SystemTime::UNIX_EPOCH)?
|
.duration_since(SystemTime::UNIX_EPOCH)?
|
||||||
.as_secs()
|
.as_secs()
|
||||||
.to_le_bytes(),
|
.to_le_bytes(),
|
||||||
|
@ -65,8 +65,8 @@ impl InputKeyMaterial {
|
||||||
id: IkmId::from_le_bytes(b[0..4].try_into().unwrap()),
|
id: IkmId::from_le_bytes(b[0..4].try_into().unwrap()),
|
||||||
scheme,
|
scheme,
|
||||||
content: b[8..8 + is].into(),
|
content: b[8..8 + is].into(),
|
||||||
created_at: InputKeyMaterial::bytes_to_system_time(&b[8 + is..8 + is + 8])?,
|
not_before: InputKeyMaterial::bytes_to_system_time(&b[8 + is..8 + is + 8])?,
|
||||||
expire_at: InputKeyMaterial::bytes_to_system_time(&b[8 + is + 8..8 + is + 8 + 8])?,
|
not_after: InputKeyMaterial::bytes_to_system_time(&b[8 + is + 8..8 + is + 8 + 8])?,
|
||||||
is_revoked: b[8 + is + 8 + 8] != 0,
|
is_revoked: b[8 + is + 8 + 8] != 0,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -168,13 +168,13 @@ impl InputKeyMaterialList {
|
||||||
let ikm_len = scheme.get_ikm_size();
|
let ikm_len = scheme.get_ikm_size();
|
||||||
let mut content: Vec<u8> = vec![0; ikm_len];
|
let mut content: Vec<u8> = vec![0; ikm_len];
|
||||||
getrandom::getrandom(content.as_mut_slice())?;
|
getrandom::getrandom(content.as_mut_slice())?;
|
||||||
let created_at = SystemTime::now();
|
let not_before = SystemTime::now();
|
||||||
self.id_counter += 1;
|
self.id_counter += 1;
|
||||||
self.ikm_lst.push(InputKeyMaterial {
|
self.ikm_lst.push(InputKeyMaterial {
|
||||||
id: self.id_counter,
|
id: self.id_counter,
|
||||||
scheme,
|
scheme,
|
||||||
created_at,
|
not_before,
|
||||||
expire_at: created_at + duration,
|
not_after: not_before + duration,
|
||||||
is_revoked: false,
|
is_revoked: false,
|
||||||
content,
|
content,
|
||||||
});
|
});
|
||||||
|
@ -212,7 +212,7 @@ impl InputKeyMaterialList {
|
||||||
self.ikm_lst
|
self.ikm_lst
|
||||||
.iter()
|
.iter()
|
||||||
.rev()
|
.rev()
|
||||||
.find(|&ikm| !ikm.is_revoked && ikm.created_at < now && ikm.expire_at > now)
|
.find(|&ikm| !ikm.is_revoked && ikm.not_before < now && ikm.not_after > now)
|
||||||
.ok_or(Error::IkmNoneAvailable)
|
.ok_or(Error::IkmNoneAvailable)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,23 +297,23 @@ mod ikm_management {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
// This list contains the folowing IKM:
|
// This list contains the folowing IKM:
|
||||||
// 1: * created_at: Monday 1 April 2019 10:21:42
|
// 1: * not_before: Monday 1 April 2019 10:21:42
|
||||||
// * expire_at: Wednesday 1 April 2020 10:21:42
|
// * not_after: Wednesday 1 April 2020 10:21:42
|
||||||
// * is_revoked: true
|
// * is_revoked: true
|
||||||
// 2: * created_at: Thursday 12 March 2020 10:21:42
|
// 2: * not_before: Thursday 12 March 2020 10:21:42
|
||||||
// * expire_at: Friday 12 March 2021 10:21:42
|
// * not_after: Friday 12 March 2021 10:21:42
|
||||||
// * is_revoked: false
|
// * is_revoked: false
|
||||||
// 3: * created_at: Sunday 21 February 2021 10:21:42
|
// 3: * not_before: Sunday 21 February 2021 10:21:42
|
||||||
// * expire_at: Thursday 10 February 2180 10:21:42
|
// * not_after: Thursday 10 February 2180 10:21:42
|
||||||
// * is_revoked: false
|
// * is_revoked: false
|
||||||
// 4: * created_at: Sunday 30 January 2022 10:21:42
|
// 4: * not_before: Sunday 30 January 2022 10:21:42
|
||||||
// * expire_at: Tuesday 10 January 2023 10:21:42
|
// * not_after: Tuesday 10 January 2023 10:21:42
|
||||||
// * is_revoked: false
|
// * is_revoked: false
|
||||||
// 5: * created_at: Tuesday 2 January 2024 10:21:42
|
// 5: * not_before: Tuesday 2 January 2024 10:21:42
|
||||||
// * expire_at: Tuesday 6 June 2180 10:21:42
|
// * not_after: Tuesday 6 June 2180 10:21:42
|
||||||
// * is_revoked: true
|
// * is_revoked: true
|
||||||
// 6: * created_at: Tuesday 15 August 2180 10:21:42
|
// 6: * not_before: Tuesday 15 August 2180 10:21:42
|
||||||
// * expire_at: Wednesday 15 August 2181 10:21:42
|
// * not_after: Wednesday 15 August 2181 10:21:42
|
||||||
// * is_revoked: false
|
// * is_revoked: false
|
||||||
const TEST_STR: &str = "BgAAAA:AQAAAAEAAACUAPcqngJ46_HMtJSdIw-WeUtImcCVxOA47n6UIN5K2TbmoVwAAAAANmuEXgAAAAAB:AgAAAAEAAADf7CR8vl_aWOUyfsO0ek0YQr_Yi7L_sJmF2nIt_XOaCzYNal4AAAAAtkBLYAAAAAAA:AwAAAAEAAAAMoNIW9gIGkzegUDEsU3N1Rf_Zz0OMuylUSiQjUzLXqzY0MmAAAAAANsk0iwEAAAAA:BAAAAAEAAABbwRrMz3x3DkfOEFg1BHfLLRHoNqg6d_xGWwdh48hH8rZm9mEAAAAANjy9YwAAAAAA:BQAAAAEAAAA2LwnTgDUF7qn7dy79VA24JSSgo6vllAtU5zmhrxNJu7YIz4sBAAAANoUMjgEAAAAB:BgAAAAEAAAAn0Vqe2f9YRXBt6xVYaeSLs0Gf0S0_5B-hk-a2b0rhlraCJbwAAAAAtlErjAEAAAAA";
|
const TEST_STR: &str = "BgAAAA:AQAAAAEAAACUAPcqngJ46_HMtJSdIw-WeUtImcCVxOA47n6UIN5K2TbmoVwAAAAANmuEXgAAAAAB:AgAAAAEAAADf7CR8vl_aWOUyfsO0ek0YQr_Yi7L_sJmF2nIt_XOaCzYNal4AAAAAtkBLYAAAAAAA:AwAAAAEAAAAMoNIW9gIGkzegUDEsU3N1Rf_Zz0OMuylUSiQjUzLXqzY0MmAAAAAANsk0iwEAAAAA:BAAAAAEAAABbwRrMz3x3DkfOEFg1BHfLLRHoNqg6d_xGWwdh48hH8rZm9mEAAAAANjy9YwAAAAAA:BQAAAAEAAAA2LwnTgDUF7qn7dy79VA24JSSgo6vllAtU5zmhrxNJu7YIz4sBAAAANoUMjgEAAAAB:BgAAAAEAAAAn0Vqe2f9YRXBt6xVYaeSLs0Gf0S0_5B-hk-a2b0rhlraCJbwAAAAAtlErjAEAAAAA";
|
||||||
|
|
||||||
|
@ -426,8 +426,8 @@ mod ikm_management {
|
||||||
let el_bis = &lst_bis.ikm_lst[i];
|
let el_bis = &lst_bis.ikm_lst[i];
|
||||||
assert_eq!(el_bis.id, el.id);
|
assert_eq!(el_bis.id, el.id);
|
||||||
assert_eq!(el_bis.content, el.content);
|
assert_eq!(el_bis.content, el.content);
|
||||||
assert_eq!(el_bis.created_at, round_time(el.created_at));
|
assert_eq!(el_bis.not_before, round_time(el.not_before));
|
||||||
assert_eq!(el_bis.expire_at, round_time(el.expire_at));
|
assert_eq!(el_bis.not_after, round_time(el.not_after));
|
||||||
assert_eq!(el_bis.is_revoked, el.is_revoked);
|
assert_eq!(el_bis.is_revoked, el.is_revoked);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,30 +172,30 @@ mod ikm_lst {
|
||||||
let mut lst = crate::InputKeyMaterialList::new();
|
let mut lst = crate::InputKeyMaterialList::new();
|
||||||
let _ = lst.add_ikm();
|
let _ = lst.add_ikm();
|
||||||
lst.ikm_lst[0].content = TEST_CTN_0.to_vec();
|
lst.ikm_lst[0].content = TEST_CTN_0.to_vec();
|
||||||
lst.ikm_lst[0].created_at = bytes_to_system_time(1554114102);
|
lst.ikm_lst[0].not_before = bytes_to_system_time(1554114102);
|
||||||
lst.ikm_lst[0].expire_at = bytes_to_system_time(1585736502);
|
lst.ikm_lst[0].not_after = bytes_to_system_time(1585736502);
|
||||||
lst.ikm_lst[0].is_revoked = true;
|
lst.ikm_lst[0].is_revoked = true;
|
||||||
let _ = lst.add_ikm();
|
let _ = lst.add_ikm();
|
||||||
lst.ikm_lst[1].content = TEST_CTN_1.to_vec();
|
lst.ikm_lst[1].content = TEST_CTN_1.to_vec();
|
||||||
lst.ikm_lst[1].created_at = bytes_to_system_time(1584008502);
|
lst.ikm_lst[1].not_before = bytes_to_system_time(1584008502);
|
||||||
lst.ikm_lst[1].expire_at = bytes_to_system_time(1615544502);
|
lst.ikm_lst[1].not_after = bytes_to_system_time(1615544502);
|
||||||
let _ = lst.add_ikm();
|
let _ = lst.add_ikm();
|
||||||
lst.ikm_lst[2].content = TEST_CTN_2.to_vec();
|
lst.ikm_lst[2].content = TEST_CTN_2.to_vec();
|
||||||
lst.ikm_lst[2].created_at = bytes_to_system_time(1613902902);
|
lst.ikm_lst[2].not_before = bytes_to_system_time(1613902902);
|
||||||
lst.ikm_lst[2].expire_at = bytes_to_system_time(6630459702);
|
lst.ikm_lst[2].not_after = bytes_to_system_time(6630459702);
|
||||||
let _ = lst.add_ikm();
|
let _ = lst.add_ikm();
|
||||||
lst.ikm_lst[3].content = TEST_CTN_3.to_vec();
|
lst.ikm_lst[3].content = TEST_CTN_3.to_vec();
|
||||||
lst.ikm_lst[3].created_at = bytes_to_system_time(1643538102);
|
lst.ikm_lst[3].not_before = bytes_to_system_time(1643538102);
|
||||||
lst.ikm_lst[3].expire_at = bytes_to_system_time(1673346102);
|
lst.ikm_lst[3].not_after = bytes_to_system_time(1673346102);
|
||||||
let _ = lst.add_ikm();
|
let _ = lst.add_ikm();
|
||||||
lst.ikm_lst[4].content = TEST_CTN_4.to_vec();
|
lst.ikm_lst[4].content = TEST_CTN_4.to_vec();
|
||||||
lst.ikm_lst[4].created_at = bytes_to_system_time(6640568502);
|
lst.ikm_lst[4].not_before = bytes_to_system_time(6640568502);
|
||||||
lst.ikm_lst[4].expire_at = bytes_to_system_time(6678152502);
|
lst.ikm_lst[4].not_after = bytes_to_system_time(6678152502);
|
||||||
lst.ikm_lst[4].is_revoked = true;
|
lst.ikm_lst[4].is_revoked = true;
|
||||||
let _ = lst.add_ikm();
|
let _ = lst.add_ikm();
|
||||||
lst.ikm_lst[5].content = TEST_CTN_5.to_vec();
|
lst.ikm_lst[5].content = TEST_CTN_5.to_vec();
|
||||||
lst.ikm_lst[5].created_at = bytes_to_system_time(3156574902);
|
lst.ikm_lst[5].not_before = bytes_to_system_time(3156574902);
|
||||||
lst.ikm_lst[5].expire_at = bytes_to_system_time(6646616502);
|
lst.ikm_lst[5].not_after = bytes_to_system_time(6646616502);
|
||||||
|
|
||||||
let s = super::encode_ikm_list(&lst).unwrap();
|
let s = super::encode_ikm_list(&lst).unwrap();
|
||||||
assert_eq!(s, TEST_STR);
|
assert_eq!(s, TEST_STR);
|
||||||
|
@ -209,33 +209,33 @@ mod ikm_lst {
|
||||||
assert_eq!(lst.id_counter, 6);
|
assert_eq!(lst.id_counter, 6);
|
||||||
assert_eq!(lst.ikm_lst[0].id, 1);
|
assert_eq!(lst.ikm_lst[0].id, 1);
|
||||||
assert_eq!(lst.ikm_lst[0].content, TEST_CTN_0);
|
assert_eq!(lst.ikm_lst[0].content, TEST_CTN_0);
|
||||||
assert_eq!(as_ts!(lst.ikm_lst[0].created_at), 1554114102);
|
assert_eq!(as_ts!(lst.ikm_lst[0].not_before), 1554114102);
|
||||||
assert_eq!(as_ts!(lst.ikm_lst[0].expire_at), 1585736502);
|
assert_eq!(as_ts!(lst.ikm_lst[0].not_after), 1585736502);
|
||||||
assert_eq!(lst.ikm_lst[0].is_revoked, true);
|
assert_eq!(lst.ikm_lst[0].is_revoked, true);
|
||||||
assert_eq!(lst.ikm_lst[1].id, 2);
|
assert_eq!(lst.ikm_lst[1].id, 2);
|
||||||
assert_eq!(lst.ikm_lst[1].content, TEST_CTN_1);
|
assert_eq!(lst.ikm_lst[1].content, TEST_CTN_1);
|
||||||
assert_eq!(as_ts!(lst.ikm_lst[1].created_at), 1584008502);
|
assert_eq!(as_ts!(lst.ikm_lst[1].not_before), 1584008502);
|
||||||
assert_eq!(as_ts!(lst.ikm_lst[1].expire_at), 1615544502);
|
assert_eq!(as_ts!(lst.ikm_lst[1].not_after), 1615544502);
|
||||||
assert_eq!(lst.ikm_lst[1].is_revoked, false);
|
assert_eq!(lst.ikm_lst[1].is_revoked, false);
|
||||||
assert_eq!(lst.ikm_lst[2].id, 3);
|
assert_eq!(lst.ikm_lst[2].id, 3);
|
||||||
assert_eq!(lst.ikm_lst[2].content, TEST_CTN_2);
|
assert_eq!(lst.ikm_lst[2].content, TEST_CTN_2);
|
||||||
assert_eq!(as_ts!(lst.ikm_lst[2].created_at), 1613902902);
|
assert_eq!(as_ts!(lst.ikm_lst[2].not_before), 1613902902);
|
||||||
assert_eq!(as_ts!(lst.ikm_lst[2].expire_at), 6630459702);
|
assert_eq!(as_ts!(lst.ikm_lst[2].not_after), 6630459702);
|
||||||
assert_eq!(lst.ikm_lst[2].is_revoked, false);
|
assert_eq!(lst.ikm_lst[2].is_revoked, false);
|
||||||
assert_eq!(lst.ikm_lst[3].id, 4);
|
assert_eq!(lst.ikm_lst[3].id, 4);
|
||||||
assert_eq!(lst.ikm_lst[3].content, TEST_CTN_3);
|
assert_eq!(lst.ikm_lst[3].content, TEST_CTN_3);
|
||||||
assert_eq!(as_ts!(lst.ikm_lst[3].created_at), 1643538102);
|
assert_eq!(as_ts!(lst.ikm_lst[3].not_before), 1643538102);
|
||||||
assert_eq!(as_ts!(lst.ikm_lst[3].expire_at), 1673346102);
|
assert_eq!(as_ts!(lst.ikm_lst[3].not_after), 1673346102);
|
||||||
assert_eq!(lst.ikm_lst[3].is_revoked, false);
|
assert_eq!(lst.ikm_lst[3].is_revoked, false);
|
||||||
assert_eq!(lst.ikm_lst[4].id, 5);
|
assert_eq!(lst.ikm_lst[4].id, 5);
|
||||||
assert_eq!(lst.ikm_lst[4].content, TEST_CTN_4);
|
assert_eq!(lst.ikm_lst[4].content, TEST_CTN_4);
|
||||||
assert_eq!(as_ts!(lst.ikm_lst[4].created_at), 6640568502);
|
assert_eq!(as_ts!(lst.ikm_lst[4].not_before), 6640568502);
|
||||||
assert_eq!(as_ts!(lst.ikm_lst[4].expire_at), 6678152502);
|
assert_eq!(as_ts!(lst.ikm_lst[4].not_after), 6678152502);
|
||||||
assert_eq!(lst.ikm_lst[4].is_revoked, true);
|
assert_eq!(lst.ikm_lst[4].is_revoked, true);
|
||||||
assert_eq!(lst.ikm_lst[5].id, 6);
|
assert_eq!(lst.ikm_lst[5].id, 6);
|
||||||
assert_eq!(lst.ikm_lst[5].content, TEST_CTN_5);
|
assert_eq!(lst.ikm_lst[5].content, TEST_CTN_5);
|
||||||
assert_eq!(as_ts!(lst.ikm_lst[5].created_at), 3156574902);
|
assert_eq!(as_ts!(lst.ikm_lst[5].not_before), 3156574902);
|
||||||
assert_eq!(as_ts!(lst.ikm_lst[5].expire_at), 6646616502);
|
assert_eq!(as_ts!(lst.ikm_lst[5].not_after), 6646616502);
|
||||||
assert_eq!(lst.ikm_lst[5].is_revoked, false);
|
assert_eq!(lst.ikm_lst[5].is_revoked, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,12 +262,12 @@ mod ikm_lst {
|
||||||
assert_eq!(lst.ikm_lst[i].scheme, lst2.ikm_lst[i].scheme);
|
assert_eq!(lst.ikm_lst[i].scheme, lst2.ikm_lst[i].scheme);
|
||||||
assert_eq!(lst.ikm_lst[i].content, lst2.ikm_lst[i].content);
|
assert_eq!(lst.ikm_lst[i].content, lst2.ikm_lst[i].content);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
as_ts!(lst.ikm_lst[i].created_at),
|
as_ts!(lst.ikm_lst[i].not_before),
|
||||||
as_ts!(lst2.ikm_lst[i].created_at)
|
as_ts!(lst2.ikm_lst[i].not_before)
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
as_ts!(lst.ikm_lst[i].expire_at),
|
as_ts!(lst.ikm_lst[i].not_after),
|
||||||
as_ts!(lst2.ikm_lst[i].expire_at)
|
as_ts!(lst2.ikm_lst[i].not_after)
|
||||||
);
|
);
|
||||||
assert_eq!(lst.ikm_lst[i].is_revoked, lst2.ikm_lst[i].is_revoked);
|
assert_eq!(lst.ikm_lst[i].is_revoked, lst2.ikm_lst[i].is_revoked);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue