KeyMgr test improvements

This ticket is about improving the KeyMgr tests from mgr.rs.

(for more about tor-keymgr in general, see https://docs.rs/tor-keymgr/0.28.0/tor_keymgr/)

These tests generally involve a KeyMgr backed by multiple Keystores. The underlying keystores have a funny macro-generated Keystore implementation, where the insert function adds some metadata to each TestItem inserted into the keystore. The metadata is a string that consists of the keystore ID concatenated with the meta string contained within the TestItem. This string is then used in the tests to check that the item is retrieved from the right keystore (remember, a KeyMgr has multiple underlying keystores, and without this metadata we'd have no way of checking which keystore an item retrieved with KeyMgr::get was actually retrieved from). There is a similar mechanism for noting whether a TestItem was generated using Keygen::generate().

Currently, this is all quite ugly because the metadata is stringly-typed, and therefore a bit annoying to work with. It would be a lot nicer if we changed the type of this metadata from String to a new ItemMetadata type, which might will contain:

  • a String id that identifies a given item (in the tests this would be coot, moorhen, etc)
  • a generated_in optional field specifying which keystore the item was generated in using Keygen::generate, if it was generated this way at all
  • an optional field specifying the KeystoreId of the keystore the item was retrieved from

(note that you don't necessarily have to structure ItemMetadata this way. While implementing this you might find it makes more sense to do things differently -- this is definitely not set in stone!)

That way, we'll be able to have more principled test assertions. So instead of

        assert_eq!(
            mgr.get::<TestItem>(&TestKeySpecifier3)
                .unwrap()
                .map(|k| k.meta),
            Some("keystore1_moorhen".to_string())
        );

we'll have much neater, and less confusing assertions that will look roughly like this:

    let meta = mgr.get::<TestItem>(&TestKeySpecifier3).unwrap().unwrap().meta;
    // Check we got the expected item
    assert_eq!(meta.item_id, "moorhen".to_string());
    // Ensure the item was retrieved from keystore1
    assert_eq!(meta.retrieved_from, Some(KeystoreId::from_str("keystore1").unwrap()));
    // Ensure the item wasn't generated with Keygen::generate()
    assert_eq!(meta.generated_in, None);