Skip to content

Commit

Permalink
Add pub + secret keys to test vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
pietgeursen committed Jun 7, 2020
1 parent 4e83dce commit 38380d0
Show file tree
Hide file tree
Showing 2 changed files with 272 additions and 234 deletions.
27 changes: 25 additions & 2 deletions generate-test-vectors/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ pub fn main() {
fn valid_first_entry() -> Value {
let mut csprng: OsRng = OsRng{};
let keypair: Keypair = Keypair::generate(&mut csprng);
let secret_byte_string = hex::encode(&keypair.secret);
let public_byte_string = hex::encode(&keypair.public);

let mut log = Log::new(
MemoryEntryStore::new(),
Expand All @@ -69,6 +71,10 @@ fn valid_first_entry() -> Value {
json!({
"description": "A valid first entry. Note that the previous and limpaa links are None / null. And that the seq_num starts at 1.",
"payload": hex::encode(payload),
"author": {
"public": public_byte_string,
"secret": secret_byte_string,
},
"decoded": entry,
"encoded": Bytes(&buffer[..buff_size])
})
Expand All @@ -78,6 +84,8 @@ fn valid_first_entry() -> Value {
fn n_valid_entries(n: u64) -> Value {
let mut csprng: OsRng = OsRng{};
let keypair: Keypair = Keypair::generate(&mut csprng);
let secret_byte_string = hex::encode(&keypair.secret);
let public_byte_string = hex::encode(&keypair.public);
let mut log = Log::new(
MemoryEntryStore::new(),
keypair.public.clone(),
Expand Down Expand Up @@ -105,6 +113,10 @@ fn n_valid_entries(n: u64) -> Value {

json!({
"description": format!("A valid collection of {} entries.", n),
"author": {
"public": public_byte_string,
"secret": secret_byte_string,
},
"entries": vals
})
}
Expand All @@ -114,6 +126,8 @@ fn valid_partially_replicated_feed(n: u64) -> Value {
let mut csprng: OsRng = OsRng{};
let keypair: Keypair = Keypair::generate(&mut csprng);
let public = keypair.public.clone();
let secret_byte_string = hex::encode(&keypair.secret);
let public_byte_string = hex::encode(&keypair.public);
let mut log = Log::new(MemoryEntryStore::new(), public.clone(), Some(keypair), 0);

(1..n).into_iter().for_each(|i| {
Expand All @@ -125,7 +139,7 @@ fn valid_partially_replicated_feed(n: u64) -> Value {

let mut partial_log = Log::new(MemoryEntryStore::new(), public.clone(), None, 0);

lipmaa_seqs
let vals = lipmaa_seqs
.iter()
.rev()
.map(|lipmaa_seq| {
Expand All @@ -141,7 +155,16 @@ fn valid_partially_replicated_feed(n: u64) -> Value {
"encoded": Bytes(&buffer[..buff_size])
})
})
.collect()
.collect::<Value>();

json!({
"description": format!("A valid collection of {} entries.", n),
"author": {
"public": public_byte_string,
"secret": secret_byte_string,
},
"entries": vals
})
}

fn build_lipmaa_set(n: u64, mut vec: Option<Vec<u64>>) -> Vec<u64> {
Expand Down
Loading

0 comments on commit 38380d0

Please sign in to comment.