/// Creates a random recipient stanza that exercises the joint in the age v1 format.
///
/// This function is guaranteed to return a valid stanza, but makes no other guarantees
/// about the stanza's fields.
Creates a random recipient stanza that exercises the joint in the age v1 format.
This function is guaranteed to return a valid stanza, but makes no other guarantees
about the stanza's fields.
Creates a random recipient stanza that exercises the joint in the age v1 format . This function is guaranteed to return a valid stanza but makes no other guarantees about the stanza ' s fields .
pub fn grease_the_joint() -> Stanza {
    // Generate arbitrary strings between 1 and 9 characters long.
    fn gen_arbitrary_string<R: RngCore>(rng: &mut R) -> String {
        let length = Uniform::from(1..9).sample(rng);
        Uniform::from(33..=126)
            .sample_iter(rng)
            .map(char::from)
            .take(length)
            .collect()
    }
    let mut rng = thread_rng();
    // Add a suffix to the random tag so users know what is going on.
    let tag = format!("{}-grease", gen_arbitrary_string(&mut rng));
    // Between this and the above generation bounds, the first line of the recipient
    // stanza will be between five and 69 characters.
    let args = (0..Uniform::from(0..5).sample(&mut rng))
        .map(|_| gen_arbitrary_string(&mut rng))
        .collect();
    // A length between 0 and 100 bytes exercises the following stanza bodies:
    // - Empty
    // - Single short-line
    // - Single full-line
    // - Two lines, second short
    // - Two lines, both full
    // - Three lines, last short
    let mut body = vec![0; Uniform::from(0..100).sample(&mut rng)];
    rng.fill_bytes(&mut body);
    Stanza { tag, args, body }
}
pub fn grease_the_joint ( ) -> Stanza { // Generate arbitrary strings between 1 and 9 characters long. fn gen_arbitrary_string < R : RngCore > ( rng : & mut R ) -> String { let length = Uniform :: from ( 1 .. 9 ) . sample ( rng ) ; Uniform :: from ( 33 ..= 126 ) . sample_iter ( rng ) . map ( char :: from ) . take ( length ) . collect ( ) } let mut rng = thread_rng ( ) ; // Add a suffix to the random tag so users know what is going on. let tag = format ! ( " " gen_arbitrary_string ( mut rng ) ) ; // Between this and the above generation bounds, the first line of the recipient // stanza will be between five and 69 characters. let args = ( 0 .. Uniform :: from ( 0 .. 5 ) . sample ( & mut rng ) ) . map ( | _ | gen_arbitrary_string ( & mut rng ) ) . collect ( ) ; // A length between 0 and 100 bytes exercises the following stanza bodies: // - Empty // - Single short-line // - Single full-line // - Two lines, second short // - Two lines, both full // - Three lines, last short let mut body = vec ! [ 0 Uniform from ( 0 100 ) sample ( mut rng ) ] ; rng . fill_bytes ( & mut body ) ; Stanza { tag , args , body } }
Creates a random recipient stanza that exercises the joint in the age v1 format.
Creates a random recipient stanza that exercises the joint in the age v1 format .