use super::types::{
ByteSourceAddress, GENERATION_CHUNK_TAG, GenerationPlan, InputOrigin, SOURCE_CHUNK_BYTES,
};
use crate::identity::ContentAddress;
use crate::report::encode_bytes;
pub(super) fn source_preimage(plan: &GenerationPlan) -> Vec<u8> {
let mut preimage: Vec<u8> = Vec::new();
plan.population().name().encode_into(&mut preimage);
encode_bytes(plan.profile().name().as_bytes(), &mut preimage);
preimage.extend_from_slice(&plan.profile().version().to_be_bytes());
preimage.push(plan.origin().slot());
match plan.origin() {
InputOrigin::Seeded(seed) => preimage.extend_from_slice(&seed.value().to_be_bytes()),
InputOrigin::Supplied(material) => encode_bytes(material, &mut preimage),
}
preimage
}
pub(super) fn chunk_material(address: ByteSourceAddress, counter: u64) -> [u8; SOURCE_CHUNK_BYTES] {
let mut preimage: Vec<u8> = Vec::new();
encode_bytes(address.address().as_bytes(), &mut preimage);
preimage.extend_from_slice(&counter.to_be_bytes());
*ContentAddress::derived(GENERATION_CHUNK_TAG, &preimage).as_bytes()
}